From 7d25aead70c6645a6085eb5592000897a41d74a5 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 28 Nov 2024 15:27:34 +0100 Subject: [PATCH] Improve/simplify templating. --- src/templates/files.tmpl | 4 ++-- src/templates/playlist.tmpl | 24 ++++++++++++++++-------- src/ytplom/misc.py | 31 +++++++++++-------------------- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl index 9af8487..35786b4 100644 --- a/src/templates/files.tmpl +++ b/src/templates/files.tmpl @@ -5,8 +5,8 @@ {{ macros.nav_head(page_names, "files") }}

downloaded videos:

{% endblock %} diff --git a/src/templates/playlist.tmpl b/src/templates/playlist.tmpl index d62e7ea..b25d131 100644 --- a/src/templates/playlist.tmpl +++ b/src/templates/playlist.tmpl @@ -29,8 +29,10 @@ window.onload = keep_updated; {% block css %} -table { width: 100%; } #status { text-align: center; font-weight: bold; } +table { width: 100%; } +th { text-align: center; } +td { vertical-align: top; } td.history { width: 50%; } {% endblock %} @@ -49,13 +51,19 @@ td.history { width: 50%; } -{% for prev_video, next_video in tuples %} - -{{ prev_video.basename }} - -{{ next_video.basename }} - -{% endfor %} +pastfuture + + + + + + + + {% endblock %} diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py index b207d49..e5f3c6f 100644 --- a/src/ytplom/misc.py +++ b/src/ytplom/misc.py @@ -47,12 +47,14 @@ PlayerUpdateId = NewType('PlayerUpdateId', str) B64Str = NewType('B64Str', str) PageNames: TypeAlias = dict[str, PathStr] DownloadsIndex: TypeAlias = dict[YoutubeId, PathStr] -PlaylistTuples = list[tuple[Optional['VideoFile'], Optional['VideoFile']]] TemplateContext: TypeAlias = dict[ - str, None | bool | PlayerUpdateId | Optional[PathStr] | YoutubeId - | QueryText | QuotaCost | list[FlagName] | 'VideoFile' | 'YoutubeVideo' - | PageNames | list['YoutubeVideo'] | list['YoutubeQuery'] - | list[tuple[B64Str, PathStr]] | PlaylistTuples] + str, + None | bool + | PageNames | PathStr | PlayerUpdateId | QueryText | QuotaCost + | 'VideoFile' | YoutubeId | 'YoutubeVideo' + | list[FlagName] | list['VideoFile'] | list['YoutubeVideo'] + | list['YoutubeQuery'] +] # major expected directories PATH_HOME = PathStr(environ.get('HOME', '')) @@ -917,9 +919,9 @@ class TaskHandler(BaseHTTPRequestHandler): def _send_files_index(self) -> None: conn = DbConnection() - files = [(f.rel_path_b64, f.rel_path) for f in VideoFile.get_all(conn)] + files = VideoFile.get_all(conn) conn.commit_close() - files.sort(key=lambda t: t[1]) + files.sort(key=lambda t: t.rel_path) self._send_rendered_template(NAME_TEMPLATE_FILES, {'files': files}) def _send_missing_json(self) -> None: @@ -936,22 +938,11 @@ class TaskHandler(BaseHTTPRequestHandler): headers=[('Content-type', 'application/json')]) def _send_playlist(self) -> None: - tuples: PlaylistTuples = [] - i: int = 0 - while True: - prev, next_ = None, None - if len(self.server.player.prev_files) > i: - prev = self.server.player.prev_files[i] - if len(self.server.player.next_files) > i: - next_ = self.server.player.next_files[i] - if not (prev or next_): - break - tuples += [(prev, next_)] - i += 1 self._send_rendered_template( NAME_TEMPLATE_PLAYLIST, {'last_update': self.server.player.last_update, 'running': self.server.player.is_running, 'paused': self.server.player.is_paused, 'current_video': self.server.player.current_file, - 'tuples': tuples}) + 'prev_files': self.server.player.prev_files, + 'next_files': self.server.player.next_files}) -- 2.30.2