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