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.

69 lines
2.5 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. u"age_limit": 18,
  15. }
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. video_id = mobj.group('videoid')
  20. # Get webpage content
  21. webpage = self._download_webpage(url, video_id)
  22. age_limit = self._rta_search(webpage)
  23. # Get the video title
  24. video_title = self._html_search_regex(r'<title>(?P<title>.*)</title>',
  25. webpage, u'title').strip()
  26. # Get the embed page
  27. result = re.search(r'https?://www.youjizz.com/videos/embed/(?P<videoid>[0-9]+)', webpage)
  28. if result is None:
  29. raise ExtractorError(u'ERROR: unable to extract embed page')
  30. embed_page_url = result.group(0).strip()
  31. video_id = result.group('videoid')
  32. webpage = self._download_webpage(embed_page_url, video_id)
  33. # Get the video URL
  34. m_playlist = re.search(r'so.addVariable\("playlist", ?"(?P<playlist>.+?)"\);', webpage)
  35. if m_playlist is not None:
  36. playlist_url = m_playlist.group('playlist')
  37. playlist_page = self._download_webpage(playlist_url, video_id,
  38. u'Downloading playlist page')
  39. m_levels = list(re.finditer(r'<level bitrate="(\d+?)" file="(.*?)"', playlist_page))
  40. if len(m_levels) == 0:
  41. raise ExtractorError(u'Unable to extract video url')
  42. videos = [(int(m.group(1)), m.group(2)) for m in m_levels]
  43. (_, video_url) = sorted(videos)[0]
  44. video_url = video_url.replace('%252F', '%2F')
  45. else:
  46. video_url = self._search_regex(r'so.addVariable\("file",encodeURIComponent\("(?P<source>[^"]+)"\)\);',
  47. webpage, u'video URL')
  48. info = {'id': video_id,
  49. 'url': video_url,
  50. 'title': video_title,
  51. 'ext': 'flv',
  52. 'format': 'flv',
  53. 'player_url': embed_page_url,
  54. 'age_limit': age_limit}
  55. return [info]