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