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.

109 lines
4.0 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. urljoin,
  10. )
  11. class PornHdIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?pornhd\.com/(?:[a-z]{2,4}/)?videos/(?P<id>\d+)(?:/(?P<display_id>.+))?'
  13. _TESTS = [{
  14. 'url': 'http://www.pornhd.com/videos/9864/selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
  15. 'md5': '87f1540746c1d32ec7a2305c12b96b25',
  16. 'info_dict': {
  17. 'id': '9864',
  18. 'display_id': 'selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
  19. 'ext': 'mp4',
  20. 'title': 'Restroom selfie masturbation',
  21. 'description': 'md5:3748420395e03e31ac96857a8f125b2b',
  22. 'thumbnail': r're:^https?://.*\.jpg',
  23. 'view_count': int,
  24. 'like_count': int,
  25. 'age_limit': 18,
  26. }
  27. }, {
  28. # removed video
  29. 'url': 'http://www.pornhd.com/videos/1962/sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
  30. 'md5': '956b8ca569f7f4d8ec563e2c41598441',
  31. 'info_dict': {
  32. 'id': '1962',
  33. 'display_id': 'sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
  34. 'ext': 'mp4',
  35. 'title': 'Sierra loves doing laundry',
  36. 'description': 'md5:8ff0523848ac2b8f9b065ba781ccf294',
  37. 'thumbnail': r're:^https?://.*\.jpg',
  38. 'view_count': int,
  39. 'like_count': int,
  40. 'age_limit': 18,
  41. },
  42. 'skip': 'Not available anymore',
  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. if not sources:
  56. message = self._html_search_regex(
  57. r'(?s)<(div|p)[^>]+class="no-video"[^>]*>(?P<value>.+?)</\1',
  58. webpage, 'error message', group='value')
  59. raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
  60. formats = []
  61. for format_id, video_url in sources.items():
  62. video_url = urljoin(url, video_url)
  63. if not video_url:
  64. continue
  65. height = int_or_none(self._search_regex(
  66. r'^(\d+)[pP]', format_id, 'height', default=None))
  67. formats.append({
  68. 'url': video_url,
  69. 'ext': determine_ext(video_url, 'mp4'),
  70. 'format_id': format_id,
  71. 'height': height,
  72. })
  73. self._sort_formats(formats)
  74. description = self._html_search_regex(
  75. r'<(div|p)[^>]+class="description"[^>]*>(?P<value>[^<]+)</\1',
  76. webpage, 'description', fatal=False, group='value')
  77. view_count = int_or_none(self._html_search_regex(
  78. r'(\d+) views\s*<', webpage, 'view count', fatal=False))
  79. thumbnail = self._search_regex(
  80. r"poster'?\s*:\s*([\"'])(?P<url>(?:(?!\1).)+)\1", webpage,
  81. 'thumbnail', fatal=False, group='url')
  82. like_count = int_or_none(self._search_regex(
  83. (r'(\d+)\s*</11[^>]+>(?:&nbsp;|\s)*\blikes',
  84. r'class=["\']save-count["\'][^>]*>\s*(\d+)'),
  85. webpage, 'like count', fatal=False))
  86. return {
  87. 'id': video_id,
  88. 'display_id': display_id,
  89. 'title': title,
  90. 'description': description,
  91. 'thumbnail': thumbnail,
  92. 'view_count': view_count,
  93. 'like_count': like_count,
  94. 'formats': formats,
  95. 'age_limit': 18,
  96. }