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