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:
parent
ef23834b03
commit
dab16420a9
4
livie.el
4
livie.el
@ -47,7 +47,7 @@
|
|||||||
:group 'livie
|
:group 'livie
|
||||||
:type 'string)
|
: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
|
(define-derived-mode livie-mode
|
||||||
special-mode "livie"
|
special-mode "livie"
|
||||||
@ -141,7 +141,7 @@ See also: `livie-mode'."
|
|||||||
`((,livie-youtube-regexp . 'link)
|
`((,livie-youtube-regexp . 'link)
|
||||||
("title: \\(.*\\)" 1 'bold)
|
("title: \\(.*\\)" 1 'bold)
|
||||||
("channel: \\(.*\\)" 1 'italic)
|
("channel: \\(.*\\)" 1 'italic)
|
||||||
("^ +[a-z]+:" . 'shadow)))
|
("^ +[a-zA-Z]+:" . 'shadow)))
|
||||||
|
|
||||||
(define-key livie-mode-map "s" 'livie)
|
(define-key livie-mode-map "s" 'livie)
|
||||||
(define-key livie-mode-map "q" 'livie-close-window)
|
(define-key livie-mode-map "q" 'livie-close-window)
|
||||||
|
40
livie.py
40
livie.py
@ -5,24 +5,32 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
BASE_URL = 'https://invidious.snopyta.org'
|
URL = 'https://invidious.snopyta.org'
|
||||||
SEARCH = sys.argv[1]
|
INPUT = sys.argv[1]
|
||||||
ITAG = '&itag=18&local=true'
|
SEARCH = f'{URL}/api/v1/search?q={INPUT}'
|
||||||
URL = f'{BASE_URL}/api/v1/search?q={SEARCH}'
|
REQUEST = requests.get(SEARCH)
|
||||||
RUTA = requests.get(URL)
|
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:
|
for video in VIDEOS:
|
||||||
title = video.get('title', '')
|
try:
|
||||||
videoid = video.get('videoId', '')
|
title = video.get('title', '')
|
||||||
author = video.get('author', '')
|
videoid = video.get('videoId', '')
|
||||||
link = f'{BASE_URL}/latest_version?id={videoid}{ITAG}'
|
author = video.get('author', '')
|
||||||
timer = video.get('lengthSeconds', '')
|
|
||||||
time = str(datetime.timedelta(seconds=timer))
|
# Make URL
|
||||||
publish = video.get('publishedText', '')
|
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:
|
if FIRST:
|
||||||
FIRST = False
|
FIRST = False
|
||||||
@ -31,7 +39,9 @@ for video in VIDEOS:
|
|||||||
|
|
||||||
# prints
|
# prints
|
||||||
print(f' title: {title}')
|
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' channel: {author}')
|
||||||
print(f' time: {time}')
|
print(f' time: {time}')
|
||||||
print(f' publish: {publish}')
|
print(f' publish: {publish}')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user