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