[youtube] we should extract ytInitialPlayerResponse more reliably

This commit is contained in:
Mort Yao 2022-06-07 16:19:14 +02:00
parent 6ddc3fce89
commit c0151a9775
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -237,7 +237,10 @@ class YouTube(VideoExtractor):
except:
# ytplayer_config = {args:{raw_player_response:ytInitialPlayerResponse}}
try: # FIXME: we should extract ytInitialPlayerResponse more reliably
ytInitialPlayerResponse = json.loads(re.search('ytInitialPlayerResponse\s*=\s*([^\n]+?});</script>', video_page).group(1))
except:
ytInitialPlayerResponse = json.loads(re.search('ytInitialPlayerResponse\s*=\s*([^\n]+?});', video_page).group(1))
stream_list = ytInitialPlayerResponse['streamingData']['formats']
#stream_list = ytInitialPlayerResponse['streamingData']['adaptiveFormats']
@ -262,7 +265,10 @@ class YouTube(VideoExtractor):
# Parse video page instead
video_page = get_content('https://www.youtube.com/watch?v=%s' % self.vid)
try: # FIXME: we should extract ytInitialPlayerResponse more reliably
ytInitialPlayerResponse = json.loads(re.search('ytInitialPlayerResponse\s*=\s*([^\n]+?});</script>', video_page).group(1))
except:
ytInitialPlayerResponse = json.loads(re.search('ytInitialPlayerResponse\s*=\s*([^\n]+?});', video_page).group(1))
self.title = ytInitialPlayerResponse["videoDetails"]["title"]
if re.search('([^"]*/base\.js)"', video_page):