animeonsen: implement oauth, add aniyomi user-agent
This commit is contained in:
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'AnimeOnsen'
|
||||
pkgNameSuffix = 'all.animeonsen'
|
||||
extClass = '.AnimeOnsen'
|
||||
extVersionCode = 1
|
||||
extVersionCode = 2
|
||||
libVersion = '13'
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
||||
Log.i("bruh", token)
|
||||
val tokenResponse = client.newCall(
|
||||
POST(
|
||||
"https://auth.animeonsen.xyz/oauth/token",
|
||||
headers,
|
||||
body,
|
||||
)
|
||||
).execute().body!!.string()
|
||||
|
||||
val tokenObject = Json.decodeFromString<JsonObject>(tokenResponse)
|
||||
|
||||
token = tokenObject["access_token"]!!.jsonPrimitive.content
|
||||
}
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
|
@ -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<VideoData>(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)"
|
||||
|
Reference in New Issue
Block a user