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.
This commit is contained in:
Jesús 2019-07-09 11:11:34 -05:00
parent ef23834b03
commit dab16420a9
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
2 changed files with 27 additions and 17 deletions

View File

@ -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)

View File

@ -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}')