From 3556509b1033a907d27202a38f9a968d176c6d4f Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 17 Feb 2025 02:31:00 +0100 Subject: [PATCH] To /playlist, add "empty" button to clear playlist. --- src/templates/playlist.tmpl | 3 ++- src/ytplom/http.py | 2 ++ src/ytplom/misc.py | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/templates/playlist.tmpl b/src/templates/playlist.tmpl index 9d4aa22..6f19dc3 100644 --- a/src/templates/playlist.tmpl +++ b/src/templates/playlist.tmpl @@ -50,8 +50,9 @@ event_handlers.push(function(data) { // update playlist {% block body %} -#playing +jump to playing +
diff --git a/src/ytplom/http.py b/src/ytplom/http.py index a47a4e6..e1d893a 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -140,6 +140,8 @@ class _TaskHandler(PlomHttpHandler): self.server.player.next() elif 'rebuild' == command: self.server.player.load_files_and_mpv() + elif 'empty' == command: + self.server.player.load_files_and_mpv(empty=True) elif command.startswith('jump_'): self.server.player.jump_to(int(command.split('_')[1])) elif command.startswith('up_'): diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 030f2e0..57031f6 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -621,16 +621,19 @@ class Player: self._mpv.command('loadfile', path, 'append') self._idx = 0 - def load_files_and_mpv(self) -> None: + def load_files_and_mpv(self, empty: bool = False) -> None: """Collect filtered files into playlist, shuffle, start player.""" - with DbConn() as conn: - known_files = {f.full_path: f for f in VideoFile.get_filtered( - conn, self.filter_path, self.needed_tags)} - self.playlist = [known_files[p] for p in PATH_DOWNLOADS.iterdir() - if p in known_files - and p.is_file() - and p.suffix[1:] in LEGAL_EXTENSIONS] - shuffle(self.playlist) + if empty: + self.playlist = [] + else: + with DbConn() as conn: + known_files = {f.full_path: f for f in VideoFile.get_filtered( + conn, self.filter_path, self.needed_tags)} + self.playlist = [known_files[p] for p in PATH_DOWNLOADS.iterdir() + if p in known_files + and p.is_file() + and p.suffix[1:] in LEGAL_EXTENSIONS] + shuffle(self.playlist) self._kill_mpv() self._start_mpv() -- 2.30.2