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.

56 lines
2.2 KiB

11 years ago
11 years ago
11 years ago
11 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?\..+?\/.+[,](?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. _IS_YOUTUBE = r'config":{"file":"(?P<youtube_url>http:[\\][/][\\][/]www[.]youtube[.]com[\\][/]watch[?]v=[^"]+)"'
  14. def _real_extract(self, url):
  15. mobj = re.match(self._VALID_URL, url)
  16. video_id = mobj.group('video_id')
  17. html = self._download_webpage(url, video_id)
  18. mobj = re.search(self._IFRAME, html)
  19. if mobj is None:
  20. raise ExtractorError(u'Cannot extract iframe url')
  21. iframe_url = unescapeHTML(mobj.group('iframe'))
  22. iframe_html = self._download_webpage(iframe_url, video_id, 'Downloading iframe')
  23. mobj = re.search(r'class="jkb_waiting"', iframe_html)
  24. if mobj is not None:
  25. raise ExtractorError(u'Video is not available(in your country?)!')
  26. self.report_extraction(video_id)
  27. mobj = re.search(self._VIDEO_URL, iframe_html)
  28. if mobj is None:
  29. mobj = re.search(self._IS_YOUTUBE, iframe_html)
  30. if mobj is None:
  31. raise ExtractorError(u'Cannot extract video url')
  32. youtube_url = unescapeHTML(mobj.group('youtube_url')).replace('\/','/')
  33. self.to_screen(u'Youtube video detected')
  34. return self.url_result(youtube_url,ie='Youtube')
  35. video_url = unescapeHTML(mobj.group('video_url')).replace('\/','/')
  36. video_ext = unescapeHTML(mobj.group('video_ext'))
  37. mobj = re.search(self._TITLE, html)
  38. if mobj is None:
  39. raise ExtractorError(u'Cannot extract title')
  40. title = unescapeHTML(mobj.group('title'))
  41. artist = unescapeHTML(mobj.group('artist'))
  42. return [{'id': video_id,
  43. 'url': video_url,
  44. 'title': artist + '-' + title,
  45. 'ext': video_ext
  46. }]