home · contact · privacy
On playlist view, if playlist empty, force Player (re-)loading files. master
authorChristian Heller <c.heller@plomlompom.de>
Fri, 29 Nov 2024 01:11:25 +0000 (02:11 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 29 Nov 2024 01:11:25 +0000 (02:11 +0100)
src/ytplom/misc.py

index e325af8c6ce104be8215ddfefefe57df53866df5..22cfb99de3302f507ed3b8cef8bf92f12f9e9c85 100644 (file)
@@ -473,7 +473,7 @@ class Player:
 
     def __init__(self) -> None:
         self.last_update = PlayerUpdateId('')
-        self._load_filenames()
+        self.load_files()
         self._mpv: Optional[MPV] = None
         self._kill_queue: Queue = Queue()
         self._monitoring_kill = False
@@ -498,7 +498,8 @@ class Player:
 
         Thread(target=kill_on_queue_get, daemon=True).start()
 
-    def _load_filenames(self) -> None:
+    def load_files(self) -> None:
+        """Collect files in PATH_DOWNLOADS DB-known and of legal extension."""
         conn = DbConnection()
         known_files = {f.full_path: f for f in VideoFile.get_all(conn)}
         conn.commit_close()
@@ -544,6 +545,11 @@ class Player:
             self._mpv = None
         self._signal_update()
 
+    @property
+    def empty(self) -> bool:
+        """Return if playlist empty."""
+        return 0 == len(self._files)
+
     @property
     def current_file(self) -> Optional[VideoFile]:
         """Return what we assume is the currently playing file."""
@@ -631,7 +637,7 @@ class Player:
     def reload(self) -> None:
         """Close MPV, re-read (and re-shuffle) filenames, then re-start MPV."""
         self._kill_mpv()
-        self._load_filenames()
+        self.load_files()
         self._start_mpv()
         self._signal_update()
 
@@ -990,6 +996,8 @@ class TaskHandler(BaseHTTPRequestHandler):
                         headers=[('Content-type', 'application/json')])
 
     def _send_playlist(self) -> None:
+        if self.server.player.empty:
+            self.server.player.load_files()
         self._send_rendered_template(
                 NAME_TEMPLATE_PLAYLIST,
                 {'last_update': self.server.player.last_update,