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.

95 lines
3.0 KiB

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