Skip to content

Commit

Permalink
Try to fix json error v2
Browse files Browse the repository at this point in the history
  • Loading branch information
LuftVerbot committed Dec 15, 2024
1 parent cabc9f3 commit 30c4e56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion ext/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ kotlin {
dependencies {
val libVersion: String by project
compileOnly("com.github.brahmkshatriya:echo:$libVersion")
compileOnly("com.squareup.okhttp3:okhttp:5.0.0-alpha.14")

implementation("org.nanohttpd:nanohttpd:2.3.1")
}
Expand Down
15 changes: 9 additions & 6 deletions ext/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.brahmkshatriya.echo.extension

import dev.brahmkshatriya.echo.common.helpers.ContinuationCallback.Companion.await
import dev.brahmkshatriya.echo.common.models.Album
import dev.brahmkshatriya.echo.common.models.ImageHolder.Companion.toImageHolder
import dev.brahmkshatriya.echo.common.models.Playlist
Expand Down Expand Up @@ -150,6 +151,8 @@ class DeezerApi(private val session: DeezerSession) {
add("Content-Language", language)
add("Content-Type", "application/json; charset=utf-8")
add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36")
add("X-User-IP", "1.1.1.1")
add("x-deezer-client-ip", "1.1.1.1")
if (method != "user.getArl") {
add("Cookie", "arl=$arl; sid=$sid")
} else {
Expand Down Expand Up @@ -188,7 +191,7 @@ class DeezerApi(private val session: DeezerSession) {
}
.build()

val response = client.newCall(request).execute()
val response = client.newCall(request).await()
val responseBody = response.body.string()

if (!response.isSuccessful) {
Expand Down Expand Up @@ -281,7 +284,7 @@ class DeezerApi(private val session: DeezerSession) {
return BigInteger(1, digest).toString(16).padStart(32, '0')
}

private fun getToken(params: Map<String, String>, sid: String): String {
private suspend fun getToken(params: Map<String, String>, sid: String): String {
val url = "https://connect.deezer.com/oauth/user_auth.php"
val httpUrl = url.toHttpUrlOrNull()!!.newBuilder().apply {
params.forEach { (key, value) -> addQueryParameter(key, value) }
Expand All @@ -298,20 +301,20 @@ class DeezerApi(private val session: DeezerSession) {
)
.build()

clientLog.newCall(request).execute().use { response ->
clientLog.newCall(request).await().use { response ->
if (!response.isSuccessful) throw Exception("Unexpected code $response")
return response.body.string()
}
}

fun getSid() {
val url = "https://www.deezer.com/"
suspend fun getSid() {
val url = "https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null"
val request = Request.Builder()
.url(url)
.get()
.build()

val response = clientLog.newCall(request).execute()
val response = clientLog.newCall(request).await()
response.headers.forEach {
if (it.second.startsWith("sid=")) {
session.updateCredentials(sid = it.second.substringAfter("sid=").substringBefore(";"))
Expand Down

0 comments on commit 30c4e56

Please sign in to comment.