Fixes lives and scheduled videos errors
This commit is contained in:
parent
9b376abfc5
commit
66f81c3608
@ -121,38 +121,8 @@ def get_renderer_key(renderer, key):
|
|||||||
def get_video_primary_info(datad, datai):
|
def get_video_primary_info(datad, datai):
|
||||||
contents = datai["contents"]["twoColumnWatchNextResults"]['results']['results']['contents']
|
contents = datai["contents"]["twoColumnWatchNextResults"]['results']['results']['contents']
|
||||||
item = get_renderer_key(contents, "videoPrimaryInfoRenderer")
|
item = get_renderer_key(contents, "videoPrimaryInfoRenderer")
|
||||||
details = datad['videoDetails']
|
details = datad['videoDetails']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ydl = YoutubeDL()
|
|
||||||
try:
|
|
||||||
data = ydl.extract_info(details['videoId'], False)
|
|
||||||
while not data['formats']:
|
|
||||||
data = ydl.extract_info(details['videoId'], False)
|
|
||||||
except Exception as e:
|
|
||||||
premieres = e
|
|
||||||
|
|
||||||
|
|
||||||
## Get audio
|
|
||||||
audio_urls = []
|
|
||||||
for f in data['formats']:
|
|
||||||
for fid in _formats:
|
|
||||||
if f['format_id'] == fid:
|
|
||||||
try:
|
|
||||||
if 'audio' in _formats[fid]['format_note']:
|
|
||||||
aurl = f['url']
|
|
||||||
fnote = _formats[fid]['format_note']
|
|
||||||
bitrate = _formats[fid]['audio_bitrate']
|
|
||||||
audio_inf = {
|
|
||||||
"url":aurl,
|
|
||||||
"id":fnote,
|
|
||||||
"btr": bitrate
|
|
||||||
}
|
|
||||||
audio_urls.append(audio_inf)
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Check if is Livestream
|
# Check if is Livestream
|
||||||
if details.get('isLive') and details['lengthSeconds'] == '0':
|
if details.get('isLive') and details['lengthSeconds'] == '0':
|
||||||
isLive = True
|
isLive = True
|
||||||
@ -170,10 +140,39 @@ def get_video_primary_info(datad, datai):
|
|||||||
premieres = False
|
premieres = False
|
||||||
views = details['viewCount']
|
views = details['viewCount']
|
||||||
if not isLive:
|
if not isLive:
|
||||||
audioURL = audio_urls[-1]
|
audioURL = audio_urls[-1]
|
||||||
else:
|
else:
|
||||||
audioURL = "#"
|
audioURL = "#"
|
||||||
|
|
||||||
|
ydl = YoutubeDL()
|
||||||
|
|
||||||
|
if not isUpcoming:
|
||||||
|
data = ydl.extract_info(details['videoId'], False)
|
||||||
|
while not data['formats']:
|
||||||
|
data = ydl.extract_info(details['videoId'], False)
|
||||||
|
formats = data['formats']
|
||||||
|
|
||||||
|
## Get audio
|
||||||
|
audio_urls = []
|
||||||
|
for f in data['formats']:
|
||||||
|
for fid in _formats:
|
||||||
|
if f['format_id'] == fid:
|
||||||
|
try:
|
||||||
|
if 'audio' in _formats[fid]['format_note']:
|
||||||
|
aurl = f['url']
|
||||||
|
fnote = _formats[fid]['format_note']
|
||||||
|
bitrate = _formats[fid]['audio_bitrate']
|
||||||
|
audio_inf = {
|
||||||
|
"url":aurl,
|
||||||
|
"id":fnote,
|
||||||
|
"btr": bitrate
|
||||||
|
}
|
||||||
|
audio_urls.append(audio_inf)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
else: # If it is a scheduled video
|
||||||
|
audio_urls = False
|
||||||
|
formats = False
|
||||||
try:
|
try:
|
||||||
primaryInfo = {
|
primaryInfo = {
|
||||||
"id": details['videoId'],
|
"id": details['videoId'],
|
||||||
@ -189,7 +188,7 @@ def get_video_primary_info(datad, datai):
|
|||||||
"isUpcoming": isUpcoming,
|
"isUpcoming": isUpcoming,
|
||||||
"url":url,
|
"url":url,
|
||||||
"allowRatings": details['allowRatings'],
|
"allowRatings": details['allowRatings'],
|
||||||
"urls":data['formats'],
|
"urls":formats,
|
||||||
"thumbnail": details['thumbnail']['thumbnails'][0]['url'],
|
"thumbnail": details['thumbnail']['thumbnails'][0]['url'],
|
||||||
"audio": audioURL,
|
"audio": audioURL,
|
||||||
"premieres": premieres
|
"premieres": premieres
|
||||||
@ -209,7 +208,7 @@ def get_video_primary_info(datad, datai):
|
|||||||
"isLive":isLive,
|
"isLive":isLive,
|
||||||
"isUpcoming":isUpcoming,
|
"isUpcoming":isUpcoming,
|
||||||
"allowRatings":True,
|
"allowRatings":True,
|
||||||
"urls":data['formats'],
|
"urls":formats,
|
||||||
"thumbnail": details['thumbnail']['thumbnails'][0]['url'],
|
"thumbnail": details['thumbnail']['thumbnails'][0]['url'],
|
||||||
"audio": audioURL,
|
"audio": audioURL,
|
||||||
"premieres": premieres
|
"premieres": premieres
|
||||||
|
Reference in New Issue
Block a user