- Rebuild regex to find the URL of the videos - Add HD format only available for some videos this is caused by the YT DRM.
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
"""This module does render video"""
|
|
|
|
import sys
|
|
import datetime
|
|
import json
|
|
import requests
|
|
|
|
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 loop
|
|
|
|
VIDEOS = json.loads(REQUEST.content)
|
|
|
|
for video in VIDEOS:
|
|
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
|
|
else:
|
|
print() # print skip line
|
|
|
|
# prints
|
|
print(f' title: {title}')
|
|
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}')
|