From 453f3accb836e0bf5189ef4b52ff66750d81008a Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Fri, 15 Nov 2024 06:06:18 +0100
Subject: [PATCH] Improve video_about page.

---
 templates/video_about.tmpl | 11 ++---------
 ytplom.py                  | 10 +++++-----
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/templates/video_about.tmpl b/templates/video_about.tmpl
index 0bee6a4..06e0c47 100644
--- a/templates/video_about.tmpl
+++ b/templates/video_about.tmpl
@@ -8,15 +8,8 @@
 <tr><th>description:</th><td>{{video_data.description}}</td></tr>
 <tr><th>duration:</th><td>{{video_data.duration}}</td></tr>
 <tr><th>definition:</th><td>{{video_data.definition}}</td></tr>
-<tr><th>YouTube ID:</th><td>{{video_data.id_}}</td></tr>
-<tr>
-<th>actions:</th>
-<td>
-<ul>
-<li><a href="{{youtube_prefix}}{{video_data.id_}}">watch on YouTube</a>
-<li><a href="/dl/{{video_data.id_}}">{% if available %}watch locally{% else %}download{% endif %}</a>
-</td>
-</tr>
+<tr><th>YouTube ID:</th><td>{{video_data.id_}} (<a href="{{youtube_prefix}}{{video_data.id_}}">watch</a>)</td></tr>
+<tr><th>download:</th><td><a href="/dl/{{video_data.id_}}">{{ file_path if file_path else "please do" }}</a></td></tr>
 <tr>
 <th>linked queries:</th>
 <td>
diff --git a/ytplom.py b/ytplom.py
index 692f26a..13e650f 100755
--- a/ytplom.py
+++ b/ytplom.py
@@ -34,9 +34,10 @@ AmountDownloads = NewType('AmountDownloads', int)
 PlayerUpdateId = NewType('PlayerUpdateId', str)
 DownloadsDb: TypeAlias = dict[VideoId, PathStr]
 TemplateContext: TypeAlias = dict[
-        str, None | bool | PlayerUpdateId | PathStr | VideoId | QueryText
-        | QuotaCost | 'VideoData' | list['VideoData'] | list['QueryData']
-        | list[tuple[VideoId, PathStr]] | list[tuple[PathStr, PathStr]]]
+        str, None | bool | PlayerUpdateId | Optional[PathStr] | VideoId
+        | QueryText | QuotaCost | 'VideoData' | list['VideoData']
+        | list['QueryData'] | list[tuple[VideoId, PathStr]]
+        | list[tuple[PathStr, PathStr]]]
 
 
 class NotFoundException(BaseException):
@@ -631,7 +632,6 @@ class TaskHandler(BaseHTTPRequestHandler):
                                         'quota_count': quota_count})
 
     def _send_video_about(self, video_id: VideoId) -> None:
-        downloads_db = self._make_downloads_db()
         conn = DatabaseConnection()
         linked_queries = QueryData.get_all_for_video(conn, video_id)
         try:
@@ -642,7 +642,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         self._send_rendered_template(
                 NAME_TEMPLATE_VIDEO_ABOUT,
                 {'video_data': video_data,
-                 'available': video_data.id_ in downloads_db,
+                 'file_path': self._make_downloads_db().get(video_id, None),
                  'youtube_prefix': YOUTUBE_URL_PREFIX,
                  'queries': linked_queries})
 
-- 
2.30.2