mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-21 00:32:04 +00:00
fix: robust Trakt continue-watching sort + new episode priority boost
This commit is contained in:
parent
9980f6b784
commit
38890942a1
2 changed files with 26 additions and 3 deletions
|
|
@ -91,8 +91,31 @@ export async function mergeTraktContinueWatching({
|
||||||
|
|
||||||
const thirtyDaysAgo = Date.now() - (30 * 24 * 60 * 60 * 1000);
|
const thirtyDaysAgo = Date.now() - (30 * 24 * 60 * 60 * 1000);
|
||||||
const sortedPlaybackItems = [...playbackItems]
|
const sortedPlaybackItems = [...playbackItems]
|
||||||
.sort((a, b) => new Date(b.paused_at).getTime() - new Date(a.paused_at).getTime())
|
.sort((a, b) => {
|
||||||
.slice(0, 30);
|
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) {
|
for (const item of sortedPlaybackItems) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1396,7 +1396,7 @@ export class TraktService {
|
||||||
*/
|
*/
|
||||||
public async getPlaybackProgressWithImages(type?: 'movies' | 'shows'): Promise<TraktPlaybackItem[]> {
|
public async getPlaybackProgressWithImages(type?: 'movies' | 'shows'): Promise<TraktPlaybackItem[]> {
|
||||||
try {
|
try {
|
||||||
const endpoint = type ? `/sync/playback/${type}?extended=images` : '/sync/playback?extended=images';
|
const endpoint = type ? `/sync/playback/${type}?extended=full,images` : '/sync/playback?extended=full,images';
|
||||||
return this.apiRequest<TraktPlaybackItem[]>(endpoint);
|
return this.apiRequest<TraktPlaybackItem[]>(endpoint);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[TraktService] Failed to get playback progress with images:', error);
|
logger.error('[TraktService] Failed to get playback progress with images:', error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue