1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-09-03 00:25:08 +00:00

[MTV] Improve mgid extraction (#1713)

Original PR: https://github.com/ytdl-org/youtube-dl/pull/30149
Fixes: #713, #1580, https://github.com/ytdl-org/youtube-dl/issues/30139

Authored by: Sipherdrakon, kikuyan
This commit is contained in:
Sipherdrakon
2021-11-24 03:01:49 -05:00
committed by GitHub
parent a61fd4cf6f
commit fec41d17a5
2 changed files with 19 additions and 18 deletions

View File

@ -306,21 +306,23 @@ class MTVServicesInfoExtractor(InfoExtractor):
if not mgid:
mgid = self._extract_triforce_mgid(webpage)
if not mgid:
mgid = self._search_regex(
r'"videoConfig":{"videoId":"(mgid:.*?)"', webpage, 'mgid', default=None)
if not mgid:
mgid = self._search_regex(
r'"media":{"video":{"config":{"uri":"(mgid:.*?)"', webpage, 'mgid', default=None)
if not mgid:
data = self._parse_json(self._search_regex(
r'__DATA__\s*=\s*({.+?});', webpage, 'data'), None)
main_container = self._extract_child_with_type(data, 'MainContainer')
ab_testing = self._extract_child_with_type(main_container, 'ABTesting')
video_player = self._extract_child_with_type(ab_testing or main_container, 'VideoPlayer')
mgid = video_player['props']['media']['video']['config']['uri']
if video_player:
mgid = try_get(video_player, lambda x: x['props']['media']['video']['config']['uri'])
else:
flex_wrapper = self._extract_child_with_type(ab_testing or main_container, 'FlexWrapper')
auth_suite_wrapper = self._extract_child_with_type(flex_wrapper, 'AuthSuiteWrapper')
player = self._extract_child_with_type(auth_suite_wrapper or flex_wrapper, 'Player')
if player:
mgid = try_get(player, lambda x: x['props']['videoDetail']['mgid'])
if not mgid:
raise ExtractorError('Could not extract mgid')
return mgid