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.

57 lines
2.3 KiB

12 years ago
12 years ago
  1. # coding: utf-8
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. unescapeHTML,
  7. )
  8. class JukeboxIE(InfoExtractor):
  9. _VALID_URL = r'^http://www\.jukebox\.es\/.+[,](?P<video_id>[a-z0-9]+).html'
  10. _IFRAME = r'<iframe .*src="(?P<iframe>[^"]*)".*>'
  11. _VIDEO_URL = r'"config":{"file":"(?P<video_url>http:[^"]+[.](?P<video_ext>[^.?]+)[?]mdtk=[0-9]+)"'
  12. _TITLE = r'<h1 class="inline">(?P<title>[^<]+)</h1>.*<span id="infos_article_artist">(?P<artist>[^<]+)</span>'
  13. _NOT_AVAILABLE = r'<span>Este video no está disponible por el momento [!]</span>'
  14. _IS_YOUTUBE = r'config":{"file":"(?P<youtube_url>http:[\\][/][\\][/]www[.]youtube[.]com[\\][/]watch[?]v=[^"]+)"'
  15. def _real_extract(self, url):
  16. mobj = re.match(self._VALID_URL, url)
  17. video_id = mobj.group('video_id')
  18. html = self._download_webpage(url, video_id)
  19. mobj = re.search(self._IFRAME, html)
  20. if mobj is None:
  21. raise ExtractorError(u'Cannot extract iframe url')
  22. iframe_url = unescapeHTML(mobj.group('iframe'))
  23. iframe_html = self._download_webpage(iframe_url, video_id, 'Downloading iframe')
  24. mobj = re.search(self._NOT_AVAILABLE, iframe_html)
  25. if mobj is not None:
  26. raise ExtractorError(u'Video is not available(in your country?)!')
  27. self.report_extraction(video_id)
  28. mobj = re.search(self._VIDEO_URL, iframe_html)
  29. if mobj is None:
  30. mobj = re.search(self._IS_YOUTUBE, iframe_html)
  31. if mobj is None:
  32. raise ExtractorError(u'Cannot extract video url')
  33. youtube_url = unescapeHTML(mobj.group('youtube_url')).replace('\/','/')
  34. self.to_screen(u'Youtube video detected')
  35. return self.url_result(youtube_url,ie='Youtube')
  36. video_url = unescapeHTML(mobj.group('video_url')).replace('\/','/')
  37. video_ext = unescapeHTML(mobj.group('video_ext'))
  38. mobj = re.search(self._TITLE, html)
  39. if mobj is None:
  40. raise ExtractorError(u'Cannot extract title')
  41. title = unescapeHTML(mobj.group('title'))
  42. artist = unescapeHTML(mobj.group('artist'))
  43. return [{'id': video_id,
  44. 'url': video_url,
  45. 'title': artist + '-' + title,
  46. 'ext': video_ext
  47. }]