diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-12-14 22:08:36 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-12-14 22:08:36 -0800 |
commit | e870eea05737e694206c85383f3328cfaa778e90 (patch) | |
tree | ce65369741aacb65974e538f909d30961f07bc10 /youtube/yt_data_extract.py | |
parent | a04aa63efee5813c6083dcdb3defcbcf32ce88f4 (diff) | |
download | yt-local-e870eea05737e694206c85383f3328cfaa778e90.tar.lz yt-local-e870eea05737e694206c85383f3328cfaa778e90.tar.xz yt-local-e870eea05737e694206c85383f3328cfaa778e90.zip |
Extraction: Add fallback playability error extraction from renderers
Diffstat (limited to 'youtube/yt_data_extract.py')
-rw-r--r-- | youtube/yt_data_extract.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/youtube/yt_data_extract.py b/youtube/yt_data_extract.py index 42e10db..ec9d683 100644 --- a/youtube/yt_data_extract.py +++ b/youtube/yt_data_extract.py @@ -1091,6 +1091,25 @@ def extract_formats(info, player_response): info['formats'].append(fmt) +def extract_playability_error(info, player_response, error_prefix=''): + if info['formats']: + info['playability_error'] = None + return + + playability_status = default_multi_get(player_response, 'playabilityStatus', 'status', default=None) + info['playability_status'] = playability_status + + playability_reason = extract_plain_text(multi_default_multi_get(player_response, + ['playabilityStatus', 'reason'], + ['playabilityStatus', 'errorScreen', 'playerErrorMessageRenderer', 'reason'], + default='Could not find playability error') + ) + + if playability_status not in (None, 'OK'): + info['playability_error'] = error_prefix + playability_reason + else: + info['playability_error'] = error_prefix + 'Unknown playability error' + SUBTITLE_FORMATS = ('srv1', 'srv2', 'srv3', 'ttml', 'vtt') def extract_watch_info(polymer_json): info = {'playability_error': None, 'error': None} @@ -1146,16 +1165,12 @@ def extract_watch_info(polymer_json): # formats extract_formats(info, player_response) - playability_status = default_multi_get(player_response, 'playabilityStatus', 'status', default=None) - playability_reason = default_multi_get(player_response, 'playabilityStatus', 'reason', default='Could not find playability error') - if not info['formats']: - if playability_status not in (None, 'OK'): - info['playability_error'] = playability_reason - else: - info['playability_error'] = 'Unknown playability error' + + # playability errors + extract_playability_error(info, player_response) # check age-restriction - info['age_restricted'] = (playability_status == 'LOGIN_REQUIRED' and playability_reason and ' age' in playability_reason) + info['age_restricted'] = (info['playability_status'] == 'LOGIN_REQUIRED' and info['playability_reason'] and ' age' in info['playability_reason']) # base_js (for decryption of signatures) info['base_js'] = default_multi_get(top_level, 'player', 'assets', 'js') @@ -1202,12 +1217,4 @@ def update_with_age_restricted_info(info, video_info_page): return extract_formats(info, player_response) - if info['formats']: - info['playability_error'] = None - else: - playability_status = default_multi_get(player_response, 'playabilityStatus', 'status', default=None) - playability_reason = default_multi_get(player_response, 'playabilityStatus', 'reason', default=ERROR_PREFIX + 'Could not find playability error') - if playability_status not in (None, 'OK'): - info['playability_error'] = ERROR_PREFIX + playability_reason - else: - info['playability_error'] = ERROR_PREFIX + 'Unknown playability error' + extract_playability_error(info, player_response, error_prefix=ERROR_PREFIX) |