From: Christian Heller <c.heller@plomlompom.de>
Date: Sun, 13 Apr 2025 21:56:49 +0000 (+0200)
Subject: Allow YouTube links, but make them optional via config.
X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/%7B%7B%20web_path%20%7D%7D/error?a=commitdiff_plain;p=ytplom

Allow YouTube links, but make them optional via config.
---

diff --git a/src/templates/yt_result.tmpl b/src/templates/yt_result.tmpl
index 9a7ca49..2aa3737 100644
--- a/src/templates/yt_result.tmpl
+++ b/src/templates/yt_result.tmpl
@@ -24,7 +24,7 @@ event_handlers.download = function(data) {
 <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>YouTube ID:</th><td>{% if youtube_prefix|length > 0 %}<a href="{{youtube_prefix}}{{video_data.id_}}">{{video_data.id_}}{% else %}{{video_data.id_}}{% endif %}</td></tr>
 <tr><th>download:</th><td id="status"></td></tr>
 <tr>
 <th>linked queries:</th>
diff --git a/src/ytplom/http.py b/src/ytplom/http.py
index 0c98d2b..e1105a6 100644
--- a/src/ytplom/http.py
+++ b/src/ytplom/http.py
@@ -13,10 +13,9 @@ from plomlib.web import (
         PlomHttpHandler, PlomHttpServer, PlomQueryMap, MIME_APP_JSON)
 from ytplom.db import Hash, DbConn
 from ytplom.misc import (
-        FilterStr, FlagName, QueryId, QueryText, TagSet, YoutubeId,
-        FILE_FLAGS, PATH_THUMBNAILS, ensure_expected_dirs,
-        Config, DownloadsManager, Player, QuotaLog, VideoFile, YoutubeQuery,
-        YoutubeVideo
+    FILE_FLAGS, PATH_THUMBNAILS, YOUTUBE_URL_PREFIX, ensure_expected_dirs,
+    Config, DownloadsManager, FilterStr, FlagName, Player, QueryId, QueryText,
+    QuotaLog, TagSet, VideoFile, YoutubeId, YoutubeQuery, YoutubeVideo
 )
 from ytplom.primitives import NotFoundException, PATH_APP_DATA
 
@@ -406,7 +405,10 @@ class _TaskHandler(PlomHttpHandler):
                  'is_temp': video_id in self.server.downloads.ids_unfinished,
                  'file_digest': file_digest,
                  'file_path': file_path,
-                 'queries': linked_queries})
+                 'queries': linked_queries,
+                 'youtube_prefix': (
+                     YOUTUBE_URL_PREFIX if self.server.config.link_originals
+                     else '')})
 
     def _send_yt_queries_index_and_search(self) -> None:
         with DbConn() as conn:
diff --git a/src/ytplom/misc.py b/src/ytplom/misc.py
index ade627e..a3f337b 100644
--- a/src/ytplom/misc.py
+++ b/src/ytplom/misc.py
@@ -34,7 +34,8 @@ DEFAULTS = {
     'tags_prefilter_needed': [],
     'tags_display_whitelist': [],
     'tags_default': ['new'],
-    'allow_file_edit': True
+    'allow_file_edit': True,
+    'link_originals': True
 }
 
 # type definitions for mypy
@@ -183,6 +184,7 @@ class Config:
     tags_prefilter_whitelist: TagSet
     tags_display_whitelist: TagSet
     tags_default: TagSet
+    link_originals: bool
 
     def __init__(self):
         def set_attrs_from_dict(d):