A feature-rich command-line audio/video downloader
Merge branch 'master' into youtube-mix-fix
insaneracist712799bd30f2
diff --cc youtube_dlc/extractor/youtube.pyindex 0354866eff,d605f1e740..ad67fa4100--- a/youtube_dlc/extractor/youtube.py+++ b/youtube_dlc/extractor/youtube.py@@@ -1406,6 -1397,53 +1406,44 @@@ class YoutubeIE(YoutubeBaseInfoExtractoreturn self._parse_json(uppercase_escape(config), video_id, fatal=False)- def _get_yt_initial_data(self, video_id, webpage):- config = self._search_regex(- (r'window\["ytInitialData"\]\s*=\s*(.*?)(?<=});',- r'var\s+ytInitialData\s*=\s*(.*?)(?<=});'),- webpage, 'ytInitialData', default=None)- if config:- return self._parse_json(- uppercase_escape(config), video_id, fatal=False)-+ def _get_music_metadata_from_yt_initial(self, yt_initial):+ music_metadata = []+ key_map = {+ 'Album': 'album',+ 'Artist': 'artist',+ 'Song': 'track'+ }+ contents = try_get(yt_initial, lambda x: x['contents']['twoColumnWatchNextResults']['results']['results']['contents'])+ if type(contents) is list:+ for content in contents:+ music_track = {}+ if type(content) is not dict:+ continue+ videoSecondaryInfoRenderer = try_get(content, lambda x: x['videoSecondaryInfoRenderer'])+ if type(videoSecondaryInfoRenderer) is not dict:+ continue+ rows = try_get(videoSecondaryInfoRenderer, lambda x: x['metadataRowContainer']['metadataRowContainerRenderer']['rows'])+ if type(rows) is not list:+ continue+ for row in rows:+ metadataRowRenderer = try_get(row, lambda x: x['metadataRowRenderer'])+ if type(metadataRowRenderer) is not dict:+ continue+ key = try_get(metadataRowRenderer, lambda x: x['title']['simpleText'])+ value = try_get(metadataRowRenderer, lambda x: x['contents'][0]['simpleText']) or \+ try_get(metadataRowRenderer, lambda x: x['contents'][0]['runs'][0]['text'])+ if type(key) is not str or type(value) is not str:+ continue+ if key in key_map:+ if key_map[key] in music_track:+ # we've started on a new track+ music_metadata.append(music_track)+ music_track = {}+ music_track[key_map[key]] = value+ if len(music_track.keys()):+ music_metadata.append(music_track)+ return music_metadata+def _get_automatic_captions(self, video_id, webpage):"""We need the webpage for getting the captions url, pass it as anargument to speed up the process."""