From ea4ae8b4212ec0e1d7d78e039bbe4c2a17f31ac2 Mon Sep 17 00:00:00 2001 From: paregi12 Date: Thu, 19 Mar 2026 23:55:22 +0530 Subject: [PATCH] fix(mal): enforce strict season-aware matching for episodes - Removed the fallback to the show-level malId (which often points to Season 1) during scrobbling. - Prioritized ARM/TMDB date-based mapping in watchedService and MalSync. - Enabled tmdbId mapping when marking an entire season as watched in SeriesContent.tsx to ensure accurate season resolution on MyAnimeList. --- src/components/metadata/SeriesContent.tsx | 19 +++++++++++-------- src/services/mal/MalSync.ts | 10 +++++----- src/services/watchedService.ts | 7 +------ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/components/metadata/SeriesContent.tsx b/src/components/metadata/SeriesContent.tsx index bdc5984b..c8397052 100644 --- a/src/components/metadata/SeriesContent.tsx +++ b/src/components/metadata/SeriesContent.tsx @@ -724,18 +724,21 @@ const SeriesContentComponent: React.FC = ({ const lastEp = Math.max(...episodeNumbers); const lastEpisodeData = seasonEpisodes.find(e => e.episode_number === lastEp); const totalEpisodes = Object.values(groupedEpisodes).reduce((acc, curr) => acc + (curr?.length || 0), 0); - + const showTmdbId = (metadata as any)?.tmdbId || (metadata as any)?.external_ids?.tmdb_id; + MalSync.scrobbleEpisode( - metadata.name, - lastEp, - totalEpisodes, - 'series', - currentSeason, + metadata.name, + lastEp, + totalEpisodes, + 'series', + currentSeason, imdbId, - lastEpisodeData?.air_date // Pass release date for accuracy + lastEpisodeData?.air_date, // Pass release date for accuracy + undefined, // Don't pass the base show malId, force it to resolve correct season + undefined, // No dayIndex for season completion + showTmdbId ); } - // Re-sync with source of truth loadEpisodesProgress(); diff --git a/src/services/mal/MalSync.ts b/src/services/mal/MalSync.ts index 6dbeba8e..2ba9d872 100644 --- a/src/services/mal/MalSync.ts +++ b/src/services/mal/MalSync.ts @@ -194,11 +194,11 @@ export const MalSync = { return; } - let malId: number | null = providedMalId || null; + let malId: number | null = null; let finalEpisodeNumber = episodeNumber; - // Strategy 1: TMDB-based Resolution (High Accuracy for Specials) - if (!malId && tmdbId && releaseDate) { + // Strategy 1: TMDB-based Resolution (High Accuracy for Specials/Seasons) + if (tmdbId && releaseDate) { const tmdbResult = await ArmSyncService.resolveByTmdb(tmdbId, releaseDate, dayIndex); if (tmdbResult) { malId = tmdbResult.malId; @@ -296,11 +296,11 @@ export const MalSync = { try { if (!MalAuth.isAuthenticated()) return; - let malId: number | null = providedMalId || null; + let malId: number | null = null; let finalEpisodeNumber = episodeNumber; // Resolve ID using same strategies as scrobbling - if (!malId && tmdbId && releaseDate) { + if (tmdbId && releaseDate) { const tmdbResult = await ArmSyncService.resolveByTmdb(tmdbId, releaseDate, dayIndex); if (tmdbResult) { malId = tmdbResult.malId; diff --git a/src/services/watchedService.ts b/src/services/watchedService.ts index 43608f64..5e78fa71 100644 --- a/src/services/watchedService.ts +++ b/src/services/watchedService.ts @@ -332,15 +332,10 @@ class WatchedService { // Sync to MAL if (MalAuth.isAuthenticated() && (showImdbId || malId || tmdbId)) { - // Strategy 0: Direct Match (if malId is provided) let synced = false; - if (malId) { - await MalSync.scrobbleDirect(malId, episode); - synced = true; - } // Strategy 1: TMDB-based Resolution (High Accuracy for Specials) - if (!synced && releaseDate && tmdbId) { + if (releaseDate && tmdbId) { try { const tmdbResult = await ArmSyncService.resolveByTmdb(tmdbId, releaseDate, dayIndex); if (tmdbResult) {