New age restriction bypass method since get_video_info was disabled

From
https://github.com/yt-dlp/yt-dlp/issues/574#issuecomment-887171136

Signed-off-by: Jesús <heckyel@hyperbola.info>
This commit is contained in:
James Taylor 2021-07-28 13:00:25 -07:00 committed by Jesús
parent 54b39f1303
commit f27105fa7f
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
2 changed files with 34 additions and 31 deletions

View File

@ -241,33 +241,41 @@ def extract_info(video_id, use_invidious, playlist_id=None, index=None):
# see https://github.com/user234683/youtube-local/issues/22#issuecomment-706395160 # see https://github.com/user234683/youtube-local/issues/22#issuecomment-706395160
if info['age_restricted'] or info['player_urls_missing']: if info['age_restricted'] or info['player_urls_missing']:
if info['age_restricted']: if info['age_restricted']:
print('Age restricted video. Fetching get_video_info page') print('Age restricted video. Fetching /youtubei/v1/player page')
else: else:
print('Missing player. Fetching get_video_info page') print('Missing player. Fetching /youtubei/v1/player page')
# https://github.com/yt-dlp/yt-dlp/issues/574#issuecomment-887171136
# ANDROID is used instead because its urls don't require decryption
# The URLs returned with WEB for videos requiring decryption
# couldn't be decrypted with the base.js from the web page for some
# reason
url ='https://youtubei.googleapis.com/youtubei/v1/player'
url += '?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8'
data = { data = {
'video_id': video_id, 'videoId': video_id,
'eurl': 'https://youtube.googleapis.com/v/' + video_id, 'context': {
'html5': '1', 'client': {
# See https://github.com/ytdl-org/youtube-dl/issues/29333#issuecomment-864049544 'clientName': 'ANDROID',
'c': 'TVHTML5', 'clientVersion': '16.20',
'cver': '6.20180913', 'clientScreen': 'EMBED',
'hl': 'en', 'gl': 'US',
'hl': 'en',
},
# https://github.com/yt-dlp/yt-dlp/pull/575#issuecomment-887739287
'thirdParty': {
'embedUrl': 'https://google.com', # Can be any valid URL
}
}
} }
url = 'https://www.youtube.com/get_video_info?' data = json.dumps(data)
url += urllib.parse.urlencode(data) content_header = (('Content-Type', 'application/json'),)
try: player_response = util.fetch_url(
video_info_page = util.fetch_url( url, data=data, headers=util.mobile_ua + content_header,
url, headers=util.mobile_ua, debug_name='get_video_info', debug_name='youtubei_player',
report_text='Fetched get_video_info page').decode('utf-8') report_text='Fetched youtubei player page').decode('utf-8')
except util.FetchError as e: yt_data_extract.update_with_age_restricted_info(info,
if e.code == '404': player_response)
_add_to_error(info, 'playability_error',
'\n\nget_video_info not available (404).')
else:
raise
else:
yt_data_extract.update_with_age_restricted_info(info,
video_info_page)
# signature decryption # signature decryption
decryption_error = decrypt_signatures(info, video_id) decryption_error = decrypt_signatures(info, video_id)

View File

@ -706,15 +706,10 @@ def get_caption_url(info, language, format, automatic=False, translation_languag
url += '&tlang=' + translation_language url += '&tlang=' + translation_language
return url return url
def update_with_age_restricted_info(info, video_info_page): def update_with_age_restricted_info(info, player_response):
'''Inserts urls from 'player_response' in get_video_info page''' '''Inserts urls from player_response json'''
ERROR_PREFIX = 'Error getting missing player or bypassing age-restriction: ' ERROR_PREFIX = 'Error getting missing player or bypassing age-restriction: '
video_info = urllib.parse.parse_qs(video_info_page)
player_response = deep_get(video_info, 'player_response', 0)
if player_response is None:
info['playability_error'] = ERROR_PREFIX + 'Could not find player_response in video_info_page'
return
try: try:
player_response = json.loads(player_response) player_response = json.loads(player_response)
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError: