redo how trakt marks stuff as watched to local

This commit is contained in:
chrisk325 2026-01-03 18:33:06 +05:30 committed by GitHub
parent e323906083
commit 4603d1dc2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -301,52 +301,60 @@ class WatchedService {
* Check if a movie is marked as watched (locally) * Check if a movie is marked as watched (locally)
*/ */
public async isMovieWatched(imdbId: string): Promise<boolean> { public async isMovieWatched(imdbId: string): Promise<boolean> {
try { try {
// First check local watched flag const isAuthed = await this.traktService.isAuthenticated();
const localWatched = await mmkvStorage.getItem(`watched:movie:${imdbId}`);
if (localWatched === 'true') {
return true;
}
// Check local progress if (isAuthed) {
const progress = await storageService.getWatchProgress(imdbId, 'movie'); const traktWatched =
if (progress) { await this.traktService.isMovieWatchedAccurate(imdbId);
const progressPercent = (progress.currentTime / progress.duration) * 100; if (traktWatched) return true;
if (progressPercent >= 85) {
return true;
}
}
return false;
} catch (error) {
logger.error('[WatchedService] Error checking movie watched status:', error);
return false;
} }
const local = await mmkvStorage.getItem(`watched:movie:${imdbId}`);
return local === 'true';
} catch {
return false;
}
} }
/** /**
* Check if an episode is marked as watched (locally) * Check if an episode is marked as watched (locally)
*/ */
public async isEpisodeWatched(showId: string, season: number, episode: number): Promise<boolean> { public async isEpisodeWatched(
try { showId: string,
const episodeId = `${showId}:${season}:${episode}`; season: number,
episode: number
): Promise<boolean> {
try {
const isAuthed = await this.traktService.isAuthenticated();
// Check local progress if (isAuthed) {
const progress = await storageService.getWatchProgress(showId, 'series', episodeId); const traktWatched =
if (progress) { await this.traktService.isEpisodeWatchedAccurate(
const progressPercent = (progress.currentTime / progress.duration) * 100; showId,
if (progressPercent >= 85) { season,
return true; episode
} );
} if (traktWatched) return true;
return false;
} catch (error) {
logger.error('[WatchedService] Error checking episode watched status:', error);
return false;
} }
}
const episodeId = `${showId}:${season}:${episode}`;
const progress = await storageService.getWatchProgress(
showId,
'series',
episodeId
);
if (!progress) return false;
const pct = (progress.currentTime / progress.duration) * 100;
return pct >= 99;
} catch {
return false;
}
}
/** /**
* Set local watched status by creating a "completed" progress entry * Set local watched status by creating a "completed" progress entry
*/ */