[youtube] check playabilityStatus and ask for cookies if needed

This commit is contained in:
Mort Yao 2024-06-23 17:03:31 +02:00
parent b0e6f0cadc
commit 2aaf38ce23
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -190,8 +190,6 @@ class YouTube(VideoExtractor):
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 @@ class YouTube(VideoExtractor):
# 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: