diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistInterceptor.kt index 8c21070c4..388b3e1b5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistInterceptor.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.track.anilist +import eu.kanade.tachiyomi.BuildConfig import okhttp3.Interceptor import okhttp3.Response import java.io.IOException @@ -40,6 +41,7 @@ class AnilistInterceptor(val anilist: Anilist, private var token: String?) : Int // Add the authorization header to the original request. val authRequest = originalRequest.newBuilder() .addHeader("Authorization", "Bearer ${oauth!!.access_token}") + .header("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})") .build() return chain.proceed(authRequest) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt index 9d2073707..0b905b514 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt @@ -182,8 +182,8 @@ class BangumiApi( ) companion object { - private const val clientId = "bgm10555cda0762e80ca" - private const val clientSecret = "8fff394a8627b4c388cbf349ec865775" + private const val clientId = "bgm291665acbd06a4c28" + private const val clientSecret = "43e5ce36b207de16e5d3cfd3e79118db" private const val apiUrl = "https://api.bgm.tv" private const val oauthUrl = "https://bgm.tv/oauth/access_token" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt index d2183fdbf..c8a0d15fc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt @@ -1,8 +1,10 @@ package eu.kanade.tachiyomi.data.track.bangumi +import eu.kanade.tachiyomi.BuildConfig import kotlinx.serialization.json.Json import okhttp3.FormBody import okhttp3.Interceptor +import okhttp3.Request import okhttp3.Response import uy.kohesive.injekt.injectLazy @@ -29,22 +31,20 @@ class BangumiInterceptor(private val bangumi: Bangumi) : Interceptor { } } - val authRequest = if (originalRequest.method == "GET") { - originalRequest.newBuilder() - .header("User-Agent", "Tachiyomi") - .url( - originalRequest.url.newBuilder() - .addQueryParameter("access_token", currAuth.access_token).build(), - ) - .build() - } else { - originalRequest.newBuilder() - .post(addToken(currAuth.access_token, originalRequest.body as FormBody)) - .header("User-Agent", "Tachiyomi") - .build() - } - - return chain.proceed(authRequest) + return originalRequest.newBuilder() + .header("User-Agent", "antsylich/Mihon/v${BuildConfig.VERSION_NAME} (Android) (http://github.com/mihonapp/mihon)") + .apply { + if (originalRequest.method == "GET") { + val newUrl = originalRequest.url.newBuilder() + .addQueryParameter("access_token", currAuth.access_token) + .build() + url(newUrl) + } else { + post(addToken(currAuth.access_token, originalRequest.body as FormBody)) + } + } + .build() + .let(chain::proceed) } fun newAuth(oauth: OAuth?) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/KavitaInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/KavitaInterceptor.kt index 8b26c3e02..89708ccc5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/KavitaInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/KavitaInterceptor.kt @@ -18,7 +18,7 @@ class KavitaInterceptor(private val kavita: Kavita) : Interceptor { // Add the authorization header to the original request. val authRequest = originalRequest.newBuilder() .addHeader("Authorization", "Bearer $jwtToken") - .header("User-Agent", "Tachiyomi Kavita v${BuildConfig.VERSION_NAME}") + .header("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})") .build() return chain.proceed(authRequest) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt index fe7e42292..da9aff7fc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuInterceptor.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.track.kitsu +import eu.kanade.tachiyomi.BuildConfig import kotlinx.serialization.json.Json import okhttp3.Interceptor import okhttp3.Response @@ -34,6 +35,7 @@ class KitsuInterceptor(private val kitsu: Kitsu) : Interceptor { // Add the authorization header to the original request. val authRequest = originalRequest.newBuilder() .addHeader("Authorization", "Bearer ${oauth!!.access_token}") + .header("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})") .header("Accept", "application/vnd.api+json") .header("Content-Type", "application/vnd.api+json") .build() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/KomgaApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/KomgaApi.kt index 5992727ae..47c3d7b41 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/KomgaApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/KomgaApi.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.track.komga +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.network.GET @@ -8,6 +9,7 @@ import eu.kanade.tachiyomi.network.parseAs import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import logcat.LogPriority +import okhttp3.Headers import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.Request @@ -23,6 +25,12 @@ class KomgaApi( private val client: OkHttpClient, ) { + private val headers: Headers by lazy { + Headers.Builder() + .add("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})") + .build() + } + private val json: Json by injectLazy() suspend fun getTrackSearch(url: String): TrackSearch = @@ -30,12 +38,12 @@ class KomgaApi( try { val track = with(json) { if (url.contains(READLIST_API)) { - client.newCall(GET(url)) + client.newCall(GET(url, headers)) .awaitSuccess() .parseAs() .toTrack() } else { - client.newCall(GET(url)) + client.newCall(GET(url, headers)) .awaitSuccess() .parseAs() .toTrack() @@ -43,7 +51,7 @@ class KomgaApi( } val progress = client - .newCall(GET("${url.replace("/api/v1/series/", "/api/v2/series/")}/read-progress/tachiyomi")) + .newCall(GET("${url.replace("/api/v1/series/", "/api/v2/series/")}/read-progress/tachiyomi", headers)) .awaitSuccess().let { with(json) { if (url.contains("/api/v1/series/")) { @@ -80,6 +88,7 @@ class KomgaApi( client.newCall( Request.Builder() .url("${track.tracking_url.replace("/api/v1/series/", "/api/v2/series/")}/read-progress/tachiyomi") + .headers(headers) .put(payload.toRequestBody("application/json".toMediaType())) .build(), ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt index a8ec37708..4fa1ec6ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListInterceptor.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.track.myanimelist +import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.network.parseAs import kotlinx.serialization.json.Json import okhttp3.Interceptor @@ -34,6 +35,7 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var t // Add the authorization header to the original request val authRequest = originalRequest.newBuilder() .addHeader("Authorization", "Bearer ${oauth!!.access_token}") + .header("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})") .build() val response = chain.proceed(authRequest) @@ -50,6 +52,7 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var t val newRequest = originalRequest.newBuilder() .addHeader("Authorization", "Bearer ${newToken.access_token}") + .header("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})") .build() return chain.proceed(newRequest) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt index d84b01330..5db8a5799 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt @@ -192,8 +192,8 @@ class ShikimoriApi( ) companion object { - private const val clientId = "1aaf4cf232372708e98b5abc813d795b539c5a916dbbfe9ac61bf02a360832cc" - private const val clientSecret = "229942c742dd4cde803125d17d64501d91c0b12e14cb1e5120184d77d67024c0" + private const val clientId = "PB9dq8DzI405s7wdtwTdirYqHiyVMh--djnP7lBUqSA" + private const val clientSecret = "NajpZcOBKB9sJtgNcejf8OB9jBN1OYYoo-k4h2WWZus" private const val baseUrl = "https://shikimori.one" private const val apiUrl = "$baseUrl/api" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriInterceptor.kt index 84c64462f..aa2d4247a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriInterceptor.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.data.track.shikimori +import eu.kanade.tachiyomi.BuildConfig import kotlinx.serialization.json.Json import okhttp3.Interceptor import okhttp3.Response @@ -33,7 +34,7 @@ class ShikimoriInterceptor(private val shikimori: Shikimori) : Interceptor { // Add the authorization header to the original request. val authRequest = originalRequest.newBuilder() .addHeader("Authorization", "Bearer ${oauth!!.access_token}") - .header("User-Agent", "Tachiyomi") + .header("User-Agent", "Mihon v${BuildConfig.VERSION_NAME} (${BuildConfig.APPLICATION_ID})") .build() return chain.proceed(authRequest)