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 'upload_date': '20130704',
62 'timestamp': 1372906800,
65 'skip_download': 'true',
68 _SMIL_BASE_URL = 'http://smil.lvl3.vevo.com/'
70 def _formats_from_json(self, video_info):
71 last_version = {'version': -1}
72 for version in video_info['videoVersions']:
73 # These are the HTTP downloads, other types are for different manifests
74 if version['sourceType'] == 2:
75 if version['version'] > last_version['version']:
76 last_version = version
77 if last_version['version'] == -1:
78 raise ExtractorError('Unable to extract last version of the video')
80 renditions = xml.etree.ElementTree.fromstring(last_version['data'])
82 # Already sorted from worst to best quality
83 for rend in renditions.findall('rendition'):
85 format_note = '%(videoCodec)s@%(videoBitrate)4sk, %(audioCodec)s@%(audioBitrate)3sk' % attr
88 'format_id': attr['name'],
89 'format_note': format_note,
90 'height': int(attr['frameheight']),
91 'width': int(attr['frameWidth']),
95 def _formats_from_smil(self, smil_xml):
97 smil_doc = xml.etree.ElementTree.fromstring(smil_xml.encode('utf-8'))
98 els = smil_doc.findall('.//{http://www.w3.org/2001/SMIL20/Language}video')
100 src = el.attrib['src']
101 m = re.match(r'''(?xi)
104 [/a-z0-9]+ # The directory and main part of the URL
106 _(?P<width>[0-9]+)x(?P<height>[0-9]+)
107 _(?P<vcodec>[a-z0-9]+)
109 _(?P<acodec>[a-z0-9]+)
111 \.[a-z0-9]+ # File extension
116 format_url = self._SMIL_BASE_URL + m.group('path')
119 'format_id': 'SMIL_' + m.group('cbr'),
120 'vcodec': m.group('vcodec'),
121 'acodec': m.group('acodec'),
122 'vbr': int(m.group('vbr')),
123 'abr': int(m.group('abr')),
124 'ext': m.group('ext'),
125 'width': int(m.group('width')),
126 'height': int(m.group('height')),
130 def _real_extract(self, url):
131 mobj = re.match(self._VALID_URL, url)
132 video_id = mobj.group('id')
134 json_url = 'http://videoplayer.vevo.com/VideoService/AuthenticateVideo?isrc=%s' % video_id
135 video_info = self._download_json(json_url, video_id)['video']
137 formats = self._formats_from_json(video_info)
139 is_explicit = video_info.get('isExplicit')
140 if is_explicit is True:
142 elif is_explicit is False:
148 smil_blocks = sorted((
149 f for f in video_info['videoVersions']
150 if f['sourceType'] == 13),
151 key=lambda f: f['version'])
153 smil_url = '%s/Video/V2/VFILE/%s/%sr.smil' % (
154 self._SMIL_BASE_URL, video_id, video_id.lower())
156 smil_url_m = self._search_regex(
157 r'url="([^"]+)"', smil_blocks[-1]['data'], 'SMIL URL',
159 if smil_url_m is not None:
160 smil_url = smil_url_m
163 smil_xml = self._download_webpage(smil_url, video_id,
164 'Downloading SMIL info')
165 formats.extend(self._formats_from_smil(smil_xml))
166 except ExtractorError as ee:
167 if not isinstance(ee.cause, compat_HTTPError):
169 self._downloader.report_warning(
170 'Cannot download SMIL information, falling back to JSON ..')
172 timestamp_ms = int(self._search_regex(
173 r'/Date\((\d+)\)/', video_info['launchDate'], 'launch date'))
177 'title': video_info['title'],
179 'thumbnail': video_info['imageUrl'],
180 'timestamp': timestamp_ms // 1000,
181 'uploader': video_info['mainArtists'][0]['artistName'],
182 'duration': video_info['duration'],
183 'age_limit': age_limit,