aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/watch.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-12-12 22:13:17 -0800
committerJames Taylor <user234683@users.noreply.github.com>2019-12-12 22:13:17 -0800
commit26f37521babbb2fc4b86ad59354e8c69da1f3897 (patch)
tree7fd6eb51bc09ce84b18a9193ab99f23cb481af55 /youtube/watch.py
parent205ad29cb0763dd263a5940cdcb3059d189bbfe7 (diff)
downloadyt-local-26f37521babbb2fc4b86ad59354e8c69da1f3897.tar.lz
yt-local-26f37521babbb2fc4b86ad59354e8c69da1f3897.tar.xz
yt-local-26f37521babbb2fc4b86ad59354e8c69da1f3897.zip
Extraction: Bypass age-restriction
Diffstat (limited to 'youtube/watch.py')
-rw-r--r--youtube/watch.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/youtube/watch.py b/youtube/watch.py
index fa697ba..4575c1e 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -275,17 +275,32 @@ headers = (
) + util.mobile_ua
def extract_info(video_id):
- polymer_json = util.fetch_url('https://m.youtube.com/watch?v=' + video_id + '&pbj=1', headers=headers, debug_name='watch')
+ polymer_json = util.fetch_url('https://m.youtube.com/watch?v=' + video_id + '&pbj=1', headers=headers, debug_name='watch').decode('utf-8')
+ # TODO: Decide whether this should be done in yt_data_extract.extract_watch_info
try:
polymer_json = json.loads(polymer_json)
except json.decoder.JSONDecodeError:
traceback.print_exc()
return {'error': 'Failed to parse json response'}
info = yt_data_extract.extract_watch_info(polymer_json)
- error = decrypt_signatures(info)
- if error:
- print('Error decrypting url signatures: ' + error)
- info['playability_error'] = error
+
+ # age restriction bypass
+ if info['age_restricted']:
+ print('Fetching age restriction bypass page')
+ data = {
+ 'video_id': video_id,
+ 'eurl': 'https://youtube.googleapis.com/v/' + video_id,
+ }
+ url = 'https://www.youtube.com/get_video_info?' + urllib.parse.urlencode(data)
+ video_info_page = util.fetch_url(url, debug_name='get_video_info', report_text='Fetched age restriction bypass page').decode('utf-8')
+ yt_data_extract.update_with_age_restricted_info(info, video_info_page)
+
+ # signature decryption
+ decryption_error = decrypt_signatures(info)
+ if decryption_error:
+ decryption_error = 'Error decrypting url signatures: ' + decryption_error
+ info['playability_error'] = decryption_error
+
return info
def video_quality_string(format):
@@ -410,6 +425,7 @@ def get_watch_page():
uploader = info['author'],
description = info['description'],
unlisted = info['unlisted'],
+ age_restricted = info['age_restricted'],
playability_error = info['playability_error'],
)