diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-02-04 19:08:56 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-02-04 19:08:56 -0800 |
commit | 14b9c30daf2ffe3368cb4bff8a395e9c384a06e5 (patch) | |
tree | d8bb947afb70493698cbd7dc400b12f4eff4fa19 /youtube | |
parent | 9f090dbbf82a212b5e4b82f99ec48ec15c0946b0 (diff) | |
download | yt-local-14b9c30daf2ffe3368cb4bff8a395e9c384a06e5.tar.lz yt-local-14b9c30daf2ffe3368cb4bff8a395e9c384a06e5.tar.xz yt-local-14b9c30daf2ffe3368cb4bff8a395e9c384a06e5.zip |
Invidious fallback: Use original format info and just substitute invidious urls
Because the invidious formats don't have all the information
Diffstat (limited to 'youtube')
-rw-r--r-- | youtube/watch.py | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/youtube/watch.py b/youtube/watch.py index f9e6b7c..5b36462 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -263,30 +263,20 @@ def extract_info(video_id): return info video_info = json.loads(video_info.decode('utf-8')) - info['formats'] = [] - for fmt in (video_info['adaptiveFormats'] + # collect invidious urls for each itag + itag_to_url = {} + for invidious_fmt in (video_info['adaptiveFormats'] + video_info['formatStreams']): - # adjust keys to match our conventions - 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 - itag = fmt.get('itag') - fmt.update(yt_data_extract._formats.get(itag, {})) - - # extract acodec, vcodec, and ext - # (need for 'ext' because 'container' not always present) - yt_data_extract.update_format_with_type_info(fmt, fmt) - - # 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) + itag_to_url[invidious_fmt['itag']] = invidious_fmt['url'] + + # replace urls with urls from invidious + for fmt in info['formats']: + itag = str(fmt['itag']) + if itag not in itag_to_url: + print(('Warning: itag ' + + itag + ' not found in invidious urls')) + continue + fmt['url'] = itag_to_url[itag] return info def video_quality_string(format): |