Merge pull request #679 from ram130/fix-trakt-continue-watching

This commit is contained in:
Nayif 2026-03-19 22:24:47 +05:30 committed by GitHub
commit ef7ac71363
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View file

@ -91,8 +91,31 @@ export async function mergeTraktContinueWatching({
const thirtyDaysAgo = Date.now() - (30 * 24 * 60 * 60 * 1000);
const sortedPlaybackItems = [...playbackItems]
.sort((a, b) => new Date(b.paused_at).getTime() - new Date(a.paused_at).getTime())
.slice(0, 30);
.sort((a, b) => {
const getBaseTime = (item: any) =>
new Date(
item.paused_at ||
item.updated_at ||
item.last_watched_at ||
0
).getTime();
const getPriorityTime = (item: any) => {
const base = getBaseTime(item);
// NEW EPISODE PRIORITY BOOST
if (item.episode && (item.progress ?? 0) < 1) {
const aired = new Date(item.episode.first_aired || 0).getTime();
const daysSinceAired = (Date.now() - aired) / (1000 * 60 * 60 * 24);
if (daysSinceAired >= 0 && daysSinceAired < 60) {
return base + 1000000000; // boost to top on aired ep
}
}
return base;
};
return getPriorityTime(b) - getPriorityTime(a);
})
.slice(0, 30);
for (const item of sortedPlaybackItems) {
try {

View file

@ -1396,7 +1396,9 @@ export class TraktService {
*/
public async getPlaybackProgressWithImages(type?: 'movies' | 'shows'): Promise<TraktPlaybackItem[]> {
try {
const endpoint = type ? `/sync/playback/${type}?extended=images` : '/sync/playback?extended=images';
// extended=full,images so we receive episode.first_aired (needed for the new-episode priority boost
// in mergeTraktContinueWatching.ts — brand-new/recently-aired episodes now jump to the top of Continue Watching).
const endpoint = type ? `/sync/playback/${type}?extended=full,images` : '/sync/playback?extended=full,images';
return this.apiRequest<TraktPlaybackItem[]>(endpoint);
} catch (error) {
logger.error('[TraktService] Failed to get playback progress with images:', error);