1 from __future__ import unicode_literals
4 import xml.etree.ElementTree
6 from .common import InfoExtractor
13 class VevoIE(InfoExtractor):
15 Accepts urls from vevo.com or in the format 'vevo:{id}'
16 (currently used by MTVIE and MySpaceIE)
19 (?:https?://www\.vevo\.com/watch/(?:[^/]+/(?:[^/]+/)?)?|
20 https?://cache\.vevo\.com/m/html/embed\.html\?video=|
21 https?://videoplayer\.vevo\.com/embed/embedded\?videoId=|
26 'url': 'http://www.vevo.com/watch/hurts/somebody-to-die-for/GB1101300280',
27 "md5": "95ee28ee45e70130e3ab02b0f579ae23",
31 "upload_date": "20130624",
33 "title": "Somebody to Die For",
37 # timestamp and upload_date are often incorrect; seem to change randomly
41 'note': 'v3 SMIL format',
42 'url': 'http://www.vevo.com/watch/cassadee-pope/i-wish-i-could-break-your-heart/USUV71302923',
43 'md5': 'f6ab09b034f8c22969020b042e5ac7fc',
47 'upload_date': '20140219',
48 'uploader': 'Cassadee Pope',
49 'title': 'I Wish I Could Break Your Heart',
55 'note': 'Age-limited video',
56 'url': 'https://www.vevo.com/watch/justin-timberlake/tunnel-vision-explicit/USRV81300282',
61 'title': 'Tunnel Vision (Explicit)',
62 'uploader': 'Justin Timberlake',
63 'upload_date': 're:2013070[34]',
67 'skip_download': 'true',
70 _SMIL_BASE_URL = 'http://smil.lvl3.vevo.com/'
72 def _real_initialize(self):
73 req = compat_urllib_request.Request(
74 'http://www.vevo.com/auth', data=b'')
75 webpage = self._download_webpage(
77 note='Retrieving oauth token',
78 errnote='Unable to retrieve oauth token',
81 self._oauth_token = None
83 self._oauth_token = self._search_regex(
84 r'access_token":\s*"([^"]+)"',
85 webpage, 'access token', fatal=False)
87 def _formats_from_json(self, video_info):
88 last_version = {'version': -1}
89 for version in video_info['videoVersions']:
90 # These are the HTTP downloads, other types are for different manifests
91 if version['sourceType'] == 2:
92 if version['version'] > last_version['version']:
93 last_version = version
94 if last_version['version'] == -1:
95 raise ExtractorError('Unable to extract last version of the video')
97 renditions = xml.etree.ElementTree.fromstring(last_version['data'])
99 # Already sorted from worst to best quality
100 for rend in renditions.findall('rendition'):
102 format_note = '%(videoCodec)s@%(videoBitrate)4sk, %(audioCodec)s@%(audioBitrate)3sk' % attr
105 'format_id': attr['name'],
106 'format_note': format_note,
107 'height': int(attr['frameheight']),
108 'width': int(attr['frameWidth']),
112 def _formats_from_smil(self, smil_xml):
114 smil_doc = xml.etree.ElementTree.fromstring(smil_xml.encode('utf-8'))
115 els = smil_doc.findall('.//{http://www.w3.org/2001/SMIL20/Language}video')
117 src = el.attrib['src']
118 m = re.match(r'''(?xi)
121 [/a-z0-9]+ # The directory and main part of the URL
123 _(?P<width>[0-9]+)x(?P<height>[0-9]+)
124 _(?P<vcodec>[a-z0-9]+)
126 _(?P<acodec>[a-z0-9]+)
128 \.[a-z0-9]+ # File extension
133 format_url = self._SMIL_BASE_URL + m.group('path')
136 'format_id': 'SMIL_' + m.group('cbr'),
137 'vcodec': m.group('vcodec'),
138 'acodec': m.group('acodec'),
139 'vbr': int(m.group('vbr')),
140 'abr': int(m.group('abr')),
141 'ext': m.group('ext'),
142 'width': int(m.group('width')),
143 'height': int(m.group('height')),
147 def _download_api_formats(self, video_id):
148 if not self._oauth_token:
149 self._downloader.report_warning(
150 'No oauth token available, skipping API HLS download')
153 api_url = 'https://apiv2.vevo.com/video/%s/streams/hls?token=%s' % (
154 video_id, self._oauth_token)
155 api_data = self._download_json(
157 note='Downloading HLS formats',
158 errnote='Failed to download HLS format list', fatal=False)
162 m3u8_url = api_data[0]['url']
163 return self._extract_m3u8_formats(
164 m3u8_url, video_id, entry_protocol='m3u8_native', ext='mp4',
167 def _real_extract(self, url):
168 mobj = re.match(self._VALID_URL, url)
169 video_id = mobj.group('id')
171 json_url = 'http://videoplayer.vevo.com/VideoService/AuthenticateVideo?isrc=%s' % video_id
172 response = self._download_json(json_url, video_id)
173 video_info = response['video']
176 if 'statusMessage' in response:
177 raise ExtractorError('%s said: %s' % (self.IE_NAME, response['statusMessage']), expected=True)
178 raise ExtractorError('Unable to extract videos')
180 formats = self._formats_from_json(video_info)
182 is_explicit = video_info.get('isExplicit')
183 if is_explicit is True:
185 elif is_explicit is False:
190 # Download via HLS API
191 formats.extend(self._download_api_formats(video_id))
193 self._sort_formats(formats)
194 timestamp_ms = int(self._search_regex(
195 r'/Date\((\d+)\)/', video_info['launchDate'], 'launch date'))
199 'title': video_info['title'],
201 'thumbnail': video_info['imageUrl'],
202 'timestamp': timestamp_ms // 1000,
203 'uploader': video_info['mainArtists'][0]['artistName'],
204 'duration': video_info['duration'],
205 'age_limit': age_limit,