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.

64 lines
2.4 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<id>[0-9]+)\.html(?:$|[?#])'
  9. _TESTS = [{
  10. 'url': 'http://www.youjizz.com/videos/zeichentrick-1-2189178.html',
  11. 'md5': '07e15fa469ba384c7693fd246905547c',
  12. 'info_dict': {
  13. 'id': '2189178',
  14. 'ext': 'flv',
  15. 'title': 'Zeichentrick 1',
  16. 'age_limit': 18,
  17. }
  18. }, {
  19. 'url': 'http://www.youjizz.com/videos/-2189178.html',
  20. 'only_matching': True,
  21. }]
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(url, video_id)
  25. age_limit = self._rta_search(webpage)
  26. video_title = self._html_search_regex(
  27. r'<title>\s*(.*)\s*</title>', webpage, 'title')
  28. embed_page_url = self._search_regex(
  29. r'(https?://www.youjizz.com/videos/embed/[0-9]+)',
  30. webpage, 'embed page')
  31. webpage = self._download_webpage(
  32. embed_page_url, video_id, note='downloading embed page')
  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. '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('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, 'video URL')
  48. return {
  49. 'id': video_id,
  50. 'url': video_url,
  51. 'title': video_title,
  52. 'ext': 'flv',
  53. 'format': 'flv',
  54. 'player_url': embed_page_url,
  55. 'age_limit': age_limit,
  56. }