Skip to content

Commit

Permalink
Revert "Try to fix json error"
Browse files Browse the repository at this point in the history
This reverts commit 7453481.
  • Loading branch information
LuftVerbot committed Dec 15, 2024
1 parent 7453481 commit cabc9f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions ext/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
16 changes: 7 additions & 9 deletions ext/src/main/java/dev/brahmkshatriya/echo/extension/DeezerApi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 @@ -151,8 +150,6 @@ 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 @@ -191,7 +188,7 @@ class DeezerApi(private val session: DeezerSession) {
}
.build()

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

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

private suspend fun getToken(params: Map<String, String>, sid: String): String {
private 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 @@ -301,19 +298,20 @@ class DeezerApi(private val session: DeezerSession) {
)
.build()

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

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"
fun getSid() {
val url = "https://www.deezer.com/"
val request = Request.Builder()
.url(url)
.get()
.build()
val response = clientLog.newCall(request).await()

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

0 comments on commit cabc9f3

Please sign in to comment.