fix up next yet again (final fix probably)

This commit is contained in:
chrisk325 2026-01-03 01:50:43 +05:30 committed by GitHub
parent a079649563
commit faa4f341e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -241,43 +241,41 @@ const ContinueWatchingSection = React.forwardRef<ContinueWatchingRef>((props, re
} }
}, []); }, []);
// Helper function to find the next episode const findNextEpisode = useCallback((
const findNextEpisode = useCallback((currentSeason: number, currentEpisode: number, videos: any[]) => { currentSeason: number,
currentEpisode: number,
videos: any[],
watchedSet?: Set<string>,
showId?: string
) => {
if (!videos || !Array.isArray(videos)) return null; if (!videos || !Array.isArray(videos)) return null;
// Sort videos to ensure correct order
const sortedVideos = [...videos].sort((a, b) => { const sortedVideos = [...videos].sort((a, b) => {
if (a.season !== b.season) return a.season - b.season; if (a.season !== b.season) return a.season - b.season;
return a.episode - b.episode; return a.episode - b.episode;
}); });
// Strategy 1: Look for next episode in the same season const isAlreadyWatched = (season: number, episode: number): boolean => {
let nextEp = sortedVideos.find(v => v.season === currentSeason && v.episode === currentEpisode + 1); if (!watchedSet || !showId) return false;
const cleanShowId = showId.startsWith('tt') ? showId : `tt${showId}`;
return watchedSet.has(`${cleanShowId}:${season}:${episode}`) ||
watchedSet.has(`${showId}:${season}:${episode}`);
};
// Strategy 2: If not found, look for the first episode of the next season for (const video of sortedVideos) {
if (!nextEp) { if (video.season < currentSeason) continue;
nextEp = sortedVideos.find(v => v.season === currentSeason + 1 && v.episode === 1); if (video.season === currentSeason && video.episode <= currentEpisode) continue;
}
if (isAlreadyWatched(video.season, video.episode)) continue;
// Strategy 3: Just find the very next video in the list after the current one
// This handles cases where episode numbering isn't sequential or S+1 E1 isn't the standard start if (isEpisodeReleased(video)) {
if (!nextEp) { return video;
const currentIndex = sortedVideos.findIndex(v => v.season === currentSeason && v.episode === currentEpisode);
if (currentIndex !== -1 && currentIndex + 1 < sortedVideos.length) {
const candidate = sortedVideos[currentIndex + 1];
// Ensure we didn't just jump to a random special; check reasonable bounds if needed,
// but generally taking the next sorted item is correct for sequential viewing.
nextEp = candidate;
} }
} }
// Verify the found episode is released
if (nextEp && isEpisodeReleased(nextEp)) {
return nextEp;
}
return null; return null;
}, []); }, []);
// Modified loadContinueWatching to render incrementally // Modified loadContinueWatching to render incrementally
const loadContinueWatching = useCallback(async (isBackgroundRefresh = false) => { const loadContinueWatching = useCallback(async (isBackgroundRefresh = false) => {