From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 17 Feb 2025 01:31:00 +0000 (+0100)
Subject: To /playlist, add "empty" button to clear playlist.
X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/static/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=3556509b1033a907d27202a38f9a968d176c6d4f;p=ytplom

To /playlist, add "empty" button to clear playlist.
---

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 %}
-<a href="#playing">#playing</a>
+<a href="#playing">jump to playing</a>
 <button onclick="player_command('rebuild')">rebuild</button>
+<button onclick="player_command('empty')">empty</button>
 <hr />
 <table id="playlist_rows">
 </table>
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()