Use get_video_info to get video urls if player response missing
Fixes failure mode 1 in #22
This commit is contained in:
parent
b35afb7cf6
commit
c9d0f685a4
@ -226,15 +226,19 @@ def extract_info(video_id, use_invidious, playlist_id=None, index=None):
|
|||||||
return {'error': 'Failed to parse json response'}
|
return {'error': 'Failed to parse json response'}
|
||||||
info = yt_data_extract.extract_watch_info(polymer_json)
|
info = yt_data_extract.extract_watch_info(polymer_json)
|
||||||
|
|
||||||
# age restriction bypass
|
# request player if it's missing
|
||||||
if info['age_restricted']:
|
# see https://github.com/user234683/youtube-local/issues/22#issuecomment-706395160
|
||||||
print('Fetching age restriction bypass page')
|
if info['age_restricted'] or info['player_response_missing']:
|
||||||
|
if info['age_restricted']:
|
||||||
|
print('Age restricted video. Fetching get_video_info page')
|
||||||
|
else:
|
||||||
|
print('Missing player. Fetching get_video_info page')
|
||||||
data = {
|
data = {
|
||||||
'video_id': video_id,
|
'video_id': video_id,
|
||||||
'eurl': 'https://youtube.googleapis.com/v/' + video_id,
|
'eurl': 'https://youtube.googleapis.com/v/' + video_id,
|
||||||
}
|
}
|
||||||
url = 'https://www.youtube.com/get_video_info?' + urllib.parse.urlencode(data)
|
url = 'https://www.youtube.com/get_video_info?' + urllib.parse.urlencode(data)
|
||||||
video_info_page = util.fetch_url(url, debug_name='get_video_info', report_text='Fetched age restriction bypass page').decode('utf-8')
|
video_info_page = util.fetch_url(url, debug_name='get_video_info', report_text='Fetched get_video_info page').decode('utf-8')
|
||||||
yt_data_extract.update_with_age_restricted_info(info, video_info_page)
|
yt_data_extract.update_with_age_restricted_info(info, video_info_page)
|
||||||
|
|
||||||
# signature decryption
|
# signature decryption
|
||||||
|
@ -447,7 +447,8 @@ def _extract_playability_error(info, player_response, error_prefix=''):
|
|||||||
|
|
||||||
SUBTITLE_FORMATS = ('srv1', 'srv2', 'srv3', 'ttml', 'vtt')
|
SUBTITLE_FORMATS = ('srv1', 'srv2', 'srv3', 'ttml', 'vtt')
|
||||||
def extract_watch_info(polymer_json):
|
def extract_watch_info(polymer_json):
|
||||||
info = {'playability_error': None, 'error': None}
|
info = {'playability_error': None, 'error': None,
|
||||||
|
'player_response_missing': None}
|
||||||
|
|
||||||
if isinstance(polymer_json, dict):
|
if isinstance(polymer_json, dict):
|
||||||
top_level = polymer_json
|
top_level = polymer_json
|
||||||
@ -477,6 +478,10 @@ def extract_watch_info(polymer_json):
|
|||||||
else:
|
else:
|
||||||
embedded_player_response = {}
|
embedded_player_response = {}
|
||||||
|
|
||||||
|
# see https://github.com/user234683/youtube-local/issues/22#issuecomment-706395160
|
||||||
|
info['player_response_missing'] = not (
|
||||||
|
player_response or embedded_player_response)
|
||||||
|
|
||||||
# captions
|
# captions
|
||||||
info['automatic_caption_languages'] = []
|
info['automatic_caption_languages'] = []
|
||||||
info['manual_caption_languages'] = []
|
info['manual_caption_languages'] = []
|
||||||
@ -580,7 +585,8 @@ def get_caption_url(info, language, format, automatic=False, translation_languag
|
|||||||
return url
|
return url
|
||||||
|
|
||||||
def update_with_age_restricted_info(info, video_info_page):
|
def update_with_age_restricted_info(info, video_info_page):
|
||||||
ERROR_PREFIX = 'Error bypassing age-restriction: '
|
'''Inserts urls from 'player_response' in get_video_info page'''
|
||||||
|
ERROR_PREFIX = 'Error getting missing player or bypassing age-restriction: '
|
||||||
|
|
||||||
video_info = urllib.parse.parse_qs(video_info_page)
|
video_info = urllib.parse.parse_qs(video_info_page)
|
||||||
player_response = deep_get(video_info, 'player_response', 0)
|
player_response = deep_get(video_info, 'player_response', 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user