mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-22 17:14:32 +01:00
Saavn Internal Error Bug fix
This commit is contained in:
parent
4e539bbaae
commit
48e4c04973
@ -13,6 +13,7 @@ import io.github.shabinder.utils.getJsonArray
|
|||||||
import io.github.shabinder.utils.getJsonObject
|
import io.github.shabinder.utils.getJsonObject
|
||||||
import io.github.shabinder.utils.getString
|
import io.github.shabinder.utils.getString
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.features.ServerResponseException
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonArray
|
import kotlinx.serialization.json.JsonArray
|
||||||
@ -52,17 +53,21 @@ interface JioSaavnRequests {
|
|||||||
|
|
||||||
val searchURL = search_base_url + query
|
val searchURL = search_base_url + query
|
||||||
val results = mutableListOf<SaavnSearchResult>()
|
val results = mutableListOf<SaavnSearchResult>()
|
||||||
|
try {
|
||||||
(globalJson.parseToJsonElement(httpClient.get(searchURL)) as JsonObject).getJsonObject("songs").getJsonArray("data")?.forEach {
|
(globalJson.parseToJsonElement(httpClient.get(searchURL)) as JsonObject).getJsonObject("songs").getJsonArray("data")?.forEach {
|
||||||
(it as? JsonObject)?.formatData()?.let { jsonObject ->
|
(it as? JsonObject)?.formatData()?.let { jsonObject ->
|
||||||
results.add(globalJson.decodeFromJsonElement(SaavnSearchResult.serializer(), jsonObject))
|
results.add(globalJson.decodeFromJsonElement(SaavnSearchResult.serializer(), jsonObject))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}catch (e: ServerResponseException) {}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getLyrics(ID: String): String? {
|
suspend fun getLyrics(ID: String): String? {
|
||||||
return (Json.parseToJsonElement(httpClient.get(lyrics_base_url + ID)) as JsonObject)
|
return try {
|
||||||
|
(Json.parseToJsonElement(httpClient.get(lyrics_base_url + ID)) as JsonObject)
|
||||||
.getString("lyrics")
|
.getString("lyrics")
|
||||||
|
}catch (e:Exception) { null }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSong(
|
suspend fun getSong(
|
||||||
@ -74,6 +79,7 @@ interface JioSaavnRequests {
|
|||||||
.formatData(fetchLyrics)
|
.formatData(fetchLyrics)
|
||||||
return globalJson.decodeFromJsonElement(SaavnSong.serializer(), data)
|
return globalJson.decodeFromJsonElement(SaavnSong.serializer(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSongFromID(
|
suspend fun getSongFromID(
|
||||||
ID: String,
|
ID: String,
|
||||||
fetchLyrics: Boolean = false
|
fetchLyrics: Boolean = false
|
||||||
|
Loading…
Reference in New Issue
Block a user