Youtube Mp3 Link Fetching Fixed for Native

This commit is contained in:
shabinder 2021-05-04 16:25:44 +05:30
parent c278d6379a
commit 440210931b
3 changed files with 4 additions and 3 deletions

View File

@ -75,6 +75,8 @@ fun createHttpClient(enableNetworkLogs: Boolean = false) = HttpClient {
install(JsonFeature) { install(JsonFeature) {
serializer = KotlinxSerializer() serializer = KotlinxSerializer()
} }
// WorkAround for Freezing
// Use httpClient.getData / httpClient.postData Extensions
/*install(JsonFeature) { /*install(JsonFeature) {
serializer = KotlinxSerializer( serializer = KotlinxSerializer(
Json { Json {

View File

@ -49,7 +49,6 @@ suspend inline fun <reified T: Any> HttpClient.postData(
): T { ): T {
val response = post<HttpResponse> { val response = post<HttpResponse> {
url.takeFrom(urlString) url.takeFrom(urlString)
header(HttpHeaders.ContentType, ContentType.Application.Json)
block() block()
} }
val jsonBody = response.readText() val jsonBody = response.readText()

View File

@ -45,7 +45,7 @@ interface Yt1sMp3 {
* Body Form= q:yt video link ,vt:format=mp3 * Body Form= q:yt video link ,vt:format=mp3
* */ * */
private suspend fun getKey(videoID: String): String { private suspend fun getKey(videoID: String): String {
val response: JsonObject? = httpClient.postData("${corsApi}https://yt1s.com/api/ajaxSearch/index") { val response: JsonObject? = httpClient.post("${corsApi}https://yt1s.com/api/ajaxSearch/index") {
body = FormDataContent( body = FormDataContent(
Parameters.build { Parameters.build {
append("q", "https://www.youtube.com/watch?v=$videoID") append("q", "https://www.youtube.com/watch?v=$videoID")
@ -57,7 +57,7 @@ interface Yt1sMp3 {
} }
private suspend fun getConvertedMp3Link(videoID: String, key: String): JsonObject? { private suspend fun getConvertedMp3Link(videoID: String, key: String): JsonObject? {
return httpClient.postData("${corsApi}https://yt1s.com/api/ajaxConvert/convert") { return httpClient.post("${corsApi}https://yt1s.com/api/ajaxConvert/convert") {
body = FormDataContent( body = FormDataContent(
Parameters.build { Parameters.build {
append("vid", videoID) append("vid", videoID)