home · contact · privacy
To /playlist, add "empty" button to clear playlist.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 17 Feb 2025 01:31:00 +0000 (02:31 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 17 Feb 2025 01:31:00 +0000 (02:31 +0100)
src/templates/playlist.tmpl
src/ytplom/http.py
src/ytplom/misc.py

index 9d4aa22f0c3ba7052df8f322fc47e1e46d121382..6f19dc3c4c473c4665b15d4818c69fb2909552ce 100644 (file)
@@ -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>
index a47a4e65b64951291657a3e6080c21ab82e80cc9..e1d893a496a86be6681acedbc9a34f4f924062b2 100644 (file)
@@ -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_'):
index 030f2e0ea7d763ec42da9f600dfcc139325dc005..57031f6a00afd9f871b24c0d42f99638e96a6803 100644 (file)
@@ -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()