youjizz.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. int_or_none,
  5. parse_duration,
  6. url_or_none,
  7. )
  8. class YouJizzIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:\w+\.)?youjizz\.com/videos/(?:[^/#?]*-(?P<id>\d+)\.html|embed/(?P<embed_id>\d+))'
  10. _TESTS = [{
  11. 'url': 'http://www.youjizz.com/videos/zeichentrick-1-2189178.html',
  12. 'md5': 'b1e1dfaa8bb9537d8b84eeda9cf4acf4',
  13. 'info_dict': {
  14. 'id': '2189178',
  15. 'ext': 'mp4',
  16. 'title': 'Zeichentrick 1',
  17. 'age_limit': 18,
  18. 'duration': 2874,
  19. },
  20. }, {
  21. 'url': 'http://www.youjizz.com/videos/-2189178.html',
  22. 'only_matching': True,
  23. }, {
  24. 'url': 'https://www.youjizz.com/videos/embed/31991001',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. mobj = self._match_valid_url(url)
  29. video_id = mobj.group('id') or mobj.group('embed_id')
  30. webpage = self._download_webpage(url, video_id)
  31. title = self._html_extract_title(webpage)
  32. formats = []
  33. encodings = self._parse_json(
  34. self._search_regex(
  35. r'[Ee]ncodings\s*=\s*(\[.+?\]);\n', webpage, 'encodings',
  36. default='[]'),
  37. video_id, fatal=False)
  38. for encoding in encodings:
  39. if not isinstance(encoding, dict):
  40. continue
  41. format_url = url_or_none(encoding.get('filename'))
  42. if not format_url:
  43. continue
  44. if determine_ext(format_url) == 'm3u8':
  45. formats.extend(self._extract_m3u8_formats(
  46. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  47. m3u8_id='hls', fatal=False))
  48. else:
  49. format_id = encoding.get('name') or encoding.get('quality')
  50. height = int_or_none(self._search_regex(
  51. r'^(\d+)[pP]', format_id, 'height', default=None))
  52. formats.append({
  53. 'url': format_url,
  54. 'format_id': format_id,
  55. 'height': height,
  56. })
  57. if formats:
  58. info_dict = {
  59. 'formats': formats,
  60. }
  61. else:
  62. # YouJizz's HTML5 player has invalid HTML
  63. webpage = webpage.replace('"controls', '" controls')
  64. info_dict = self._parse_html5_media_entries(
  65. url, webpage, video_id)[0]
  66. duration = parse_duration(self._search_regex(
  67. r'<strong>Runtime:</strong>([^<]+)', webpage, 'duration',
  68. default=None))
  69. uploader = self._search_regex(
  70. r'<strong>Uploaded By:.*?<a[^>]*>([^<]+)', webpage, 'uploader',
  71. default=None)
  72. info_dict.update({
  73. 'id': video_id,
  74. 'title': title,
  75. 'age_limit': self._rta_search(webpage),
  76. 'duration': duration,
  77. 'uploader': uploader,
  78. })
  79. return info_dict