aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--livie.el4
-rw-r--r--livie.py40
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}')