From dab16420a933365acd03adc1f39a6d8b5de4deb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Tue, 9 Jul 2019 11:11:34 -0500 Subject: Support HD videos - Rebuild regex to find the URL of the videos - Add HD format only available for some videos this is caused by the YT DRM. --- livie.el | 4 ++-- livie.py | 40 +++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/livie.el b/livie.el index 37ecfa8..85d35a0 100644 --- a/livie.el +++ b/livie.el @@ -47,7 +47,7 @@ :group 'livie :type 'string) -(defvar livie-youtube-regexp "https://invidious.snopyta.org/latest_version\\?id=[A-Za-z0-9_\\-]\\{11\\}&itag=18&local=true") +(defvar livie-youtube-regexp "https://invidious.snopyta.org/latest_version\\?id=[A-Za-z0-9_\\-]\\{11\\}&itag=\\<\\([0-9]*\\.[0-9]+\\|[0-9]+\\)[df]?\\>&local=true") (define-derived-mode livie-mode special-mode "livie" @@ -141,7 +141,7 @@ See also: `livie-mode'." `((,livie-youtube-regexp . 'link) ("title: \\(.*\\)" 1 'bold) ("channel: \\(.*\\)" 1 'italic) - ("^ +[a-z]+:" . 'shadow))) + ("^ +[a-zA-Z]+:" . 'shadow))) (define-key livie-mode-map "s" 'livie) (define-key livie-mode-map "q" 'livie-close-window) diff --git a/livie.py b/livie.py index 1be9dc2..fcce309 100644 --- a/livie.py +++ b/livie.py @@ -5,24 +5,32 @@ import datetime import json import requests -BASE_URL = 'https://invidious.snopyta.org' -SEARCH = sys.argv[1] -ITAG = '&itag=18&local=true' -URL = f'{BASE_URL}/api/v1/search?q={SEARCH}' -RUTA = requests.get(URL) +URL = 'https://invidious.snopyta.org' +INPUT = sys.argv[1] +SEARCH = f'{URL}/api/v1/search?q={INPUT}' +REQUEST = requests.get(SEARCH) +UNSD = '&itag=18&local=true' +UNHD = '&itag=22&local=true' -FIRST = True # skip line in bucle +FIRST = True # skip line loop -VIDEOS = json.loads(RUTA.content) +VIDEOS = json.loads(REQUEST.content) for video in VIDEOS: - title = video.get('title', '') - videoid = video.get('videoId', '') - author = video.get('author', '') - link = f'{BASE_URL}/latest_version?id={videoid}{ITAG}' - timer = video.get('lengthSeconds', '') - time = str(datetime.timedelta(seconds=timer)) - publish = video.get('publishedText', '') + try: + title = video.get('title', '') + videoid = video.get('videoId', '') + author = video.get('author', '') + + # Make URL + sd = f'{URL}/latest_version?id={videoid}{UNSD}' + hd = f'{URL}/latest_version?id={videoid}{UNHD}' + + timer = video.get('lengthSeconds', '') + time = str(datetime.timedelta(seconds=timer)) + publish = video.get('publishedText', '') + except TypeError: + continue if FIRST: FIRST = False @@ -31,7 +39,9 @@ for video in VIDEOS: # prints print(f' title: {title}') - print(f' url: {link}') + print(f' SD: {sd}') + print(f' HD: {hd}') + print(f' HD ^ Only some videos available caused by DRM') print(f' channel: {author}') print(f' time: {time}') print(f' publish: {publish}') -- cgit v1.2.3