aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2021-10-17 22:19:07 -0700
committerJesús <heckyel@hyperbola.info>2021-10-18 18:56:53 -0500
commit2e5a1133e3308a6f920bb310de9ad853a7955183 (patch)
treeca49fc98de483d32ac8d4ad569848e192ea511d1 /youtube
parentec5e99526218e20592edf5644070d0e9709457b4 (diff)
downloadyt-local-2e5a1133e3308a6f920bb310de9ad853a7955183.tar.lz
yt-local-2e5a1133e3308a6f920bb310de9ad853a7955183.tar.xz
yt-local-2e5a1133e3308a6f920bb310de9ad853a7955183.zip
Work around video throttling using android user-agent
Temporary fix for #95 Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube')
-rw-r--r--youtube/watch.py69
1 files changed, 35 insertions, 34 deletions
diff --git a/youtube/watch.py b/youtube/watch.py
index 09f146c..c9a5f77 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -354,45 +354,46 @@ def extract_info(video_id, use_invidious, playlist_id=None, index=None):
watch_page = watch_page.decode('utf-8')
info = yt_data_extract.extract_watch_info_from_html(watch_page)
- # request player urls if it's missing
- # see https://github.com/user234683/youtube-local/issues/22#issuecomment-706395160
+ context = {
+ 'client': {
+ 'clientName': 'ANDROID',
+ 'clientVersion': '16.20',
+ '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
+ }
+ }
if info['age_restricted'] or info['player_urls_missing']:
if info['age_restricted']:
print('Age restricted video. Fetching /youtubei/v1/player page')
else:
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 = {
- 'videoId': video_id,
- 'context': {
- 'client': {
- 'clientName': 'ANDROID',
- 'clientVersion': '16.20',
- 'clientScreen': 'EMBED',
- '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
- }
- }
- }
- data = json.dumps(data)
- content_header = (('Content-Type', 'application/json'),)
- player_response = util.fetch_url(
- url, data=data, headers=util.mobile_ua + content_header,
- debug_name='youtubei_player',
- report_text='Fetched youtubei player page').decode('utf-8')
- yt_data_extract.update_with_age_restricted_info(info,
- player_response)
+ context['client']['clientScreen'] = 'EMBED'
+ else:
+ print('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 = {
+ 'videoId': video_id,
+ 'context': context,
+ }
+ data = json.dumps(data)
+ content_header = (('Content-Type', 'application/json'),)
+ player_response = util.fetch_url(
+ url, data=data, headers=util.mobile_ua + content_header,
+ debug_name='youtubei_player',
+ report_text='Fetched youtubei player page').decode('utf-8')
+
+ yt_data_extract.update_with_age_restricted_info(info, player_response)
# signature decryption
decryption_error = decrypt_signatures(info, video_id)