3 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 u'url': u'http://www.vevo.com/watch/hurts/somebody-to-die-for/GB1101300280',
26 u'file': u'GB1101300280.mp4',
27 u"md5": u"06bea460acb744eab74a9d7dcb4bfd61",
29 u"upload_date": u"20130624",
30 u"uploader": u"Hurts",
31 u"title": u"Somebody to Die For",
37 _SMIL_BASE_URL = 'http://smil.lvl3.vevo.com/'
39 def _formats_from_json(self, video_info):
40 last_version = {'version': -1}
41 for version in video_info['videoVersions']:
42 # These are the HTTP downloads, other types are for different manifests
43 if version['sourceType'] == 2:
44 if version['version'] > last_version['version']:
45 last_version = version
46 if last_version['version'] == -1:
47 raise ExtractorError(u'Unable to extract last version of the video')
49 renditions = xml.etree.ElementTree.fromstring(last_version['data'])
51 # Already sorted from worst to best quality
52 for rend in renditions.findall('rendition'):
54 format_note = '%(videoCodec)s@%(videoBitrate)4sk, %(audioCodec)s@%(audioBitrate)3sk' % attr
57 'format_id': attr['name'],
58 'format_note': format_note,
59 'height': int(attr['frameheight']),
60 'width': int(attr['frameWidth']),
64 def _formats_from_smil(self, smil_xml):
66 smil_doc = xml.etree.ElementTree.fromstring(smil_xml.encode('utf-8'))
67 els = smil_doc.findall('.//{http://www.w3.org/2001/SMIL20/Language}video')
69 src = el.attrib['src']
70 m = re.match(r'''(?xi)
73 [/a-z0-9]+ # The directory and main part of the URL
75 _(?P<width>[0-9]+)x(?P<height>[0-9]+)
76 _(?P<vcodec>[a-z0-9]+)
78 _(?P<acodec>[a-z0-9]+)
80 \.[a-z0-9]+ # File extension
85 format_url = self._SMIL_BASE_URL + m.group('path')
88 'format_id': u'SMIL_' + m.group('cbr'),
89 'vcodec': m.group('vcodec'),
90 'acodec': m.group('acodec'),
91 'vbr': int(m.group('vbr')),
92 'abr': int(m.group('abr')),
93 'ext': m.group('ext'),
94 'width': int(m.group('width')),
95 'height': int(m.group('height')),
99 def _real_extract(self, url):
100 mobj = re.match(self._VALID_URL, url)
101 video_id = mobj.group('id')
103 json_url = 'http://videoplayer.vevo.com/VideoService/AuthenticateVideo?isrc=%s' % video_id
104 info_json = self._download_webpage(json_url, video_id, u'Downloading json info')
105 video_info = json.loads(info_json)['video']
107 formats = self._formats_from_json(video_info)
109 smil_url = '%s/Video/V2/VFILE/%s/%sr.smil' % (
110 self._SMIL_BASE_URL, video_id, video_id.lower())
111 smil_xml = self._download_webpage(smil_url, video_id,
112 u'Downloading SMIL info')
113 formats.extend(self._formats_from_smil(smil_xml))
114 except ExtractorError as ee:
115 if not isinstance(ee.cause, compat_HTTPError):
117 self._downloader.report_warning(
118 u'Cannot download SMIL information, falling back to JSON ..')
120 timestamp_ms = int(self._search_regex(
121 r'/Date\((\d+)\)/', video_info['launchDate'], u'launch date'))
122 upload_date = datetime.datetime.fromtimestamp(timestamp_ms // 1000)
125 'title': video_info['title'],
127 'thumbnail': video_info['imageUrl'],
128 'upload_date': upload_date.strftime('%Y%m%d'),
129 'uploader': video_info['mainArtists'][0]['artistName'],
130 'duration': video_info['duration'],