From: Christian Heller Date: Tue, 10 Dec 2024 22:38:26 +0000 (+0100) Subject: In YT result page, don't directly link files, instead link their pages. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/process?a=commitdiff_plain;h=b118c993fa56a537701b0a610abc46890416ace0;p=ytplom In YT result page, don't directly link files, instead link their pages. --- diff --git a/src/templates/yt_result.tmpl b/src/templates/yt_result.tmpl index 6e14dc4..ea81f45 100644 --- a/src/templates/yt_result.tmpl +++ b/src/templates/yt_result.tmpl @@ -9,7 +9,7 @@ duration:{{video_data.duration}} definition:{{video_data.definition}} YouTube ID:{{video_data.id_}} (watch) -download:{% if is_temp %}working on it{% else %}{{ file_path if file_path else "please do" }}{% endif %} +download:{% if is_temp %}working on it{% elif file_path %}{{file_path}}{% else %}please do{% endif %} linked queries: diff --git a/src/ytplom/http.py b/src/ytplom/http.py index e6b2775..b406868 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -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})