Skip to content

Instantly share code, notes, and snippets.

@Spotlightsrule
Forked from pukkandan/Project moved
Created August 10, 2022 02:19
Show Gist options
  • Save Spotlightsrule/455e41979fc6c9cc2d63ffa99a5de1b1 to your computer and use it in GitHub Desktop.
Save Spotlightsrule/455e41979fc6c9cc2d63ffa99a5de1b1 to your computer and use it in GitHub Desktop.
yt-dlp plugin to bypass youtube age-gate
"""
SPDX-License-Identifier: MIT https://opensource.org/licenses/MIT
Copyright © 2022 [email protected]
yt-dlp plugin extractor to bypass youtube age-gate
Needs yt-dlp 2022.04.08 or above
See https://github.com/yt-dlp/yt-dlp#plugins for how to use
Uses account proxy https://youtube-proxy.zerody.one by https://github.com/zerodytrash
to fetch video formats and proxy service https://www.4everproxy.com for download (if required)
Set "VIDEO_PROXY = None" to disable the proxy service
Note: The account proxy has limited resources. Please do not abuse
"""
import base64
from yt_dlp.utils import get_first, parse_qs
from yt_dlp.extractor.youtube import YoutubeIE
ACCOUNT_PROXY = 'https://youtube-proxy.zerody.one'
VIDEO_PROXY = 'https://phx.4everproxy.com'
class Youtube_AgeGateBypassIE(YoutubeIE):
IE_NAME = 'youtube:AGB'
_VALID_URL = YoutubeIE._VALID_URL
def _download_player_responses(self, url, smuggled_data, video_id, *args, **kwargs):
AGB_CLIENT = 'web'
ret = super()._download_player_responses(url, smuggled_data, video_id, *args, **kwargs)
_, ytcfg, player_responses, player_url, *_ = ret
#if all(map(self._is_agegated, player_responses)):
if True:
pr = self._download_json(
f'{ACCOUNT_PROXY}/getPlayer', video_id,
'Downloading Zerody API JSON', fatal=False, query={
'videoId': video_id,
'clientName': self._extract_client_name(ytcfg, AGB_CLIENT),
'clientVersion': self._extract_client_version(ytcfg, AGB_CLIENT),
'signatureTimestamp': self._extract_signature_timestamp(video_id, player_url, ytcfg),
'reason': 'LOGIN_REQUIRED',
'startTimeSecs': 0,
'client': 'yt-dlp',
})
if pr:
player_responses.append(pr)
streaming_data = get_first(player_responses, 'streamingData') or {}
if VIDEO_PROXY:
streaming_data['_use_proxy'] = True
return ret
def _extract_formats(self, streaming_data, *args, **kwargs):
has_gcr = False
for f in super()._extract_formats(streaming_data, *args, **kwargs):
if get_first(streaming_data, '_use_proxy') and parse_qs(f.get('url')).get('gcr'):
has_gcr = True
f['url'] = f'{VIDEO_PROXY}/direct/' + base64.b64encode(f['url'].encode()).decode()
yield f
if has_gcr:
self.to_screen('Video formats have GCR. Using proxy for download')
# Pretend to be YoutubeIE
def _real_extract(self, url):
res = super()._real_extract(url)
res['extractor_key'] = YoutubeIE.ie_key()
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment