Skip to content

Commit

Permalink
Use ios client to bypass youtube blockage of android cleint
Browse files Browse the repository at this point in the history
Fixes #205

absidue notes that blockage of the android client is collateral
damage due to YouTube's war with ReVanced. Switching to iOS should
keep us out of the line of fire for now:
yt-dlp/yt-dlp#9554 (comment)
  • Loading branch information
user234683 committed Mar 30, 2024
1 parent 4e94b0f commit 7853449
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
17 changes: 17 additions & 0 deletions youtube/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,23 @@ def to_valid_filename(name):
'REQUIRE_JS_PLAYER': False,
},


'ios': {
'INNERTUBE_API_KEY': 'AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc',
'INNERTUBE_CONTEXT': {
'client': {
'hl': 'en',
'gl': 'US',
'clientName': 'IOS',
'clientVersion': '19.09.3',
'deviceModel': 'iPhone14,3',
'userAgent': 'com.google.ios.youtube/19.09.3 (iPhone14,3; U; CPU iOS 15_6 like Mac OS X)'
}
},
'INNERTUBE_CONTEXT_CLIENT_NAME': 5,
'REQUIRE_JS_PLAYER': False
},

# This client can access age restricted videos (unless the uploader has disabled the 'allow embedding' option)
# See: https://github.com/zerodytrash/YouTube-Internal-Clients
'tv_embedded': {
Expand Down
12 changes: 2 additions & 10 deletions youtube/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,8 @@ def extract_info(video_id, use_invidious, playlist_id=None, index=None):
# Get video metadata from here
gevent.spawn(fetch_watch_page_info, video_id, playlist_id, index),

# Get video URLs by spoofing as android client 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
# https://github.com/yt-dlp/yt-dlp/issues/574#issuecomment-887171136

# Update 4/26/23, these URLs will randomly start returning 403
# mid-playback and I'm not sure why
gevent.spawn(fetch_player_response, 'android', video_id)

gevent.spawn(fetch_player_response, 'ios', video_id)
)
gevent.joinall(tasks)
util.check_gevent_exceptions(*tasks)
Expand Down

0 comments on commit 7853449

Please sign in to comment.