Revert to android URLs and fix 403s by including params

Including 'params': '8AEB' fixes the issue with the URLs
returning 403 after a couple minutes into the video.

Credit to @ImportTaste for pointing this out

Closes #168
This commit is contained in:
Jesus E 2023-05-28 21:36:15 -04:00
parent 9859c5485e
commit 512798366c
No known key found for this signature in database
GPG Key ID: 159C8F8BC9AED8B6

View File

@ -25,15 +25,19 @@ INNERTUBE_CLIENTS = {
'INNERTUBE_API_KEY': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w', 'INNERTUBE_API_KEY': 'AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w',
'INNERTUBE_CONTEXT': { 'INNERTUBE_CONTEXT': {
'client': { 'client': {
'hl': 'en',
'gl': 'US',
'clientName': 'ANDROID', 'clientName': 'ANDROID',
'clientVersion': '17.31.35', 'clientVersion': '17.31.35',
'osName': 'Android',
'osVersion': '12',
'androidSdkVersion': 31, 'androidSdkVersion': 31,
'userAgent': 'com.google.android.youtube/17.31.35 (Linux; U; Android 11) gzip' 'userAgent': 'com.google.android.youtube/17.31.35 (Linux; U; Android 12) gzip'
}, },
# https://github.com/yt-dlp/yt-dlp/pull/575#issuecomment-887739287 # https://github.com/yt-dlp/yt-dlp/pull/575#issuecomment-887739287
'thirdParty': { #'thirdParty': {
'embedUrl': 'https://google.com', # Can be any valid URL # 'embedUrl': 'https://google.com', # Can be any valid URL
} #}
}, },
'INNERTUBE_CONTEXT_CLIENT_NAME': 3, 'INNERTUBE_CONTEXT_CLIENT_NAME': 3,
'REQUIRE_JS_PLAYER': False, 'REQUIRE_JS_PLAYER': False,
@ -45,6 +49,8 @@ INNERTUBE_CLIENTS = {
'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', 'INNERTUBE_API_KEY': 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8',
'INNERTUBE_CONTEXT': { 'INNERTUBE_CONTEXT': {
'client': { 'client': {
'hl': 'en',
'gl': 'US',
'clientName': 'TVHTML5_SIMPLY_EMBEDDED_PLAYER', 'clientName': 'TVHTML5_SIMPLY_EMBEDDED_PLAYER',
'clientVersion': '2.0', 'clientVersion': '2.0',
}, },
@ -378,17 +384,19 @@ def _add_to_error(info, key, additional_message):
else: else:
info[key] = additional_message info[key] = additional_message
def fetch_player_response(client, video_id): def fetch_player_response(client, video_id):
client_params = INNERTUBE_CLIENTS[client] client_params = INNERTUBE_CLIENTS[client]
context = client_params['INNERTUBE_CONTEXT'] context = client_params['INNERTUBE_CONTEXT']
key = client_params['INNERTUBE_API_KEY'] key = client_params['INNERTUBE_API_KEY']
host = client_params.get('INNERTUBE_HOST') or 'youtubei.googleapis.com' host = client_params.get('INNERTUBE_HOST') or 'www.youtube.com'
user_agent = context['client'].get('userAgent') or util.mobile_user_agent user_agent = context['client'].get('userAgent') or util.mobile_user_agent
url = 'https://' + host + '/youtubei/v1/player?key=' + key url = 'https://' + host + '/youtubei/v1/player?key=' + key
data = { data = {
'videoId': video_id, 'videoId': video_id,
'context': context, 'context': context,
'params': '8AEB',
} }
data = json.dumps(data) data = json.dumps(data)
headers = (('Content-Type', 'application/json'),('User-Agent', user_agent)) headers = (('Content-Type', 'application/json'),('User-Agent', user_agent))
@ -440,9 +448,7 @@ def extract_info(video_id, use_invidious, playlist_id=None, index=None):
util.check_gevent_exceptions(*tasks) util.check_gevent_exceptions(*tasks)
info, player_response = tasks[0].value, tasks[1].value info, player_response = tasks[0].value, tasks[1].value
if yt_data_extract.requires_decryption(info): yt_data_extract.update_with_new_urls(info, player_response)
print('Encrypted. Replacing with URLs from Android client')
yt_data_extract.update_with_new_urls(info, player_response)
# Age restricted video, retry # Age restricted video, retry
if info['age_restricted'] or info['player_urls_missing']: if info['age_restricted'] or info['player_urls_missing']:
@ -626,8 +632,6 @@ def get_storyboard_vtt():
time_table = {'h': 3600, 'm': 60, 's': 1} time_table = {'h': 3600, 'm': 60, 's': 1}
@yt_app.route('/watch') @yt_app.route('/watch')
@yt_app.route('/embed') @yt_app.route('/embed')
@yt_app.route('/embed/<video_id>') @yt_app.route('/embed/<video_id>')
@ -745,7 +749,6 @@ def get_watch_page(video_id=None):
pair_sources = source_info['pair_sources'] pair_sources = source_info['pair_sources']
uni_idx, pair_idx = source_info['uni_idx'], source_info['pair_idx'] uni_idx, pair_idx = source_info['uni_idx'], source_info['pair_idx']
pair_quality = yt_data_extract.deep_get(pair_sources, pair_idx, 'quality') pair_quality = yt_data_extract.deep_get(pair_sources, pair_idx, 'quality')
uni_quality = yt_data_extract.deep_get(uni_sources, uni_idx, 'quality') uni_quality = yt_data_extract.deep_get(uni_sources, uni_idx, 'quality')
@ -862,7 +865,7 @@ def get_watch_page(video_id=None):
'related': info['related_videos'], 'related': info['related_videos'],
'playability_error': info['playability_error'], 'playability_error': info['playability_error'],
}, },
font_family=youtube.font_choices[settings.font], # for embed page font_family = youtube.font_choices[settings.font], # for embed page
**source_info, **source_info,
using_pair_sources = using_pair_sources, using_pair_sources = using_pair_sources,
) )