home · contact · privacy
In YT result page, don't directly link files, instead link their pages. master
authorChristian Heller <c.heller@plomlompom.de>
Tue, 10 Dec 2024 22:38:26 +0000 (23:38 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 10 Dec 2024 22:38:26 +0000 (23:38 +0100)
src/templates/yt_result.tmpl
src/ytplom/http.py

index 6e14dc46d4f4a84fc72ce6c1f61a9c24d8b171e4..ea81f4584a4787f8266d965ebf3a2702720d586d 100644 (file)
@@ -9,7 +9,7 @@
 <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_}} (<a href="{{youtube_prefix}}{{video_data.id_}}">watch</a>)</td></tr>
-<tr><th>download:</th><td>{% if is_temp %}working on it{% else %}<a href="/{{page_names.download}}/{{video_data.id_}}">{{ file_path if file_path else "please do" }}</a>{% endif %}</td></tr>
+<tr><th>download:</th><td>{% if is_temp %}working on it{% elif file_path %}<a href="/{{page_names.file}}/{{file_digest}}">{{file_path}}</a>{% else %}<a href="/{{page_names.download}}/{{video_data.id_}}">please do</a>{% endif %}</td></tr>
 <tr>
 <th>linked queries:</th>
 <td>
index e6b277588623537bfefaf7a9709e729e98599524..b406868bafb0426f55ab9868598a53336277f845 100644 (file)
@@ -248,14 +248,16 @@ class _TaskHandler(BaseHTTPRequestHandler):
         try:
             with DbConn() as conn:
                 file_data = VideoFile.get_by_yt_id(conn, video_id)
+                if file_data.missing:
+                    raise NotFoundException
+                self._redirect(Path('/')
+                               .joinpath(PAGE_NAMES['file'])
+                               .joinpath(file_data.digest.b64))
         except NotFoundException:
             self.server.downloads.queue_download(video_id)
             self._redirect(Path('/')
                            .joinpath(PAGE_NAMES['yt_result'])
                            .joinpath(video_id))
-            return
-        with file_data.full_path.open('rb') as video_file:
-            self._send_http(content=video_file.read())
 
     def _send_yt_query_page(self, query_id: QueryId) -> None:
         with DbConn() as conn:
@@ -284,15 +286,19 @@ class _TaskHandler(BaseHTTPRequestHandler):
                 video_data = YoutubeVideo.get_one(conn, video_id)
             except NotFoundException:
                 video_data = YoutubeVideo(video_id)
+            file_digest: Optional[str]
+            file_path: Optional[Path]
             try:
                 file = VideoFile.get_by_yt_id(conn, video_id)
-                file_path = file.full_path if file.present else None
+                file_digest = file.digest.b64
+                file_path = file.rel_path if file.present else None
             except NotFoundException:
-                file_path = None
+                file_path, file_digest = None, None
         self._send_rendered_template(
                 _NAME_TEMPLATE_YT_VIDEO,
                 {'video_data': video_data,
                  'is_temp': video_id in self.server.downloads.ids_unfinished,
+                 'file_digest': file_digest,
                  'file_path': file_path,
                  'youtube_prefix': YOUTUBE_URL_PREFIX,
                  'queries': linked_queries})