pornhd.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. ExtractorError,
  5. int_or_none,
  6. js_to_json,
  7. merge_dicts,
  8. urljoin,
  9. )
  10. class PornHdIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?pornhd\.com/(?:[a-z]{2,4}/)?videos/(?P<id>\d+)(?:/(?P<display_id>.+))?'
  12. _TESTS = [{
  13. 'url': 'http://www.pornhd.com/videos/9864/selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
  14. 'md5': '87f1540746c1d32ec7a2305c12b96b25',
  15. 'info_dict': {
  16. 'id': '9864',
  17. 'display_id': 'selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
  18. 'ext': 'mp4',
  19. 'title': 'Restroom selfie masturbation',
  20. 'description': 'md5:3748420395e03e31ac96857a8f125b2b',
  21. 'thumbnail': r're:^https?://.*\.jpg',
  22. 'view_count': int,
  23. 'like_count': int,
  24. 'age_limit': 18,
  25. },
  26. 'skip': 'HTTP Error 404: Not Found',
  27. }, {
  28. 'url': 'http://www.pornhd.com/videos/1962/sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
  29. 'md5': '1b7b3a40b9d65a8e5b25f7ab9ee6d6de',
  30. 'info_dict': {
  31. 'id': '1962',
  32. 'display_id': 'sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
  33. 'ext': 'mp4',
  34. 'title': 'md5:98c6f8b2d9c229d0f0fde47f61a1a759',
  35. 'description': 'md5:8ff0523848ac2b8f9b065ba781ccf294',
  36. 'thumbnail': r're:^https?://.*\.jpg',
  37. 'view_count': int,
  38. 'like_count': int,
  39. 'age_limit': 18,
  40. },
  41. }]
  42. def _real_extract(self, url):
  43. mobj = self._match_valid_url(url)
  44. video_id = mobj.group('id')
  45. display_id = mobj.group('display_id')
  46. webpage = self._download_webpage(url, display_id or video_id)
  47. title = self._html_search_regex(
  48. [r'<span[^>]+class=["\']video-name["\'][^>]*>([^<]+)',
  49. r'<title>(.+?) - .*?[Pp]ornHD.*?</title>'], webpage, 'title')
  50. sources = self._parse_json(js_to_json(self._search_regex(
  51. r"(?s)sources'?\s*[:=]\s*(\{.+?\})",
  52. webpage, 'sources', default='{}')), video_id)
  53. info = {}
  54. if not sources:
  55. entries = self._parse_html5_media_entries(url, webpage, video_id)
  56. if entries:
  57. info = entries[0]
  58. if not sources and not info:
  59. message = self._html_search_regex(
  60. r'(?s)<(div|p)[^>]+class="no-video"[^>]*>(?P<value>.+?)</\1',
  61. webpage, 'error message', group='value')
  62. raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
  63. formats = []
  64. for format_id, video_url in sources.items():
  65. video_url = urljoin(url, video_url)
  66. if not video_url:
  67. continue
  68. height = int_or_none(self._search_regex(
  69. r'^(\d+)[pP]', format_id, 'height', default=None))
  70. formats.append({
  71. 'url': video_url,
  72. 'ext': determine_ext(video_url, 'mp4'),
  73. 'format_id': format_id,
  74. 'height': height,
  75. })
  76. if formats:
  77. info['formats'] = formats
  78. description = self._html_search_regex(
  79. (r'(?s)<section[^>]+class=["\']video-description[^>]+>(?P<value>.+?)</section>',
  80. r'<(div|p)[^>]+class="description"[^>]*>(?P<value>[^<]+)</\1'),
  81. webpage, 'description', fatal=False,
  82. group='value') or self._html_search_meta(
  83. 'description', webpage, default=None) or self._og_search_description(webpage)
  84. view_count = int_or_none(self._html_search_regex(
  85. r'(\d+) views\s*<', webpage, 'view count', fatal=False))
  86. thumbnail = self._search_regex(
  87. r"poster'?\s*:\s*([\"'])(?P<url>(?:(?!\1).)+)\1", webpage,
  88. 'thumbnail', default=None, group='url')
  89. like_count = int_or_none(self._search_regex(
  90. (r'(\d+)</span>\s*likes',
  91. r'(\d+)\s*</11[^>]+>(?:&nbsp;|\s)*\blikes',
  92. r'class=["\']save-count["\'][^>]*>\s*(\d+)'),
  93. webpage, 'like count', fatal=False))
  94. return merge_dicts(info, {
  95. 'id': video_id,
  96. 'display_id': display_id,
  97. 'title': title,
  98. 'description': description,
  99. 'thumbnail': thumbnail,
  100. 'view_count': view_count,
  101. 'like_count': like_count,
  102. 'formats': formats,
  103. 'age_limit': 18,
  104. })