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)
19 (?:https?://www\.vevo\.com/watch/(?:[^/]+/[^/]+/)?|
20 https?://cache\.vevo\.com/m/html/embed\.html\?video=|
21 https?://videoplayer\.vevo\.com/embed/embedded\?videoId=|
25 'url': 'http://www.vevo.com/watch/hurts/somebody-to-die-for/GB1101300280',
26 "md5": "06bea460acb744eab74a9d7dcb4bfd61",
30 "upload_date": "20130624",
32 "title": "Somebody to Die For",
36 'timestamp': 1372057200,
39 'note': 'v3 SMIL format',
40 'url': 'http://www.vevo.com/watch/cassadee-pope/i-wish-i-could-break-your-heart/USUV71302923',
41 'md5': '893ec0e0d4426a1d96c01de8f2bdff58',
45 'upload_date': '20140219',
46 'uploader': 'Cassadee Pope',
47 'title': 'I Wish I Could Break Your Heart',
50 'timestamp': 1392796919,
53 'note': 'Age-limited video',
54 'url': 'https://www.vevo.com/watch/justin-timberlake/tunnel-vision-explicit/USRV81300282',
59 'title': 'Tunnel Vision (Explicit)',
60 'uploader': 'Justin Timberlake',
61 # timestamp and upload_date are often incorrect; seem to change randomly
62 'upload_date': 're:2013070[34]',
66 'skip_download': 'true',
69 _SMIL_BASE_URL = 'http://smil.lvl3.vevo.com/'
71 def _formats_from_json(self, video_info):
72 last_version = {'version': -1}
73 for version in video_info['videoVersions']:
74 # These are the HTTP downloads, other types are for different manifests
75 if version['sourceType'] == 2:
76 if version['version'] > last_version['version']:
77 last_version = version
78 if last_version['version'] == -1:
79 raise ExtractorError('Unable to extract last version of the video')
81 renditions = xml.etree.ElementTree.fromstring(last_version['data'])
83 # Already sorted from worst to best quality
84 for rend in renditions.findall('rendition'):
86 format_note = '%(videoCodec)s@%(videoBitrate)4sk, %(audioCodec)s@%(audioBitrate)3sk' % attr
89 'format_id': attr['name'],
90 'format_note': format_note,
91 'height': int(attr['frameheight']),
92 'width': int(attr['frameWidth']),
96 def _formats_from_smil(self, smil_xml):
98 smil_doc = xml.etree.ElementTree.fromstring(smil_xml.encode('utf-8'))
99 els = smil_doc.findall('.//{http://www.w3.org/2001/SMIL20/Language}video')
101 src = el.attrib['src']
102 m = re.match(r'''(?xi)
105 [/a-z0-9]+ # The directory and main part of the URL
107 _(?P<width>[0-9]+)x(?P<height>[0-9]+)
108 _(?P<vcodec>[a-z0-9]+)
110 _(?P<acodec>[a-z0-9]+)
112 \.[a-z0-9]+ # File extension
117 format_url = self._SMIL_BASE_URL + m.group('path')
120 'format_id': 'SMIL_' + m.group('cbr'),
121 'vcodec': m.group('vcodec'),
122 'acodec': m.group('acodec'),
123 'vbr': int(m.group('vbr')),
124 'abr': int(m.group('abr')),
125 'ext': m.group('ext'),
126 'width': int(m.group('width')),
127 'height': int(m.group('height')),
131 def _real_extract(self, url):
132 mobj = re.match(self._VALID_URL, url)
133 video_id = mobj.group('id')
135 json_url = 'http://videoplayer.vevo.com/VideoService/AuthenticateVideo?isrc=%s' % video_id
136 video_info = self._download_json(json_url, video_id)['video']
138 formats = self._formats_from_json(video_info)
140 is_explicit = video_info.get('isExplicit')
141 if is_explicit is True:
143 elif is_explicit is False:
149 smil_blocks = sorted((
150 f for f in video_info['videoVersions']
151 if f['sourceType'] == 13),
152 key=lambda f: f['version'])
154 smil_url = '%s/Video/V2/VFILE/%s/%sr.smil' % (
155 self._SMIL_BASE_URL, video_id, video_id.lower())
157 smil_url_m = self._search_regex(
158 r'url="([^"]+)"', smil_blocks[-1]['data'], 'SMIL URL',
160 if smil_url_m is not None:
161 smil_url = smil_url_m
164 smil_xml = self._download_webpage(smil_url, video_id,
165 'Downloading SMIL info')
166 formats.extend(self._formats_from_smil(smil_xml))
167 except ExtractorError as ee:
168 if not isinstance(ee.cause, compat_HTTPError):
170 self._downloader.report_warning(
171 'Cannot download SMIL information, falling back to JSON ..')
173 timestamp_ms = int(self._search_regex(
174 r'/Date\((\d+)\)/', video_info['launchDate'], 'launch date'))
178 'title': video_info['title'],
180 'thumbnail': video_info['imageUrl'],
181 'timestamp': timestamp_ms // 1000,
182 'uploader': video_info['mainArtists'][0]['artistName'],
183 'duration': video_info['duration'],
184 'age_limit': age_limit,