From: Christian Heller Date: Fri, 29 Nov 2024 05:58:26 +0000 (+0100) Subject: To /files view, add "play" button for immediate playing of (present) files. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/static/todos?a=commitdiff_plain;h=96288cb00f11b2334c4d876a7ec250dc0a78834b;p=ytplom To /files view, add "play" button for immediate playing of (present) files. --- diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl index 0dda3db..a44066b 100644 --- a/src/templates/files.tmpl +++ b/src/templates/files.tmpl @@ -9,13 +9,14 @@ show absent:

known files (shown: {{files|length}}):

+
- {% for file in files %} - + {% endfor %}
presentpath
{{file.rel_path}}
+
{% endblock %} diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index 96cabd6..2bdb0c3 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -529,7 +529,7 @@ class Player: """ self._kill_queue.put(True) - self._mpv.command('playlist-play-index', self._idx) + self._play_at_index() def _kill_mpv(self) -> None: if self._mpv: @@ -537,6 +537,10 @@ class Player: self._mpv = None self._signal_update() + def _play_at_index(self): + if self._mpv: + self._mpv.command('playlist-play-index', self._idx) + @property def empty(self) -> bool: """Return if playlist empty.""" @@ -593,21 +597,18 @@ class Player: """Move player to previous item in playlist.""" if self._idx > 0: self._idx -= 1 - if self._mpv: - self._mpv.command('playlist-play-index', self._idx) + self._play_at_index() def next(self) -> None: """Move player to next item in playlist.""" if self._idx < len(self._files) - 1: self._idx += 1 - if self._mpv: - self._mpv.command('playlist-play-index', self._idx) + self._play_at_index() def jump_to(self, target_idx: int) -> None: """Move player to target_idx position in playlist.""" self._idx = target_idx - if self._mpv: - self._mpv.command('playlist-play-index', self._idx) + self._play_at_index() def move_entry(self, start_idx: int, upwards=True) -> None: """Move playlist entry at start_idx up or down one step.""" @@ -633,6 +634,16 @@ class Player: self._start_mpv() self._signal_update() + def inject_and_play(self, file: VideoFile) -> None: + """Inject file after current title, then jump to it.""" + if self._files: + self._idx += 1 + self._files.insert(self._idx, file) + if self._mpv: + self._mpv.command('loadfile', file.full_path, + 'insert-at', self._idx) + self._play_at_index() + class DownloadsManager: """Manages downloading and downloads access.""" @@ -744,6 +755,8 @@ class TaskHandler(BaseHTTPRequestHandler): postvars = parse_qs(self.rfile.read(body_length).decode()) if PAGE_NAMES['playlist'] == page_name: self._receive_player_command(list(postvars.keys())[0]) + if PAGE_NAMES['files'] == page_name: + self._receive_files_command(list(postvars.keys())[0]) elif PAGE_NAMES['file'] == page_name: self._receive_video_flag(B64Str(toks_url[2]), [FlagName(k) for k in postvars]) @@ -770,6 +783,14 @@ class TaskHandler(BaseHTTPRequestHandler): sleep(0.5) # avoid redir happening before current_file update self._redirect(Path('/')) + def _receive_files_command(self, command: str) -> None: + if command.startswith('play_'): + conn = DbConnection() + file = VideoFile.get_by_b64(conn, B64Str(command.split('_', 1)[1])) + conn.commit_close() + self.server.player.inject_and_play(file) + self._redirect(Path('/')) + def _receive_video_flag(self, rel_path_b64: B64Str, flag_names: list[FlagName]