- _SMIL_BASE_URL = 'http://smil.lvl3.vevo.com/'
-
- def _formats_from_json(self, video_info):
- last_version = {'version': -1}
- for version in video_info['videoVersions']:
- # These are the HTTP downloads, other types are for different manifests
- if version['sourceType'] == 2:
- if version['version'] > last_version['version']:
- last_version = version
- if last_version['version'] == -1:
- raise ExtractorError('Unable to extract last version of the video')
-
- renditions = xml.etree.ElementTree.fromstring(last_version['data'])
- formats = []
- # Already sorted from worst to best quality
- for rend in renditions.findall('rendition'):
- attr = rend.attrib
- format_note = '%(videoCodec)s@%(videoBitrate)4sk, %(audioCodec)s@%(audioBitrate)3sk' % attr
- formats.append({
- 'url': attr['url'],
- 'format_id': attr['name'],
- 'format_note': format_note,
- 'height': int(attr['frameheight']),
- 'width': int(attr['frameWidth']),
- })
- return formats
-
- def _formats_from_smil(self, smil_xml):
+ _VERSIONS = {
+ 0: 'youtube', # only in AuthenticateVideo videoVersions
+ 1: 'level3',
+ 2: 'akamai',
+ 3: 'level3',
+ 4: 'amazon',
+ }
+
+ def _initialize_api(self, video_id):
+ req = sanitized_Request(
+ 'http://www.vevo.com/auth', data=b'')
+ webpage = self._download_webpage(
+ req, None,
+ note='Retrieving oauth token',
+ errnote='Unable to retrieve oauth token')
+
+ if re.search(r'(?i)THIS PAGE IS CURRENTLY UNAVAILABLE IN YOUR REGION', webpage):
+ self.raise_geo_restricted(
+ '%s said: This page is currently unavailable in your region' % self.IE_NAME)
+
+ auth_info = self._parse_json(webpage, video_id)
+ self._api_url_template = self.http_scheme() + '//apiv2.vevo.com/%s?token=' + auth_info['access_token']
+
+ def _call_api(self, path, *args, **kwargs):
+ try:
+ data = self._download_json(self._api_url_template % path, *args, **kwargs)
+ except ExtractorError as e:
+ if isinstance(e.cause, compat_HTTPError):
+ errors = self._parse_json(e.cause.read().decode(), None)['errors']
+ error_message = ', '.join([error['message'] for error in errors])
+ raise ExtractorError('%s said: %s' % (self.IE_NAME, error_message), expected=True)
+ raise
+ return data
+
+ def _real_extract(self, url):
+ video_id = self._match_id(url)
+
+ self._initialize_api(video_id)
+
+ video_info = self._call_api(
+ 'video/%s' % video_id, video_id, 'Downloading api video info',
+ 'Failed to download video info')
+
+ video_versions = self._call_api(
+ 'video/%s/streams' % video_id, video_id,
+ 'Downloading video versions info',
+ 'Failed to download video versions info',
+ fatal=False)
+
+ # Some videos are only available via webpage (e.g.
+ # https://github.com/rg3/youtube-dl/issues/9366)
+ if not video_versions:
+ webpage = self._download_webpage(url, video_id)
+ video_versions = self._extract_json(webpage, video_id, 'streams')[video_id][0]
+
+ uploader = None
+ artist = None
+ featured_artist = None
+ artists = video_info.get('artists')
+ for curr_artist in artists:
+ if curr_artist.get('role') == 'Featured':
+ featured_artist = curr_artist['name']
+ else:
+ artist = uploader = curr_artist['name']
+