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.

96 lines
3.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. ExtractorError,
  6. int_or_none,
  7. js_to_json,
  8. )
  9. class PornHdIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?pornhd\.com/(?:[a-z]{2,4}/)?videos/(?P<id>\d+)(?:/(?P<display_id>.+))?'
  11. _TESTS = [{
  12. 'url': 'http://www.pornhd.com/videos/9864/selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
  13. 'md5': 'c8b964b1f0a4b5f7f28ae3a5c9f86ad5',
  14. 'info_dict': {
  15. 'id': '9864',
  16. 'display_id': 'selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
  17. 'ext': 'mp4',
  18. 'title': 'Restroom selfie masturbation',
  19. 'description': 'md5:3748420395e03e31ac96857a8f125b2b',
  20. 'thumbnail': 're:^https?://.*\.jpg',
  21. 'view_count': int,
  22. 'age_limit': 18,
  23. }
  24. }, {
  25. # removed video
  26. 'url': 'http://www.pornhd.com/videos/1962/sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
  27. 'md5': '956b8ca569f7f4d8ec563e2c41598441',
  28. 'info_dict': {
  29. 'id': '1962',
  30. 'display_id': 'sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
  31. 'ext': 'mp4',
  32. 'title': 'Sierra loves doing laundry',
  33. 'description': 'md5:8ff0523848ac2b8f9b065ba781ccf294',
  34. 'thumbnail': 're:^https?://.*\.jpg',
  35. 'view_count': int,
  36. 'age_limit': 18,
  37. },
  38. 'skip': 'Not available anymore',
  39. }]
  40. def _real_extract(self, url):
  41. mobj = re.match(self._VALID_URL, url)
  42. video_id = mobj.group('id')
  43. display_id = mobj.group('display_id')
  44. webpage = self._download_webpage(url, display_id or video_id)
  45. title = self._html_search_regex(
  46. [r'<span[^>]+class=["\']video-name["\'][^>]*>([^<]+)',
  47. r'<title>(.+?) - .*?[Pp]ornHD.*?</title>'], webpage, 'title')
  48. sources = self._parse_json(js_to_json(self._search_regex(
  49. r"(?s)'sources'\s*:\s*(\{.+?\})\s*\}[;,)]",
  50. webpage, 'sources', default='{}')), video_id)
  51. if not sources:
  52. message = self._html_search_regex(
  53. r'(?s)<(div|p)[^>]+class="no-video"[^>]*>(?P<value>.+?)</\1',
  54. webpage, 'error message', group='value')
  55. raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
  56. formats = []
  57. for format_id, video_url in sources.items():
  58. if not video_url:
  59. continue
  60. height = int_or_none(self._search_regex(
  61. r'^(\d+)[pP]', format_id, 'height', default=None))
  62. formats.append({
  63. 'url': video_url,
  64. 'format_id': format_id,
  65. 'height': height,
  66. })
  67. self._sort_formats(formats)
  68. description = self._html_search_regex(
  69. r'<(div|p)[^>]+class="description"[^>]*>(?P<value>[^<]+)</\1',
  70. webpage, 'description', fatal=False, group='value')
  71. view_count = int_or_none(self._html_search_regex(
  72. r'(\d+) views\s*<', webpage, 'view count', fatal=False))
  73. thumbnail = self._search_regex(
  74. r"'poster'\s*:\s*'([^']+)'", webpage, 'thumbnail', fatal=False)
  75. return {
  76. 'id': video_id,
  77. 'display_id': display_id,
  78. 'title': title,
  79. 'description': description,
  80. 'thumbnail': thumbnail,
  81. 'view_count': view_count,
  82. 'formats': formats,
  83. 'age_limit': 18,
  84. }