Push actual episode number to AniList instead of watched-episode count

When marking a show COMPLETED on AniList, progress now comes from
parsing the season/episode locator off each watched episode's ID and
taking the max episode number, falling back to episodes.size only if
that parsing yields nothing. Previously it always pushed episodes.size,
which undercounts progress for shows with specials or merged
multi-season watch history.
This commit is contained in:
KhooLy 2026-07-19 17:12:45 +03:00
parent f4ea52a890
commit e9ccd2e358

View file

@ -63,7 +63,9 @@ class ExternalSyncPushCoordinator @Inject constructor(
if (watched && !profile.anilistAccessToken.isNullOrBlank()) {
launch {
val token = profile.anilistAccessToken
runCatching { pushAnilistListEntry(token, meta, "COMPLETED", episodes.size.takeIf { it > 0 }) }
val progress = episodes.mapNotNull { it.id?.let { id -> TraktIntegration.episodeLocator(id)?.episode } }.maxOrNull()
?: episodes.size.takeIf { it > 0 }
runCatching { pushAnilistListEntry(token, meta, "COMPLETED", progress) }
.onSuccess { success ->
if (success) profileManager.clearExternalSyncFailure(profile.id, "anilist")
else profileManager.recordExternalSyncFailure(profile.id, "anilist")