]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/vevo.py
Add Jukebox IE
[youtube-dl.git] / youtube_dl / extractor / vevo.py
1 import re
2 import json
3
4 from .common import InfoExtractor
5 from ..utils import (
6     unified_strdate,
7     ExtractorError,
8 )
9
10 class VevoIE(InfoExtractor):
11     """
12     Accecps urls from vevo.com or in the format 'vevo:{id}'
13     (currently used by MTVIE)
14     """
15     _VALID_URL = r'((http://www.vevo.com/watch/.*?/.*?/)|(vevo:))(?P<id>.*)$'
16
17     def _real_extract(self, url):
18         mobj = re.match(self._VALID_URL, url)
19         video_id = mobj.group('id')
20
21         json_url = 'http://www.vevo.com/data/video/%s' % video_id
22         base_url = 'http://smil.lvl3.vevo.com'
23         videos_url = '%s/Video/V2/VFILE/%s/%sr.smil' % (base_url, video_id, video_id.lower())
24         info_json = self._download_webpage(json_url, video_id, u'Downloading json info')
25         links_webpage = self._download_webpage(videos_url, video_id, u'Downloading videos urls')
26
27         self.report_extraction(video_id)
28         video_info = json.loads(info_json)
29         m_urls = list(re.finditer(r'<video src="(?P<ext>.*?):(?P<url>.*?)"', links_webpage))
30         if m_urls is None or len(m_urls) == 0:
31             raise ExtractorError(u'Unable to extract video url')
32         # They are sorted from worst to best quality
33         m_url = m_urls[-1]
34         video_url = base_url + m_url.group('url')
35         ext = m_url.group('ext')
36
37         return {'url': video_url,
38                 'ext': ext,
39                 'id': video_id,
40                 'title': video_info['title'],
41                 'thumbnail': video_info['img'],
42                 'upload_date': video_info['launchDate'].replace('/',''),
43                 'uploader': video_info['Artists'][0]['title'],
44                 }