You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.6 KiB

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