Skip to content

Commit

Permalink
[youtube] check playabilityStatus and ask for cookies if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed Jun 23, 2024
1 parent b0e6f0c commit 2aaf38c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/you_get/extractors/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ' ')
Expand All @@ -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:
Expand Down

0 comments on commit 2aaf38c

Please sign in to comment.