4 from .common
import InfoExtractor
17 class VevoBaseIE(InfoExtractor
):
18 def _extract_json(self
, webpage
, video_id
):
19 return self
._parse
_json
(
21 r
'window\.__INITIAL_STORE__\s*=\s*({.+?});\s*</script>',
22 webpage
, 'initial store'),
26 class VevoIE(VevoBaseIE
):
28 Accepts urls from vevo.com or in the format 'vevo:{id}'
29 (currently used by MTVIE and MySpaceIE)
32 (?:https?://(?:www\.)?vevo\.com/watch/(?!playlist|genre)(?:[^/]+/(?:[^/]+/)?)?|
33 https?://cache\.vevo\.com/m/html/embed\.html\?video=|
34 https?://videoplayer\.vevo\.com/embed/embedded\?videoId=|
35 https?://embed\.vevo\.com/.*?[?&]isrc=|
36 https?://tv\.vevo\.com/watch/artist/(?:[^/]+)/|
39 _EMBED_REGEX
= [r
'<iframe[^>]+?src=(["\'])(?P
<url
>(?
:https?
:)?
//(?
:cache\
.)?vevo\
.com
/.+?
)\
1']
42 'url
': 'http
://www
.vevo
.com
/watch
/hurts
/somebody
-to
-die
-for/GB1101300280
',
43 'md5
': '95ee28ee45e70130e3ab02b0f579ae23
',
47 'title
': 'Hurts
- Somebody to Die For
',
48 'timestamp
': 1372057200,
49 'upload_date
': '20130624',
51 'track
': 'Somebody to Die For
',
55 'expected_warnings
': ['Unable to download SMIL
file', 'Unable to download info
'],
57 'note
': 'v3 SMIL format
',
58 'url
': 'http
://www
.vevo
.com
/watch
/cassadee
-pope
/i
-wish
-i
-could
-break-your
-heart
/USUV71302923
',
59 'md5
': 'f6ab09b034f8c22969020b042e5ac7fc
',
63 'title
': 'Cassadee Pope
- I Wish I Could Break Your Heart
',
64 'timestamp
': 1392796919,
65 'upload_date
': '20140219',
66 'uploader
': 'Cassadee Pope
',
67 'track
': 'I Wish I Could Break Your Heart
',
68 'artist
': 'Cassadee Pope
',
71 'expected_warnings
': ['Unable to download SMIL
file', 'Unable to download info
'],
73 'note
': 'Age
-limited video
',
74 'url
': 'https
://www
.vevo
.com
/watch
/justin
-timberlake
/tunnel
-vision
-explicit
/USRV81300282
',
78 'title
': 'Justin Timberlake
- Tunnel
Vision (Explicit
)',
80 'timestamp
': 1372888800,
81 'upload_date
': '20130703',
82 'uploader
': 'Justin Timberlake
',
83 'track
': 'Tunnel
Vision (Explicit
)',
84 'artist
': 'Justin Timberlake
',
87 'expected_warnings
': ['Unable to download SMIL
file', 'Unable to download info
'],
89 'note
': 'No video_info
',
90 'url
': 'http
://www
.vevo
.com
/watch
/k
-camp
-1/Till
-I
-Die
/USUV71503000
',
91 'md5
': '8b83cc492d72fc9cf74a02acee7dc1b0
',
95 'title
': 'K Camp ft
. T
.I
. - Till I Die
',
97 'timestamp
': 1449468000,
98 'upload_date
': '20151207',
100 'track
': 'Till I Die
',
104 'expected_warnings
': ['Unable to download SMIL
file', 'Unable to download info
'],
106 'note
': 'Featured test
',
107 'url
': 'https
://www
.vevo
.com
/watch
/lemaitre
/Wait
/USUV71402190
',
108 'md5
': 'd28675e5e8805035d949dc5cf161071d
',
110 'id': 'USUV71402190
',
112 'title
': 'Lemaitre ft
. LoLo
- Wait
',
114 'timestamp
': 1413432000,
115 'upload_date
': '20141016',
116 'uploader
': 'Lemaitre
',
118 'artist
': 'Lemaitre
',
119 'genre
': 'Electronic
',
121 'expected_warnings
': ['Unable to download SMIL
file', 'Unable to download info
'],
123 'note
': 'Only available via webpage
',
124 'url
': 'http
://www
.vevo
.com
/watch
/GBUV71600656
',
125 'md5
': '67e79210613865b66a47c33baa5e37fe
',
127 'id': 'GBUV71600656
',
129 'title
': 'ABC
- Viva Love
',
131 'timestamp
': 1461830400,
132 'upload_date
': '20160428',
134 'track
': 'Viva Love
',
138 'expected_warnings
': ['Failed to download video versions info
'],
140 # no genres available
141 'url
': 'http
://www
.vevo
.com
/watch
/INS171400764
',
142 'only_matching
': True,
144 # Another case available only via the webpage; using streams/streamsV3 formats
145 # Geo-restricted to Netherlands/Germany
146 'url
': 'http
://www
.vevo
.com
/watch
/boostee
/pop
-corn
-clip
-officiel
/FR1A91600909
',
147 'only_matching
': True,
149 'url
': 'https
://embed
.vevo
.com
/?isrc
=USH5V1923499
&partnerId
=4d61b777
-8023-4191-9ede
-497ed6c24647
&partnerAdCode
=',
150 'only_matching
': True,
152 'url
': 'https
://tv
.vevo
.com
/watch
/artist
/janet
-jackson
/US0450100550
',
153 'only_matching
': True,
156 0: 'youtube
', # only in AuthenticateVideo videoVersions
163 def _initialize_api(self, video_id):
164 webpage = self._download_webpage(
165 'https
://accounts
.vevo
.com
/token
', None,
166 note='Retrieving oauth token
',
167 errnote='Unable to retrieve oauth token
',
169 'client_id
': 'SPupX1tvqFEopQ1YS6SS
',
170 'grant_type
': 'urn
:vevo
:params
:oauth
:grant
-type:anonymous
',
173 'Content
-Type
': 'application
/json
',
176 if re.search(r'(?i
)THIS PAGE IS CURRENTLY UNAVAILABLE IN YOUR REGION
', webpage):
177 self.raise_geo_restricted(
178 '%s said
: This page
is currently unavailable
in your region
' % self.IE_NAME)
180 auth_info = self._parse_json(webpage, video_id)
181 self._api_url_template = self.http_scheme() + '//apiv2
.vevo
.com
/%s?token
=' + auth_info['legacy_token
']
183 def _call_api(self, path, *args, **kwargs):
185 data = self._download_json(self._api_url_template % path, *args, **kwargs)
186 except ExtractorError as e:
187 if isinstance(e.cause, compat_HTTPError):
188 errors = self._parse_json(e.cause.read().decode(), None)['errors
']
189 error_message = ', '.join([error['message
'] for error in errors])
190 raise ExtractorError('%s said
: %s' % (self.IE_NAME, error_message), expected=True)
194 def _real_extract(self, url):
195 video_id = self._match_id(url)
197 self._initialize_api(video_id)
199 video_info = self._call_api(
200 'video
/%s' % video_id, video_id, 'Downloading api video info
',
201 'Failed to download video info
')
203 video_versions = self._call_api(
204 'video
/%s/streams
' % video_id, video_id,
205 'Downloading video versions info
',
206 'Failed to download video versions info
',
209 # Some videos are only available via webpage (e.g.
210 # https://github.com/ytdl-org/youtube-dl/issues/9366)
211 if not video_versions:
212 webpage = self._download_webpage(url, video_id)
213 json_data = self._extract_json(webpage, video_id)
214 if 'streams
' in json_data.get('default
', {}):
215 video_versions = json_data['default
']['streams
'][video_id][0]
219 for key, value in json_data['apollo
']['data
'].items()
220 if key.startswith('%s.streams
' % video_id)]
224 featured_artist = None
225 artists = video_info.get('artists
')
226 for curr_artist in artists:
227 if curr_artist.get('role
') == 'Featured
':
228 featured_artist = curr_artist['name
']
230 artist = uploader = curr_artist['name
']
233 for video_version in video_versions:
234 version = self._VERSIONS.get(video_version.get('version
'), 'generic
')
235 version_url = video_version.get('url
')
239 if '.ism
' in version_url:
241 elif '.mpd
' in version_url:
242 formats.extend(self._extract_mpd_formats(
243 version_url, video_id, mpd_id='dash
-%s' % version,
244 note='Downloading
%s MPD information
' % version,
245 errnote='Failed to download
%s MPD information
' % version,
247 elif '.m3u8
' in version_url:
248 formats.extend(self._extract_m3u8_formats(
249 version_url, video_id, 'mp4
', 'm3u8_native
',
250 m3u8_id='hls
-%s' % version,
251 note='Downloading
%s m3u8 information
' % version,
252 errnote='Failed to download
%s m3u8 information
' % version,
255 m = re.search(r'''(?xi)
256 _(?P<quality>[a-z0-9]+)
257 _(?P<width>[0-9]+)x(?P<height>[0-9]+)
258 _(?P<vcodec>[a-z0-9]+)
260 _(?P<acodec>[a-z0-9]+)
262 \.(?P<ext>[a-z0-9]+)''', version_url)
268 'format_id
': f'http
-{version}
-{video_version.get("quality") or m.group("quality")}
',
269 'vcodec
': m.group('vcodec
'),
270 'acodec
': m.group('acodec
'),
271 'vbr
': int(m.group('vbr
')),
272 'abr
': int(m.group('abr
')),
273 'ext
': m.group('ext
'),
274 'width
': int(m.group('width
')),
275 'height
': int(m.group('height
')),
277 self._sort_formats(formats)
279 track = video_info['title
']
281 artist = '%s ft
. %s' % (artist, featured_artist)
282 title = '%s - %s' % (artist, track) if artist else track
284 genres = video_info.get('genres
')
286 genres[0] if genres and isinstance(genres, list)
287 and isinstance(genres[0], compat_str) else None)
289 is_explicit = video_info.get('isExplicit
')
290 if is_explicit is True:
292 elif is_explicit is False:
301 'thumbnail
': video_info.get('imageUrl
') or video_info.get('thumbnailUrl
'),
302 'timestamp
': parse_iso8601(video_info.get('releaseDate
')),
303 'uploader
': uploader,
304 'duration
': int_or_none(video_info.get('duration
')),
305 'view_count
': int_or_none(video_info.get('views
', {}).get('total
')),
306 'age_limit
': age_limit,
313 class VevoPlaylistIE(VevoBaseIE):
314 _VALID_URL = r'https?
://(?
:www\
.)?vevo\
.com
/watch
/(?P
<kind
>playlist|genre
)/(?P
<id>[^
/?
#&]+)'
317 'url': 'http://www.vevo.com/watch/genre/rock',
322 'playlist_count': 20,
324 'url': 'http://www.vevo.com/watch/genre/rock?index=0',
325 'only_matching': True,
328 def _real_extract(self
, url
):
329 mobj
= self
._match
_valid
_url
(url
)
330 playlist_id
= mobj
.group('id')
331 playlist_kind
= mobj
.group('kind')
333 webpage
= self
._download
_webpage
(url
, playlist_id
)
336 index
= qs
.get('index', [None])[0]
339 video_id
= self
._search
_regex
(
340 r
'<meta[^>]+content=(["\'])vevo
://video
/(?P
<id>.+?
)\
1[^
>]*>',
341 webpage, 'video
id', default=None, group='id')
343 return self.url_result('vevo
:%s' % video_id, VevoIE.ie_key())
345 playlists = self._extract_json(webpage, playlist_id)['default
']['%ss' % playlist_kind]
347 playlist = (list(playlists.values())[0]
348 if playlist_kind == 'playlist
' else playlists[playlist_id])
351 self.url_result('vevo
:%s' % src, VevoIE.ie_key())
352 for src in playlist['isrcs
']]
354 return self.playlist_result(
355 entries, playlist.get('playlistId
') or playlist_id,
356 playlist.get('name
'), playlist.get('description
'))