From 9e2db50b77fdd99578eddc55d07cc343bacb049b Mon Sep 17 00:00:00 2001 From: jmir1 Date: Wed, 9 Jun 2021 12:47:03 +0200 Subject: [PATCH] fix kitsu tracking and other trackinf related fixes --- .../data/track/anilist/AnilistApi.kt | 5 ++++ .../data/track/anilist/AnilistModels.kt | 2 +- .../tachiyomi/data/track/kitsu/Kitsu.kt | 8 +++++-- .../tachiyomi/data/track/kitsu/KitsuApi.kt | 23 ++++++++++++------- .../tachiyomi/data/track/kitsu/KitsuModels.kt | 18 +++++++-------- .../data/track/myanimelist/MyAnimeListApi.kt | 2 +- .../ui/setting/SettingsAdvancedController.kt | 11 +++++++-- app/src/main/res/values/strings.xml | 5 ++-- 8 files changed, 49 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt index 47ce19e391..85c0a71bd4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt @@ -542,11 +542,16 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { private const val apiUrl = "https://graphql.anilist.co/" private const val baseUrl = "https://anilist.co/api/v2/" private const val baseMangaUrl = "https://anilist.co/manga/" + private const val baseAnimeUrl = "https://anilist.co/anime/" fun mangaUrl(mediaId: Int): String { return baseMangaUrl + mediaId } + fun animeUrl(mediaId: Int): String { + return baseAnimeUrl + mediaId + } + fun authUrl(): Uri = "${baseUrl}oauth/authorize".toUri().buildUpon() .appendQueryParameter("client_id", clientId) .appendQueryParameter("response_type", "token") diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt index 49038a118f..a2cca40283 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt @@ -58,7 +58,7 @@ data class ALAnime( total_episodes = this@ALAnime.total_episodes cover_url = image_url_lge summary = description ?: "" - tracking_url = AnilistApi.mangaUrl(media_id) + tracking_url = AnilistApi.animeUrl(media_id) publishing_status = this@ALAnime.publishing_status publishing_type = type if (start_date_fuzzy != 0L) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index 47d2e0b746..6a6d5c6bae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -19,10 +19,12 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { companion object { const val READING = 1 + const val WATCHING = 11 const val COMPLETED = 2 const val ON_HOLD = 3 const val DROPPED = 4 const val PLAN_TO_READ = 5 + const val PLAN_TO_WATCH = 15 } @StringRes @@ -43,13 +45,15 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } override fun getStatusListAnime(): List { - return listOf(READING, PLAN_TO_READ, COMPLETED, ON_HOLD, DROPPED) + return listOf(WATCHING, PLAN_TO_WATCH, COMPLETED, ON_HOLD, DROPPED) } override fun getStatus(status: Int): String = with(context) { when (status) { READING -> getString(R.string.currently_reading) + WATCHING -> getString(R.string.currently_watching) PLAN_TO_READ -> getString(R.string.want_to_read) + PLAN_TO_WATCH -> getString(R.string.want_to_watch) COMPLETED -> getString(R.string.completed) ON_HOLD -> getString(R.string.on_hold) DROPPED -> getString(R.string.dropped) @@ -114,7 +118,7 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { track.media_id = remoteTrack.media_id update(track) } else { - track.status = READING + track.status = WATCHING track.score = 0F add(track) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt index 83e7dc1614..f012986b23 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt @@ -95,7 +95,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) putJsonObject("media") { putJsonObject("data") { put("id", track.media_id) - put("type", "manga") + put("type", "anime") } } } @@ -245,7 +245,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) private suspend fun algoliaSearchAnime(key: String, query: String): List { return withIOContext { val jsonObject = buildJsonObject { - put("params", "query=$query$algoliaFilter") + put("params", "query=$query$algoliaFilterAnime") } client.newCall( @@ -295,8 +295,8 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) suspend fun findLibAnime(track: AnimeTrack, userId: String): AnimeTrack? { return withIOContext { val url = "${baseUrl}library-entries".toUri().buildUpon() - .encodedQuery("filter[manga_id]=${track.media_id}&filter[user_id]=$userId") - .appendQueryParameter("include", "manga") + .encodedQuery("filter[anime_id]=${track.media_id}&filter[user_id]=$userId") + .appendQueryParameter("include", "anime") .build() authClient.newCall(GET(url.toString())) .await() @@ -304,8 +304,8 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) .let { val data = it["data"]!!.jsonArray if (data.size > 0) { - val manga = it["included"]!!.jsonArray[0].jsonObject - KitsuLibAnime(data[0].jsonObject, manga).toTrack() + val anime = it["included"]!!.jsonArray[0].jsonObject + KitsuLibAnime(data[0].jsonObject, anime).toTrack() } else { null } @@ -338,7 +338,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) return withIOContext { val url = "${baseUrl}library-entries".toUri().buildUpon() .encodedQuery("filter[id]=${track.media_id}") - .appendQueryParameter("include", "manga") + .appendQueryParameter("include", "anime") .build() authClient.newCall(GET(url.toString())) .await() @@ -349,7 +349,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) val anime = it["included"]!!.jsonArray[0].jsonObject KitsuLibAnime(data[0].jsonObject, anime).toTrack() } else { - throw Exception("Could not find manga") + throw Exception("Could not find anime") } } } @@ -393,6 +393,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) private const val baseUrl = "https://kitsu.io/api/edge/" private const val loginUrl = "https://kitsu.io/api/oauth/token" private const val baseMangaUrl = "https://kitsu.io/manga/" + private const val baseAnimeUrl = "https://kitsu.io/anime/" private const val algoliaKeyUrl = "https://kitsu.io/api/edge/algolia-keys/media/" private const val algoliaUrl = @@ -400,11 +401,17 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) private const val algoliaAppId = "AWQO5J657S" private const val algoliaFilter = "&facetFilters=%5B%22kind%3Amanga%22%5D&attributesToRetrieve=%5B%22synopsis%22%2C%22canonicalTitle%22%2C%22chapterCount%22%2C%22posterImage%22%2C%22startDate%22%2C%22subtype%22%2C%22endDate%22%2C%20%22id%22%5D" + private const val algoliaFilterAnime = + "&facetFilters=%5B%22kind%3Aanime%22%5D&attributesToRetrieve=%5B%22synopsis%22%2C%22canonicalTitle%22%2C%22episodeCount%22%2C%22posterImage%22%2C%22startDate%22%2C%22subtype%22%2C%22endDate%22%2C%20%22id%22%5D" fun mangaUrl(remoteId: Int): String { return baseMangaUrl + remoteId } + fun animeUrl(remoteId: Int): String { + return baseAnimeUrl + remoteId + } + fun refreshTokenRequest(token: String) = POST( loginUrl, body = FormBody.Builder() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt index 9a2cea3609..912bb12049 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt @@ -55,7 +55,7 @@ class KitsuSearchManga(obj: JsonObject) { class KitsuSearchAnime(obj: JsonObject) { val id = obj["id"]!!.jsonPrimitive.int private val canonicalTitle = obj["canonicalTitle"]!!.jsonPrimitive.content - private val chapterCount = obj["chapterCount"]?.jsonPrimitive?.intOrNull + private val episodeCount = obj["episodeCount"]?.jsonPrimitive?.intOrNull val subType = obj["subtype"]?.jsonPrimitive?.contentOrNull val original = try { obj["posterImage"]?.jsonObject?.get("original")?.jsonPrimitive?.content @@ -74,10 +74,10 @@ class KitsuSearchAnime(obj: JsonObject) { fun toTrack() = AnimeTrackSearch.create(TrackManager.KITSU).apply { media_id = this@KitsuSearchAnime.id title = canonicalTitle - total_episodes = chapterCount ?: 0 + total_episodes = episodeCount ?: 0 cover_url = original ?: "" summary = synopsis - tracking_url = KitsuApi.mangaUrl(media_id) + tracking_url = KitsuApi.animeUrl(media_id) publishing_status = if (endDate == null) { "Publishing" } else { @@ -130,7 +130,7 @@ class KitsuLibAnime(obj: JsonObject, anime: JsonObject) { val id = anime["id"]!!.jsonPrimitive.int private val canonicalTitle = anime["attributes"]!!.jsonObject["canonicalTitle"]!!.jsonPrimitive.content private val episodeCount = anime["attributes"]!!.jsonObject["episodeCount"]?.jsonPrimitive?.intOrNull - val type = anime["attributes"]!!.jsonObject["animeType"]?.jsonPrimitive?.contentOrNull.orEmpty() + val type = anime["attributes"]!!.jsonObject["subtype"]?.jsonPrimitive?.contentOrNull.orEmpty() val original = anime["attributes"]!!.jsonObject["posterImage"]!!.jsonObject["original"]!!.jsonPrimitive.content private val synopsis = anime["attributes"]!!.jsonObject["synopsis"]!!.jsonPrimitive.content private val startDate = anime["attributes"]!!.jsonObject["startDate"]?.jsonPrimitive?.contentOrNull.orEmpty() @@ -145,7 +145,7 @@ class KitsuLibAnime(obj: JsonObject, anime: JsonObject) { total_episodes = episodeCount ?: 0 cover_url = original summary = synopsis - tracking_url = KitsuApi.mangaUrl(media_id) + tracking_url = KitsuApi.animeUrl(media_id) publishing_status = this@KitsuLibAnime.status publishing_type = type start_date = startDate @@ -155,11 +155,11 @@ class KitsuLibAnime(obj: JsonObject, anime: JsonObject) { } private fun toTrackStatus() = when (status) { - "current" -> Kitsu.READING + "current" -> Kitsu.WATCHING "completed" -> Kitsu.COMPLETED "on_hold" -> Kitsu.ON_HOLD "dropped" -> Kitsu.DROPPED - "planned" -> Kitsu.PLAN_TO_READ + "planned" -> Kitsu.PLAN_TO_WATCH else -> throw Exception("Unknown status") } } @@ -178,11 +178,11 @@ fun Track.toKitsuScore(): String? { } fun AnimeTrack.toKitsuStatus() = when (status) { - Kitsu.READING -> "current" + Kitsu.WATCHING -> "current" Kitsu.COMPLETED -> "completed" Kitsu.ON_HOLD -> "on_hold" Kitsu.DROPPED -> "dropped" - Kitsu.PLAN_TO_READ -> "planned" + Kitsu.PLAN_TO_WATCH -> "planned" else -> throw Exception("Unknown status") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt index b39319676a..83ca6c7659 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt @@ -152,7 +152,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI summary = obj["synopsis"]?.jsonPrimitive?.content ?: "" total_episodes = obj["num_episodes"]!!.jsonPrimitive.int cover_url = obj["main_picture"]?.jsonObject?.get("large")?.jsonPrimitive?.content ?: "" - tracking_url = "https://myanimelist.net/manga/$media_id" + tracking_url = "https://myanimelist.net/anime/$media_id" publishing_status = obj["status"]!!.jsonPrimitive.content.replace("_", " ") publishing_type = obj["media_type"]!!.jsonPrimitive.content.replace("_", " ") start_date = try { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index 3b11796002..5c5e2f05ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -11,6 +11,7 @@ import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.animelib.AnimelibUpdateService import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.library.LibraryUpdateService @@ -154,14 +155,20 @@ class SettingsAdvancedController : SettingsController() { key = "pref_refresh_library_covers" titleRes = R.string.pref_refresh_library_covers - onClick { LibraryUpdateService.start(context, target = Target.COVERS) } + onClick { + LibraryUpdateService.start(context.createAttributionContext("manga"), target = Target.COVERS) + AnimelibUpdateService.start(context.createAttributionContext("anime"), target = AnimelibUpdateService.Target.COVERS) + } } preference { key = "pref_refresh_library_tracking" titleRes = R.string.pref_refresh_library_tracking summaryRes = R.string.pref_refresh_library_tracking_summary - onClick { LibraryUpdateService.start(context, target = Target.TRACKING) } + onClick { + LibraryUpdateService.start(context.createAttributionContext("manga"), target = Target.TRACKING) + AnimelibUpdateService.start(context.createAttributionContext("anime"), target = AnimelibUpdateService.Target.TRACKING) + } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b1fb512164..6d5dd3500c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -469,9 +469,9 @@ Delete history for manga that are not saved in your library Are you sure? Read chapters and progress of non-library manga will be lost Entries deleted - Refresh library manga covers + Refresh library covers Refresh tracking - Updates status, score and last chapter read from the tracking services + Updates status, score and progress from the tracking services Dump crash logs Saves error logs to a file for sharing with the developers Crash logs saved @@ -650,6 +650,7 @@ Plan to read Plan to watch Want to read + Want to watch Rereading Rewatching Score