]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vevo.py
70408c4f0edc2ba5b00a9e793cf1e1c2e0ba30ed
[youtubedl] / youtube_dl / extractor / vevo.py
1 import re
2 import json
3
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 )
8
9 class VevoIE(InfoExtractor):
10 """
11 Accepts urls from vevo.com or in the format 'vevo:{id}'
12 (currently used by MTVIE)
13 """
14 _VALID_URL = r'((http://www.vevo.com/watch/.*?/.*?/)|(vevo:))(?P<id>.*?)(\?|$)'
15 _TEST = {
16 u'url': u'http://www.vevo.com/watch/hurts/somebody-to-die-for/GB1101300280',
17 u'file': u'GB1101300280.mp4',
18 u'md5': u'06bea460acb744eab74a9d7dcb4bfd61',
19 u'info_dict': {
20 u"upload_date": u"20130624",
21 u"uploader": u"Hurts",
22 u"title": u"Somebody to Die For"
23 }
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28 video_id = mobj.group('id')
29
30 json_url = 'http://www.vevo.com/data/video/%s' % video_id
31 base_url = 'http://smil.lvl3.vevo.com'
32 videos_url = '%s/Video/V2/VFILE/%s/%sr.smil' % (base_url, video_id, video_id.lower())
33 info_json = self._download_webpage(json_url, video_id, u'Downloading json info')
34 links_webpage = self._download_webpage(videos_url, video_id, u'Downloading videos urls')
35
36 self.report_extraction(video_id)
37 video_info = json.loads(info_json)
38 m_urls = list(re.finditer(r'<video src="(?P<ext>.*?):/?(?P<url>.*?)"', links_webpage))
39 if m_urls is None or len(m_urls) == 0:
40 raise ExtractorError(u'Unable to extract video url')
41 # They are sorted from worst to best quality
42 m_url = m_urls[-1]
43 video_url = base_url + '/' + m_url.group('url')
44 ext = m_url.group('ext')
45
46 return {'url': video_url,
47 'ext': ext,
48 'id': video_id,
49 'title': video_info['title'],
50 'thumbnail': video_info['img'],
51 'upload_date': video_info['launchDate'].replace('/',''),
52 'uploader': video_info['Artists'][0]['title'],
53 }