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.

65 lines
2.3 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. )
  6. class YouJizzIE(InfoExtractor):
  7. _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youjizz\.com/videos/(?P<videoid>[^.]+).html$'
  8. _TEST = {
  9. u'url': u'http://www.youjizz.com/videos/zeichentrick-1-2189178.html',
  10. u'file': u'2189178.flv',
  11. u'md5': u'07e15fa469ba384c7693fd246905547c',
  12. u'info_dict': {
  13. u"title": u"Zeichentrick 1"
  14. }
  15. }
  16. def _real_extract(self, url):
  17. mobj = re.match(self._VALID_URL, url)
  18. video_id = mobj.group('videoid')
  19. # Get webpage content
  20. webpage = self._download_webpage(url, video_id)
  21. # Get the video title
  22. video_title = self._html_search_regex(r'<title>(?P<title>.*)</title>',
  23. webpage, u'title').strip()
  24. # Get the embed page
  25. result = re.search(r'https?://www.youjizz.com/videos/embed/(?P<videoid>[0-9]+)', webpage)
  26. if result is None:
  27. raise ExtractorError(u'ERROR: unable to extract embed page')
  28. embed_page_url = result.group(0).strip()
  29. video_id = result.group('videoid')
  30. webpage = self._download_webpage(embed_page_url, video_id)
  31. # Get the video URL
  32. m_playlist = re.search(r'so.addVariable\("playlist", ?"(?P<playlist>.+?)"\);', webpage)
  33. if m_playlist is not None:
  34. playlist_url = m_playlist.group('playlist')
  35. playlist_page = self._download_webpage(playlist_url, video_id,
  36. u'Downloading playlist page')
  37. m_levels = list(re.finditer(r'<level bitrate="(\d+?)" file="(.*?)"', playlist_page))
  38. if len(m_levels) == 0:
  39. raise ExtractorError(u'Unable to extract video url')
  40. videos = [(int(m.group(1)), m.group(2)) for m in m_levels]
  41. (_, video_url) = sorted(videos)[0]
  42. video_url = video_url.replace('%252F', '%2F')
  43. else:
  44. video_url = self._search_regex(r'so.addVariable\("file",encodeURIComponent\("(?P<source>[^"]+)"\)\);',
  45. webpage, u'video URL')
  46. info = {'id': video_id,
  47. 'url': video_url,
  48. 'title': video_title,
  49. 'ext': 'flv',
  50. 'format': 'flv',
  51. 'player_url': embed_page_url}
  52. return [info]