]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | extract_attributes, | |
6 | int_or_none, | |
7 | str_to_int, | |
8 | unified_strdate, | |
9 | url_or_none, | |
10 | ) | |
11 | ||
12 | ||
13 | class YouPornIE(InfoExtractor): | |
14 | _VALID_URL = r'https?://(?:www\.)?youporn\.com/(?:watch|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?' | |
15 | _EMBED_REGEX = [r'<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//(?:www\.)?youporn\.com/embed/\d+)'] | |
16 | _TESTS = [{ | |
17 | 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/', | |
18 | 'md5': '3744d24c50438cf5b6f6d59feb5055c2', | |
19 | 'info_dict': { | |
20 | 'id': '505835', | |
21 | 'display_id': 'sex-ed-is-it-safe-to-masturbate-daily', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Sex Ed: Is It Safe To Masturbate Daily?', | |
24 | 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?', | |
25 | 'thumbnail': r're:^https?://.*\.jpg$', | |
26 | 'duration': 210, | |
27 | 'uploader': 'Ask Dan And Jennifer', | |
28 | 'upload_date': '20101217', | |
29 | 'average_rating': int, | |
30 | 'view_count': int, | |
31 | 'categories': list, | |
32 | 'tags': list, | |
33 | 'age_limit': 18, | |
34 | }, | |
35 | 'skip': 'This video has been disabled', | |
36 | }, { | |
37 | # Unknown uploader | |
38 | 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4', | |
39 | 'info_dict': { | |
40 | 'id': '561726', | |
41 | 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show', | |
42 | 'ext': 'mp4', | |
43 | 'title': 'Big Tits Awesome Brunette On amazing webcam show', | |
44 | 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4', | |
45 | 'thumbnail': r're:^https?://.*\.jpg$', | |
46 | 'uploader': 'Unknown', | |
47 | 'upload_date': '20110418', | |
48 | 'average_rating': int, | |
49 | 'view_count': int, | |
50 | 'categories': list, | |
51 | 'tags': list, | |
52 | 'age_limit': 18, | |
53 | }, | |
54 | 'params': { | |
55 | 'skip_download': True, | |
56 | }, | |
57 | 'skip': '404', | |
58 | }, { | |
59 | 'url': 'https://www.youporn.com/embed/505835/sex-ed-is-it-safe-to-masturbate-daily/', | |
60 | 'only_matching': True, | |
61 | }, { | |
62 | 'url': 'http://www.youporn.com/watch/505835', | |
63 | 'only_matching': True, | |
64 | }, { | |
65 | 'url': 'https://www.youporn.com/watch/13922959/femdom-principal/', | |
66 | 'only_matching': True, | |
67 | }] | |
68 | ||
69 | def _real_extract(self, url): | |
70 | mobj = self._match_valid_url(url) | |
71 | video_id = mobj.group('id') | |
72 | display_id = mobj.group('display_id') or video_id | |
73 | ||
74 | definitions = self._download_json( | |
75 | 'https://www.youporn.com/api/video/media_definitions/%s/' % video_id, | |
76 | display_id) | |
77 | ||
78 | formats = [] | |
79 | for definition in definitions: | |
80 | if not isinstance(definition, dict): | |
81 | continue | |
82 | video_url = url_or_none(definition.get('videoUrl')) | |
83 | if not video_url: | |
84 | continue | |
85 | f = { | |
86 | 'url': video_url, | |
87 | 'filesize': int_or_none(definition.get('videoSize')), | |
88 | } | |
89 | height = int_or_none(definition.get('quality')) | |
90 | # Video URL's path looks like this: | |
91 | # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 | |
92 | # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4 | |
93 | # /videos/201703/11/109285532/1080P_4000K_109285532.mp4 | |
94 | # We will benefit from it by extracting some metadata | |
95 | mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url) | |
96 | if mobj: | |
97 | if not height: | |
98 | height = int(mobj.group('height')) | |
99 | bitrate = int(mobj.group('bitrate')) | |
100 | f.update({ | |
101 | 'format_id': '%dp-%dk' % (height, bitrate), | |
102 | 'tbr': bitrate, | |
103 | }) | |
104 | f['height'] = height | |
105 | formats.append(f) | |
106 | ||
107 | webpage = self._download_webpage( | |
108 | 'http://www.youporn.com/watch/%s' % video_id, display_id, | |
109 | headers={'Cookie': 'age_verified=1'}) | |
110 | ||
111 | title = self._html_search_regex( | |
112 | r'(?s)<div[^>]+class=["\']watchVideoTitle[^>]+>(.+?)</div>', | |
113 | webpage, 'title', default=None) or self._og_search_title( | |
114 | webpage, default=None) or self._html_search_meta( | |
115 | 'title', webpage, fatal=True) | |
116 | ||
117 | description = self._html_search_regex( | |
118 | r'(?s)<div[^>]+\bid=["\']description["\'][^>]*>(.+?)</div>', | |
119 | webpage, 'description', | |
120 | default=None) or self._og_search_description( | |
121 | webpage, default=None) | |
122 | thumbnail = self._search_regex( | |
123 | r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P<thumbnail>.+?)\1', | |
124 | webpage, 'thumbnail', fatal=False, group='thumbnail') | |
125 | duration = int_or_none(self._html_search_meta( | |
126 | 'video:duration', webpage, 'duration', fatal=False)) | |
127 | ||
128 | uploader = self._html_search_regex( | |
129 | r'(?s)<div[^>]+class=["\']submitByLink["\'][^>]*>(.+?)</div>', | |
130 | webpage, 'uploader', fatal=False) | |
131 | upload_date = unified_strdate(self._html_search_regex( | |
132 | (r'UPLOADED:\s*<span>([^<]+)', | |
133 | r'Date\s+[Aa]dded:\s*<span>([^<]+)', | |
134 | r'''(?s)<div[^>]+class=["']videoInfo(?:Date|Time)\b[^>]*>(.+?)</div>''', | |
135 | r'(?s)<label\b[^>]*>Uploaded[^<]*</label>\s*<span\b[^>]*>(.+?)</span>'), | |
136 | webpage, 'upload date', fatal=False)) | |
137 | ||
138 | age_limit = self._rta_search(webpage) | |
139 | ||
140 | view_count = None | |
141 | views = self._search_regex( | |
142 | r'(<div[^>]+\bclass=["\']js_videoInfoViews["\']>)', webpage, | |
143 | 'views', default=None) | |
144 | if views: | |
145 | view_count = str_to_int(extract_attributes(views).get('data-value')) | |
146 | comment_count = str_to_int(self._search_regex( | |
147 | r'>All [Cc]omments? \(([\d,.]+)\)', | |
148 | webpage, 'comment count', default=None)) | |
149 | ||
150 | def extract_tag_box(regex, title): | |
151 | tag_box = self._search_regex(regex, webpage, title, default=None) | |
152 | if not tag_box: | |
153 | return [] | |
154 | return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box) | |
155 | ||
156 | categories = extract_tag_box( | |
157 | r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories') | |
158 | tags = extract_tag_box( | |
159 | r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent["\'][^>]*>(.+?)</div>', | |
160 | 'tags') | |
161 | ||
162 | return { | |
163 | 'id': video_id, | |
164 | 'display_id': display_id, | |
165 | 'title': title, | |
166 | 'description': description, | |
167 | 'thumbnail': thumbnail, | |
168 | 'duration': duration, | |
169 | 'uploader': uploader, | |
170 | 'upload_date': upload_date, | |
171 | 'view_count': view_count, | |
172 | 'comment_count': comment_count, | |
173 | 'categories': categories, | |
174 | 'tags': tags, | |
175 | 'age_limit': age_limit, | |
176 | 'formats': formats, | |
177 | } |