diff options
Diffstat (limited to 'livie.py')
-rw-r--r-- | livie.py | 40 |
1 files changed, 25 insertions, 15 deletions
@@ -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}') |