From eeffb6b6e21ce4abe1194e6ed0b4e1d263b77a65 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Tue, 10 Dec 2024 16:57:51 +0100
Subject: [PATCH] In all-pages player control, link playing title to file page.

---
 src/templates/_base.tmpl | 20 ++++++++++++--------
 src/ytplom/http.py       |  1 +
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/templates/_base.tmpl b/src/templates/_base.tmpl
index 9f19af6..2161f8f 100644
--- a/src/templates/_base.tmpl
+++ b/src/templates/_base.tmpl
@@ -8,6 +8,8 @@
 const RETRY_INTERVAL_S = 5;
 const PATH_EVENTS = '/{{page_names.events}}';
 const PATH_PLAYER = '/{{page_names.player}}';
+const PATH_PLAYLIST = '/{{page_names.playlist}}';
+const PATH_PREFIX_FILE = '/{{page_names.file}}/';
 var event_handlers = [];
 var events_params = '';
 
@@ -42,11 +44,12 @@ function player_command(command) {
     send_to({command: [command]}, PATH_PLAYER); }
 
 event_handlers.push(function(data) {  // update player state
-    const state_desc = data.running ? (data.paused ? 'paused' : 'playing') : 'stopped';
-    for (const [id, text] of [['player_state', `${state_desc}: ${data.title}`],
+    for (const [id, text] of [['player_state', data.running ? (data.paused ? 'paused' : 'playing') : 'stopped'],
+                              ['a_playing', data.title],
                               ['btn_pause', data.paused ? 'resume' : 'pause'],
-                              ['btn_stop', data.running? 'stop' : 'play']]) {
-        document.getElementById(id).textContent = text; }});
+                              ['btn_stop', data.running ? 'stop' : 'play']]) {
+        document.getElementById(id).textContent = text; }
+    document.getElementById('a_playing').href = data.title_digest ? `${PATH_PREFIX_FILE}${data.title_digest}` : PATH_PLAYLIST ; })
 
 {% block script %}
 {% endblock %}
@@ -65,11 +68,12 @@ td, th { vertical-align: top; text-align: left; }
 {{ macros.link_if("playlist" != selected, page_names.playlist) }}
 · {{ macros.link_if("files" != selected, page_names.files) }}
 · {{ macros.link_if("yt_queries" != selected, page_names.yt_queries, "queries") }}
-| <button onclick="player_command('prev')">prev</button>
+<hr />
+<button onclick="player_command('prev')">prev</button>
 <button onclick="player_command('next')">next</button>
-<button id="btn_pause" onclick="player_command('pause')">?</button>
-<button id="btn_stop" onclick="player_command('stop')">?</button>
-<span id="player_state" /></span>
+<button id="btn_pause" onclick="player_command('pause')"></button>
+<button id="btn_stop" onclick="player_command('stop')"></button>
+· <span id="player_state" /></span>: <a id="a_playing"></a>
 <hr />
 {% block body %}
 {% endblock %}
diff --git a/src/ytplom/http.py b/src/ytplom/http.py
index 90c3ef0..4535361 100644
--- a/src/ytplom/http.py
+++ b/src/ytplom/http.py
@@ -381,6 +381,7 @@ class _TaskHandler(BaseHTTPRequestHandler):
                     'last_update': self.server.player.last_update,
                     'running': self.server.player.is_running,
                     'paused': self.server.player.is_paused,
+                    'title_digest': playing.digest.b64 if playing else '',
                     'title': str(playing.rel_path) if playing else 'none'}
                 if 'playlist' in params.as_dict:
                     data['playlist_files'] = [
-- 
2.30.2