mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-23 01:32:11 +00:00
Merge pull request #153 from aayushrautela/main
Fix trakt scrobbling algorithm
This commit is contained in:
commit
9d32c483eb
1 changed files with 57 additions and 17 deletions
|
|
@ -227,25 +227,47 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
contentGroups[contentKey].episodes.push({ key, episodeId, progress, progressPercent });
|
contentGroups[contentKey].episodes.push({ key, episodeId, progress, progressPercent });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch Trakt watched movies once and reuse
|
// Fetch Trakt watched movies and shows once and reuse
|
||||||
const traktMoviesSetPromise = (async () => {
|
const traktDataPromise = (async () => {
|
||||||
try {
|
try {
|
||||||
const traktService = TraktService.getInstance();
|
const traktService = TraktService.getInstance();
|
||||||
const isAuthed = await traktService.isAuthenticated();
|
const isAuthed = await traktService.isAuthenticated();
|
||||||
if (!isAuthed) return new Set<string>();
|
if (!isAuthed) return { watchedMovies: new Set<string>(), watchedShows: new Set<string>() };
|
||||||
if (typeof (traktService as any).getWatchedMovies === 'function') {
|
|
||||||
const watched = await (traktService as any).getWatchedMovies();
|
const [watchedMovies, watchedShows] = await Promise.all([
|
||||||
if (Array.isArray(watched)) {
|
// Get watched movies
|
||||||
const ids = watched
|
(async () => {
|
||||||
.map((w: any) => w?.movie?.ids?.imdb)
|
if (typeof (traktService as any).getWatchedMovies === 'function') {
|
||||||
.filter(Boolean)
|
const watched = await (traktService as any).getWatchedMovies();
|
||||||
.map((imdb: string) => (imdb.startsWith('tt') ? imdb : `tt${imdb}`));
|
if (Array.isArray(watched)) {
|
||||||
return new Set<string>(ids);
|
const ids = watched
|
||||||
}
|
.map((w: any) => w?.movie?.ids?.imdb)
|
||||||
}
|
.filter(Boolean)
|
||||||
return new Set<string>();
|
.map((imdb: string) => (imdb.startsWith('tt') ? imdb : `tt${imdb}`));
|
||||||
|
return new Set<string>(ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Set<string>();
|
||||||
|
})(),
|
||||||
|
// Get watched shows
|
||||||
|
(async () => {
|
||||||
|
if (typeof (traktService as any).getWatchedShows === 'function') {
|
||||||
|
const watched = await (traktService as any).getWatchedShows();
|
||||||
|
if (Array.isArray(watched)) {
|
||||||
|
const ids = watched
|
||||||
|
.map((w: any) => w?.show?.ids?.imdb)
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((imdb: string) => (imdb.startsWith('tt') ? imdb : `tt${imdb}`));
|
||||||
|
return new Set<string>(ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Set<string>();
|
||||||
|
})()
|
||||||
|
]);
|
||||||
|
|
||||||
|
return { watchedMovies, watchedShows };
|
||||||
} catch {
|
} catch {
|
||||||
return new Set<string>();
|
return { watchedMovies: new Set<string>(), watchedShows: new Set<string>() };
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
@ -253,10 +275,13 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
const groupPromises = Object.values(contentGroups).map(async (group) => {
|
const groupPromises = Object.values(contentGroups).map(async (group) => {
|
||||||
try {
|
try {
|
||||||
if (!isSupportedId(group.id)) return;
|
if (!isSupportedId(group.id)) return;
|
||||||
|
|
||||||
|
// Get Trakt data for filtering
|
||||||
|
const { watchedMovies, watchedShows } = await traktDataPromise;
|
||||||
|
|
||||||
// Skip movies that are already watched on Trakt
|
// Skip movies that are already watched on Trakt
|
||||||
if (group.type === 'movie') {
|
if (group.type === 'movie') {
|
||||||
const watchedSet = await traktMoviesSetPromise;
|
if (watchedMovies.has(group.id)) {
|
||||||
if (watchedSet.has(group.id)) {
|
|
||||||
// Optional: sync local store to watched to prevent reappearance
|
// Optional: sync local store to watched to prevent reappearance
|
||||||
try {
|
try {
|
||||||
await storageService.setWatchProgress(group.id, 'movie', {
|
await storageService.setWatchProgress(group.id, 'movie', {
|
||||||
|
|
@ -270,6 +295,14 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip shows that are marked as watched on Trakt (entire show)
|
||||||
|
if (group.type === 'series') {
|
||||||
|
if (watchedShows.has(group.id)) {
|
||||||
|
logger.log(`🚫 [TraktFilter] Skipping show marked as watched on Trakt: ${group.id}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const cachedData = await getCachedMetadata(group.type, group.id);
|
const cachedData = await getCachedMetadata(group.type, group.id);
|
||||||
if (!cachedData?.basicContent) return;
|
if (!cachedData?.basicContent) return;
|
||||||
const { metadata, basicContent } = cachedData;
|
const { metadata, basicContent } = cachedData;
|
||||||
|
|
@ -392,6 +425,13 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this show is marked as watched on Trakt (entire show)
|
||||||
|
const { watchedShows } = await traktDataPromise;
|
||||||
|
if (watchedShows.has(showId)) {
|
||||||
|
logger.log(`🚫 [TraktSync] Skipping show marked as watched on Trakt: ${showId}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const nextEpisode = info.episode + 1;
|
const nextEpisode = info.episode + 1;
|
||||||
const cachedData = await getCachedMetadata('series', showId);
|
const cachedData = await getCachedMetadata('series', showId);
|
||||||
if (!cachedData?.basicContent) return;
|
if (!cachedData?.basicContent) return;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue