diff --git a/src/all/animeonsen/build.gradle b/src/all/animeonsen/build.gradle index 56e228e8e..9e2917fe5 100644 --- a/src/all/animeonsen/build.gradle +++ b/src/all/animeonsen/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'AnimeOnsen' pkgNameSuffix = 'all.animeonsen' extClass = '.AnimeOnsen' - extVersionCode = 1 + extVersionCode = 2 libVersion = '13' } diff --git a/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AOAPIInterceptor.kt b/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AOAPIInterceptor.kt index 8d6f3cc44..8bf61e253 100644 --- a/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AOAPIInterceptor.kt +++ b/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AOAPIInterceptor.kt @@ -1,11 +1,15 @@ package eu.kanade.tachiyomi.animeextension.all.animeonsen -import android.util.Base64 -import android.util.Log -import eu.kanade.tachiyomi.network.GET -import okhttp3.HttpUrl.Companion.toHttpUrl +import eu.kanade.tachiyomi.network.POST +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.jsonPrimitive +import okhttp3.Headers import okhttp3.Interceptor +import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient +import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response class AOAPIInterceptor(client: OkHttpClient) : Interceptor { @@ -13,19 +17,27 @@ class AOAPIInterceptor(client: OkHttpClient) : Interceptor { private val token: String init { - val cookie = client.cookieJar - .loadForRequest("https://animeonsen.xyz".toHttpUrl()) - .find { it.name == "ao.session" }?.value - ?: client.newCall(GET("https://animeonsen.xyz")).execute().header("set-cookie") + val body = """ + { + "client_id": "f296be26-28b5-4358-b5a1-6259575e23b7", + "client_secret": "349038c4157d0480784753841217270c3c5b35f4281eaee029de21cb04084235", + "grant_type": "client_credentials" + } + """.trimIndent().toRequestBody("application/json".toMediaType()) - token = String( - Base64.decode( - java.net.URLDecoder.decode(cookie, "utf-8"), - Base64.DEFAULT + val headers = Headers.headersOf("user-agent", AO_USER_AGENT) + + val tokenResponse = client.newCall( + POST( + "https://auth.animeonsen.xyz/oauth/token", + headers, + body, ) - ) + ).execute().body!!.string() - Log.i("bruh", token) + val tokenObject = Json.decodeFromString(tokenResponse) + + token = tokenObject["access_token"]!!.jsonPrimitive.content } override fun intercept(chain: Interceptor.Chain): Response { diff --git a/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AnimeOnsen.kt b/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AnimeOnsen.kt index eb49b909e..2c8df05d0 100644 --- a/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AnimeOnsen.kt +++ b/src/all/animeonsen/src/eu/kanade/tachiyomi/animeextension/all/animeonsen/AnimeOnsen.kt @@ -49,7 +49,8 @@ class AnimeOnsen : AnimeHttpSource() { } override fun headersBuilder(): Headers.Builder = Headers.Builder() - .add("Referer", baseUrl) + .add("referer", baseUrl) + .add("user-agent", AO_USER_AGENT) // ============================== Popular =============================== // The site doesn't have a popular anime tab, so we use the home page instead (latest anime). @@ -91,7 +92,10 @@ class AnimeOnsen : AnimeHttpSource() { val videoData = json.decodeFromString(response.body!!.string()) val videoUrl = videoData.uri.stream val subtitleLangs = videoData.metadata.subtitles - val headers = Headers.headersOf("Referer", baseUrl) + val headers = Headers.headersOf( + "referer", baseUrl, + "user-agent", AO_USER_AGENT, + ) val video = try { val subtitles = videoData.uri.subtitles.keys.map { val lang = subtitleLangs[it]!!.jsonPrimitive.content @@ -166,3 +170,5 @@ class AnimeOnsen : AnimeHttpSource() { thumbnail_url = "https://api.animeonsen.xyz/v4/image/420x600/$content_id" } } + +const val AO_USER_AGENT = "Aniyomi/app (mobile)"