From 2aaf38ce239418fa40a72cf6b3a84ad66c9a4cba Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Sun, 23 Jun 2024 17:03:31 +0200 Subject: [PATCH] [youtube] check playabilityStatus and ask for cookies if needed --- src/you_get/extractors/youtube.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/you_get/extractors/youtube.py b/src/you_get/extractors/youtube.py index f5aaf50ec5..1d370ec2e4 100644 --- a/src/you_get/extractors/youtube.py +++ b/src/you_get/extractors/youtube.py @@ -190,8 +190,6 @@ def prepare(self, **kwargs): jsUrl = re.search('([^"]*/base\.js)"', video_page).group(1) except: log.wtf('[Failed] Unable to find base.js on the video page') - # FIXME: do we still need this? - jsUrl = jsUrl.replace('\/', '/') # unescape URL (for age-restricted videos) self.html5player = 'https://www.youtube.com' + jsUrl logging.debug('Retrieving the player code...') self.js = get_content(self.html5player).replace('\n', ' ') @@ -202,6 +200,14 @@ def prepare(self, **kwargs): # Get the video title self.title = ytInitialPlayerResponse["videoDetails"]["title"] + # Check the status + playabilityStatus = ytInitialPlayerResponse['playabilityStatus'] + status = playabilityStatus['status'] + logging.debug('status: %s' % status) + if status != 'OK': + # If cookies are loaded, status should be OK + log.wtf('[Failed] %s (use --cookies to load cookies)' % playabilityStatus['reason']) + stream_list = ytInitialPlayerResponse['streamingData']['formats'] for stream in stream_list: