From e3aaf396711564cafa8a2e74497dd17612c8a97b Mon Sep 17 00:00:00 2001 From: girst Date: Mon, 3 Jan 2022 17:12:57 +0100 Subject: [PATCH] expose additional metadata link in 'more actions' section also emojifies invidious/youtube links there --- app/templates/macros.imp.j2 | 9 +++++++++ app/youtube/__init__.py | 2 ++ app/youtube/lib.py | 1 + app/youtube/templates/watch.html.j2 | 5 +++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/templates/macros.imp.j2 b/app/templates/macros.imp.j2 index 4469084..c9177b6 100644 --- a/app/templates/macros.imp.j2 +++ b/app/templates/macros.imp.j2 @@ -110,20 +110,29 @@ {% set icons = { 'raw': '🎞️', 'json': '💡', + 'meta': '📜', 'audio': '🎧', 'comments': '💬', + 'iv': '🔼', + 'yt': '▶️', } %} {% set texts = { 'raw': 'show raw video', 'json': 'view json metadata', + 'meta': 'view additional metadata', 'audio': 'listen to audio only', 'comments': 'view comments', + 'iv': 'watch on invidious', + 'yt': 'youtu.be', } %} {% set actions = { 'raw': '/watch?v='~subject~'&show=raw', 'json': '/watch?v='~subject~'&show=json', + 'meta': '/watch?v='~subject~'&show=meta', 'audio': '/watch?v='~subject~'&show=audio', 'comments': 'https://old.reddit.com'~subject, + 'iv': 'https://redirect.invidious.io/watch?v='~subject, + 'yt': 'https://youtu.be/'~subject, } %} {# #}{{ icons[action] }}{# diff --git a/app/youtube/__init__.py b/app/youtube/__init__.py index e2ef6b0..56f5a09 100644 --- a/app/youtube/__init__.py +++ b/app/youtube/__init__.py @@ -158,6 +158,8 @@ def watch(): # this is the subset of (useful) keys that are not present in the # Android API response. the special key '_' contains ready-to-use # parsed versions of that data. + if error and not metadata: + return {'error': True, error: errdetails}, 400 # TODO: better (test _CpR4o81XQc) parsed = microformat_parser(metadata) return {'microformat': metadata.get('microformat'),'cards':metadata.get('cards'), '_':parsed} else: diff --git a/app/youtube/lib.py b/app/youtube/lib.py index 0c83d91..bc1e442 100644 --- a/app/youtube/lib.py +++ b/app/youtube/lib.py @@ -65,6 +65,7 @@ def channel_exists(feed_id): def microformat_parser(metadata): """ parses additional metadata only available with get_video_info(metaOnly=True) """ + # WARN: breaks if metadata == None (e.g. invalid video id) meta2 = metadata.get('microformat',{}).get('playerMicroformatRenderer',{}) all_countries = """AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BV BW BY BZ CA CC CD CF CG CH diff --git a/app/youtube/templates/watch.html.j2 b/app/youtube/templates/watch.html.j2 index cfe7a2a..bf8f6ae 100644 --- a/app/youtube/templates/watch.html.j2 +++ b/app/youtube/templates/watch.html.j2 @@ -106,8 +106,9 @@ var sha256=function a(b){function c(a,b){return a>>>b|a<<32-b}for(var d,e,f=Math
  • {{ macros.emoji_button("subscribe", channel_id, is_subscribed, True) }}
  • {{ macros.emoji_link("raw", video_id, True) }}
  • {{ macros.emoji_link("json", video_id, True) }} -
  • watch on invidious -
  • youtu.be +
  • {{ macros.emoji_link("meta", video_id, True) }} +
  • {{ macros.emoji_link("iv", video_id, True) }} +
  • {{ macros.emoji_link("yt", video_id, True) }} | embed -- 2.39.3