home · contact · privacy
To /files view, add "play" button for immediate playing of (present) files.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 29 Nov 2024 05:58:26 +0000 (06:58 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 29 Nov 2024 05:58:26 +0000 (06:58 +0100)
src/templates/files.tmpl
src/ytplom/misc.py

index 0dda3db556192f219dcb91f24b9b36b390694d37..a44066b5c733cb31df98ee1db77907abf55dc0ac 100644 (file)
@@ -9,13 +9,14 @@ show absent: <input type="checkbox" name="show_absent" {% if show_absent %}check
 <input type="submit" value="filter" />
 </form>
 <p>known files (shown: {{files|length}}):</p>
+<form action="files" method="POST">
 <table>
-<tr><th>present</th><th>path</th></td>
 {% for file in files %}
 <tr>
-<td><input type="checkbox"{% if file.present %} checked{% endif %} disabled/></td>
+<td><input type="submit" name="play_{{file.rel_path_b64}}" value="play" {% if not file.present %}disabled {% endif %}/></td>
 <td><a href="/{{page_names.file}}/{{file.rel_path_b64}}">{{file.rel_path}}</a></td>
 </tr>
 {% endfor %}
 </table>
+</form>
 {% endblock %}
index 96cabd6bcd50ae26739892bf6aa725249e132956..2bdb0c3a716b76e8c4e04d29be18634701d35493 100644 (file)
@@ -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]