From a0f7ecec9ae31be74cceaa43c98d1f281e75cd30 Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Fri, 21 Aug 2026 00:33:55 +0800 Subject: [PATCH] Add completion-time sort option for downloaded items --- app/ytdl.py | 5 +++++ ui/src/app/app.component.ts | 4 +++- ui/src/app/download-list.component.html | 1 + ui/src/app/downloads.service.ts | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/ytdl.py b/app/ytdl.py index e4e2575..435e30c 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -138,6 +138,7 @@ class DownloadInfo: self.status = "pending" self.size = None self.timestamp = time.time_ns() + self.completion_timestamp = None self.error = error self.entry = entry self.playlist_item_limit = playlist_item_limit @@ -417,6 +418,9 @@ class PersistentQueue: v.thumbnail = None if not hasattr(v, 'duration'): v.duration = None + # Ensure completion timestamp exists (added for completion-time sorting) + if not hasattr(v, 'completion_timestamp'): + v.completion_timestamp = None self.dict[k] = Download(None, None, None, None, None, None, {}, v) def exists(self, key): @@ -743,6 +747,7 @@ class DownloadQueue: if download.canceled: asyncio.create_task(self.notifier.canceled(download.info.url)) else: + download.info.completion_timestamp = time.time_ns() self.done.put(download) asyncio.create_task(self.notifier.completed(download.info)) diff --git a/ui/src/app/app.component.ts b/ui/src/app/app.component.ts index 9e7efe9..3ea2e73 100644 --- a/ui/src/app/app.component.ts +++ b/ui/src/app/app.component.ts @@ -38,7 +38,7 @@ export class AppComponent implements OnInit, OnDestroy { status: DownloadTab = 'queued'; selectedFolder = 'all'; filter = ''; - sort: 'date' | 'title' | 'size' = 'date'; + sort: 'date' | 'completion' | 'title' | 'size' = 'date'; sortAscending = false; view: 'list' | 'grid' = 'list'; isAdvancedOpen = false; @@ -413,6 +413,8 @@ export class AppComponent implements OnInit, OnDestroy { rows.sort((a, b) => a.value.title.localeCompare(b.value.title, 'zh') * dir); } else if (this.sort === 'size') { rows.sort((a, b) => ((a.value.size || 0) - (b.value.size || 0)) * dir); + } else if (this.sort === 'completion') { + rows.sort((a, b) => ((a.value.completion_timestamp || a.value.timestamp || 0) - (b.value.completion_timestamp || b.value.timestamp || 0)) * dir); } else { rows.sort((a, b) => ((a.value.timestamp || 0) - (b.value.timestamp || 0)) * dir); } diff --git a/ui/src/app/download-list.component.html b/ui/src/app/download-list.component.html index c2b8ebd..cb1750c 100644 --- a/ui/src/app/download-list.component.html +++ b/ui/src/app/download-list.component.html @@ -12,6 +12,7 @@ diff --git a/ui/src/app/downloads.service.ts b/ui/src/app/downloads.service.ts index bc08309..67b60d7 100644 --- a/ui/src/app/downloads.service.ts +++ b/ui/src/app/downloads.service.ts @@ -52,6 +52,7 @@ export interface Download { duration?: number; thumbnail?: string; timestamp?: number; + completion_timestamp?: number; website?: string; file_exists?: boolean; checked?: boolean;