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.

71 lines
2.5 KiB

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