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.

121 lines
4.5 KiB

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