Invidious fallback: Use original format info and just substitute invidious urls
Because the invidious formats don't have all the information
This commit is contained in:
parent
9f090dbbf8
commit
14b9c30daf
@ -263,30 +263,20 @@ def extract_info(video_id):
|
|||||||
return info
|
return info
|
||||||
|
|
||||||
video_info = json.loads(video_info.decode('utf-8'))
|
video_info = json.loads(video_info.decode('utf-8'))
|
||||||
info['formats'] = []
|
# collect invidious urls for each itag
|
||||||
for fmt in (video_info['adaptiveFormats']
|
itag_to_url = {}
|
||||||
|
for invidious_fmt in (video_info['adaptiveFormats']
|
||||||
+ video_info['formatStreams']):
|
+ video_info['formatStreams']):
|
||||||
# adjust keys to match our conventions
|
itag_to_url[invidious_fmt['itag']] = invidious_fmt['url']
|
||||||
fmt['file_size'] = fmt.get('clen')
|
|
||||||
fmt['ext'] = fmt.get('container')
|
|
||||||
if 'resolution' in fmt:
|
|
||||||
fmt['height'] = int(fmt['resolution'].rstrip('p'))
|
|
||||||
|
|
||||||
# update with information from _formats table such as ext
|
# replace urls with urls from invidious
|
||||||
itag = fmt.get('itag')
|
for fmt in info['formats']:
|
||||||
fmt.update(yt_data_extract._formats.get(itag, {}))
|
itag = str(fmt['itag'])
|
||||||
|
if itag not in itag_to_url:
|
||||||
# extract acodec, vcodec, and ext
|
print(('Warning: itag '
|
||||||
# (need for 'ext' because 'container' not always present)
|
+ itag + ' not found in invidious urls'))
|
||||||
yt_data_extract.update_format_with_type_info(fmt, fmt)
|
continue
|
||||||
|
fmt['url'] = itag_to_url[itag]
|
||||||
# ensure keys are present
|
|
||||||
for key in ('ext', 'audio_bitrate', 'acodec', 'vcodec',
|
|
||||||
'width', 'height', 'audio_sample_rate', 'fps'):
|
|
||||||
if key not in fmt:
|
|
||||||
fmt[key] = None
|
|
||||||
|
|
||||||
info['formats'].append(fmt)
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def video_quality_string(format):
|
def video_quality_string(format):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user