From: Christian Heller <c.heller@plomlompom.de>
Date: Fri, 28 Feb 2025 16:36:58 +0000 (+0100)
Subject: Add inject-and-jump-to-playing buttons.
X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7Bprefix%7D%7D/bar%20baz.html?a=commitdiff_plain;p=ytplom

Add inject-and-jump-to-playing buttons.
---

diff --git a/src/templates/file_data.tmpl b/src/templates/file_data.tmpl
index 0b069fa..e1247a3 100644
--- a/src/templates/file_data.tmpl
+++ b/src/templates/file_data.tmpl
@@ -31,6 +31,7 @@ async function update_file_data() {
         add_a_to(td_present, "yes", "/{{page_names.download}}/{{file.yt_id}}");
         add_text_to(td_present, " ");
         add_player_btn_to(td_present, 'add as next', `inject_${file_data.digest}`);
+        add_player_btn_to(td_present, 'add and play', `injectplay_${file_data.digest}`);
     } else {
         td_present.textContent = "no";
     }
diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl
index 8909d89..cf258a6 100644
--- a/src/templates/files.tmpl
+++ b/src/templates/files.tmpl
@@ -68,6 +68,7 @@ function populate_list_item_row(tr, file) {
     add_child_to('td', tr, {textContent: file.duration});
     const td_inject = add_child_to('td', tr);
     add_player_btn_to(td_inject, 'add as next', `inject_${file.digest}`, !file.present)
+    add_player_btn_to(td_inject, 'add as play', `injectplay_${file.digest}`, !file.present)
     add_tag_links_to(add_child_to('td', tr), file.tags_showable);
     add_a_to(add_child_to('td', tr), file.rel_path, `${PATH_PREFIX_FILE}${file.digest}`);
 }
diff --git a/src/ytplom/http.py b/src/ytplom/http.py
index 0e42e67..3785b07 100644
--- a/src/ytplom/http.py
+++ b/src/ytplom/http.py
@@ -167,11 +167,13 @@ class _TaskHandler(PlomHttpHandler):
             self.server.player.move_entry(int(command.split('_')[1]), False)
         elif command.startswith('rm_'):
             self.server.player.remove_by_idx(int(command.split('_')[1]))
-        elif command.startswith('inject_'):
+        elif command.startswith('inject_') or command.startswith('injectplay_'):
+            command, digest = command.split('_', 1)
             with DbConn() as conn:
-                file = VideoFile.get_one(
-                        conn, Hash.from_b64(command.split('_', 1)[1]))
+                file = VideoFile.get_one(conn, Hash.from_b64(digest))
             self.server.player.inject(file)
+            if 'injectplay' == command:
+                self.server.player.next()
         self.send_http(b'OK')
 
     def _purge_deleted_files(self) -> None: