]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/pornhd.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / pornhd.py
1 from .common import InfoExtractor
2 from ..utils import (
3 determine_ext,
4 ExtractorError,
5 int_or_none,
6 js_to_json,
7 merge_dicts,
8 urljoin,
9 )
10
11
12 class PornHdIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?pornhd\.com/(?:[a-z]{2,4}/)?videos/(?P<id>\d+)(?:/(?P<display_id>.+))?'
14 _TESTS = [{
15 'url': 'http://www.pornhd.com/videos/9864/selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
16 'md5': '87f1540746c1d32ec7a2305c12b96b25',
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',
23 'thumbnail': r're:^https?://.*\.jpg',
24 'view_count': int,
25 'like_count': int,
26 'age_limit': 18,
27 },
28 'skip': 'HTTP Error 404: Not Found',
29 }, {
30 'url': 'http://www.pornhd.com/videos/1962/sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
31 'md5': '1b7b3a40b9d65a8e5b25f7ab9ee6d6de',
32 'info_dict': {
33 'id': '1962',
34 'display_id': 'sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
35 'ext': 'mp4',
36 'title': 'md5:98c6f8b2d9c229d0f0fde47f61a1a759',
37 'description': 'md5:8ff0523848ac2b8f9b065ba781ccf294',
38 'thumbnail': r're:^https?://.*\.jpg',
39 'view_count': int,
40 'like_count': int,
41 'age_limit': 18,
42 },
43 }]
44
45 def _real_extract(self, url):
46 mobj = self._match_valid_url(url)
47 video_id = mobj.group('id')
48 display_id = mobj.group('display_id')
49
50 webpage = self._download_webpage(url, display_id or video_id)
51
52 title = self._html_search_regex(
53 [r'<span[^>]+class=["\']video-name["\'][^>]*>([^<]+)',
54 r'<title>(.+?) - .*?[Pp]ornHD.*?</title>'], webpage, 'title')
55
56 sources = self._parse_json(js_to_json(self._search_regex(
57 r"(?s)sources'?\s*[:=]\s*(\{.+?\})",
58 webpage, 'sources', default='{}')), video_id)
59
60 info = {}
61 if not sources:
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:
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
72 formats = []
73 for format_id, video_url in sources.items():
74 video_url = urljoin(url, video_url)
75 if not video_url:
76 continue
77 height = int_or_none(self._search_regex(
78 r'^(\d+)[pP]', format_id, 'height', default=None))
79 formats.append({
80 'url': video_url,
81 'ext': determine_ext(video_url, 'mp4'),
82 'format_id': format_id,
83 'height': height,
84 })
85 if formats:
86 info['formats'] = formats
87
88 description = self._html_search_regex(
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)
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(
97 r"poster'?\s*:\s*([\"'])(?P<url>(?:(?!\1).)+)\1", webpage,
98 'thumbnail', default=None, group='url')
99
100 like_count = int_or_none(self._search_regex(
101 (r'(\d+)</span>\s*likes',
102 r'(\d+)\s*</11[^>]+>(?:&nbsp;|\s)*\blikes',
103 r'class=["\']save-count["\'][^>]*>\s*(\d+)'),
104 webpage, 'like count', fatal=False))
105
106 return merge_dicts(info, {
107 'id': video_id,
108 'display_id': display_id,
109 'title': title,
110 'description': description,
111 'thumbnail': thumbnail,
112 'view_count': view_count,
113 'like_count': like_count,
114 'formats': formats,
115 'age_limit': 18,
116 })