From: Christian Heller Date: Fri, 29 Nov 2024 01:11:25 +0000 (+0100) Subject: On playlist view, if playlist empty, force Player (re-)loading files. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Btodo.comment%7D%7D?a=commitdiff_plain;h=a89d39de1ed147238a0ecf52fea0eca3cb1d0870;p=ytplom On playlist view, if playlist empty, force Player (re-)loading files. --- diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index e325af8..22cfb99 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -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,