mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-03-22 18:47:44 +00:00
Merge pull request #679 from ram130/fix-trakt-continue-watching
This commit is contained in:
commit
ef7ac71363
2 changed files with 28 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue