home · contact · privacy
Improve video_about page.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 15 Nov 2024 05:06:18 +0000 (06:06 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 15 Nov 2024 05:06:18 +0000 (06:06 +0100)
templates/video_about.tmpl
ytplom.py

index 0bee6a43ba72d9316dbc43aea425a1c3ae095039..06e0c47d84e5cdd9bc6d7a525bebcd93fdd524f4 100644 (file)
@@ -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>
index 692f26adbd782c82a4c2f4ae3cf4d99c635236f0..13e650fd2124d19d012379f65293fa812dc11ee2 100755 (executable)
--- 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})