]>
Commit | Line | Data |
---|---|---|
03635e2a MK |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
15bf2ca0 S |
4 | from ..compat import ( |
5 | compat_b64decode, | |
6 | compat_str, | |
7 | compat_urllib_parse_unquote, | |
8 | compat_urlparse, | |
9 | ) | |
1cc79574 | 10 | from ..utils import ( |
15bf2ca0 | 11 | int_or_none, |
1cc79574 | 12 | parse_duration, |
9d22a7df | 13 | parse_iso8601, |
127103b6 | 14 | str_or_none, |
1cc79574 | 15 | str_to_int, |
15bf2ca0 S |
16 | try_get, |
17 | unified_timestamp, | |
18 | url_or_none, | |
ae6cae78 | 19 | ) |
ae6cae78 | 20 | |
03635e2a | 21 | |
b3c65153 | 22 | class FourTubeBaseIE(InfoExtractor): |
15bf2ca0 S |
23 | def _extract_formats(self, url, video_id, media_id, sources): |
24 | token_url = 'https://%s/%s/desktop/%s' % ( | |
25 | self._TKN_HOST, media_id, '+'.join(sources)) | |
26 | ||
27 | parsed_url = compat_urlparse.urlparse(url) | |
28 | tokens = self._download_json(token_url, video_id, data=b'', headers={ | |
29 | 'Origin': '%s://%s' % (parsed_url.scheme, parsed_url.hostname), | |
30 | 'Referer': url, | |
31 | }) | |
32 | formats = [{ | |
33 | 'url': tokens[format]['token'], | |
34 | 'format_id': format + 'p', | |
35 | 'resolution': format + 'p', | |
36 | 'quality': int(format), | |
37 | } for format in sources] | |
38 | self._sort_formats(formats) | |
39 | return formats | |
40 | ||
b3c65153 | 41 | def _real_extract(self, url): |
5ad28e7f | 42 | mobj = self._match_valid_url(url) |
b3c65153 | 43 | kind, video_id, display_id = mobj.group('kind', 'id', 'display_id') |
03635e2a | 44 | |
b3c65153 S |
45 | if kind == 'm' or not display_id: |
46 | url = self._URL_TEMPLATE % video_id | |
03635e2a | 47 | |
9d22a7df | 48 | webpage = self._download_webpage(url, video_id) |
03635e2a | 49 | |
9d22a7df PH |
50 | title = self._html_search_meta('name', webpage) |
51 | timestamp = parse_iso8601(self._html_search_meta( | |
52 | 'uploadDate', webpage)) | |
53 | thumbnail = self._html_search_meta('thumbnailUrl', webpage) | |
54 | uploader_id = self._html_search_regex( | |
b3c65153 | 55 | r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/([^/"]+)" title="Go to [^"]+ page">', |
c677e49b | 56 | webpage, 'uploader id', fatal=False) |
9d22a7df | 57 | uploader = self._html_search_regex( |
b3c65153 | 58 | r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/[^/"]+" title="Go to ([^"]+) page">', |
c677e49b | 59 | webpage, 'uploader', fatal=False) |
03635e2a | 60 | |
9d22a7df | 61 | categories_html = self._search_regex( |
77afa008 | 62 | r'(?s)><i class="icon icon-tag"></i>\s*Categories / Tags\s*.*?<ul class="[^"]*?list[^"]*?">(.*?)</ul>', |
9d22a7df PH |
63 | webpage, 'categories', fatal=False) |
64 | categories = None | |
65 | if categories_html: | |
66 | categories = [ | |
67 | c.strip() for c in re.findall( | |
68 | r'(?s)<li><a.*?>(.*?)</a>', categories_html)] | |
ae6cae78 | 69 | |
9d22a7df | 70 | view_count = str_to_int(self._search_regex( |
77afa008 | 71 | r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:([0-9,]+)">', |
b3c65153 | 72 | webpage, 'view count', default=None)) |
9d22a7df | 73 | like_count = str_to_int(self._search_regex( |
77afa008 | 74 | r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserLikes:([0-9,]+)">', |
b3c65153 | 75 | webpage, 'like count', default=None)) |
9d22a7df | 76 | duration = parse_duration(self._html_search_meta('duration', webpage)) |
ae6cae78 | 77 | |
4356d907 S |
78 | media_id = self._search_regex( |
79 | r'<button[^>]+data-id=(["\'])(?P<id>\d+)\1[^>]+data-quality=', webpage, | |
80 | 'media id', default=None, group='id') | |
81 | sources = [ | |
82 | quality | |
83 | for _, quality in re.findall(r'<button[^>]+data-quality=(["\'])(.+?)\1', webpage)] | |
84 | if not (media_id and sources): | |
85 | player_js = self._download_webpage( | |
86 | self._search_regex( | |
87 | r'<script[^>]id=(["\'])playerembed\1[^>]+src=(["\'])(?P<url>.+?)\2', | |
88 | webpage, 'player JS', group='url'), | |
89 | video_id, 'Downloading player JS') | |
90 | params_js = self._search_regex( | |
91 | r'\$\.ajax\(url,\ opts\);\s*\}\s*\}\)\(([0-9,\[\] ]+)\)', | |
92 | player_js, 'initialization parameters') | |
93 | params = self._parse_json('[%s]' % params_js, video_id) | |
94 | media_id = params[0] | |
95 | sources = ['%s' % p for p in params[2]] | |
03635e2a | 96 | |
15bf2ca0 | 97 | formats = self._extract_formats(url, video_id, media_id, sources) |
ae6cae78 S |
98 | |
99 | return { | |
03635e2a MK |
100 | 'id': video_id, |
101 | 'title': title, | |
102 | 'formats': formats, | |
9d22a7df PH |
103 | 'categories': categories, |
104 | 'thumbnail': thumbnail, | |
ae6cae78 S |
105 | 'uploader': uploader, |
106 | 'uploader_id': uploader_id, | |
9d22a7df PH |
107 | 'timestamp': timestamp, |
108 | 'like_count': like_count, | |
ae6cae78 S |
109 | 'view_count': view_count, |
110 | 'duration': duration, | |
03635e2a | 111 | 'age_limit': 18, |
5f6a1245 | 112 | } |
b3c65153 S |
113 | |
114 | ||
115 | class FourTubeIE(FourTubeBaseIE): | |
116 | IE_NAME = '4tube' | |
117 | _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?4tube\.com/(?:videos|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?' | |
118 | _URL_TEMPLATE = 'https://www.4tube.com/videos/%s/video' | |
c9856648 | 119 | _TKN_HOST = 'token.4tube.com' |
b3c65153 S |
120 | _TESTS = [{ |
121 | 'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black', | |
122 | 'md5': '6516c8ac63b03de06bc8eac14362db4f', | |
123 | 'info_dict': { | |
124 | 'id': '209733', | |
125 | 'ext': 'mp4', | |
126 | 'title': 'Hot Babe Holly Michaels gets her ass stuffed by black', | |
127 | 'uploader': 'WCP Club', | |
128 | 'uploader_id': 'wcp-club', | |
129 | 'upload_date': '20131031', | |
130 | 'timestamp': 1383263892, | |
131 | 'duration': 583, | |
132 | 'view_count': int, | |
133 | 'like_count': int, | |
134 | 'categories': list, | |
135 | 'age_limit': 18, | |
136 | }, | |
137 | }, { | |
138 | 'url': 'http://www.4tube.com/embed/209733', | |
139 | 'only_matching': True, | |
140 | }, { | |
141 | 'url': 'http://m.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black', | |
142 | 'only_matching': True, | |
143 | }] | |
144 | ||
145 | ||
146 | class FuxIE(FourTubeBaseIE): | |
147 | _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?fux\.com/(?:video|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?' | |
148 | _URL_TEMPLATE = 'https://www.fux.com/video/%s/video' | |
c9856648 | 149 | _TKN_HOST = 'token.fux.com' |
b3c65153 S |
150 | _TESTS = [{ |
151 | 'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow', | |
152 | 'info_dict': { | |
153 | 'id': '195359', | |
154 | 'ext': 'mp4', | |
155 | 'title': 'Awesome fucking in the kitchen ends with cum swallow', | |
156 | 'uploader': 'alenci2342', | |
157 | 'uploader_id': 'alenci2342', | |
158 | 'upload_date': '20131230', | |
159 | 'timestamp': 1388361660, | |
160 | 'duration': 289, | |
161 | 'view_count': int, | |
162 | 'like_count': int, | |
163 | 'categories': list, | |
164 | 'age_limit': 18, | |
165 | }, | |
166 | 'params': { | |
167 | 'skip_download': True, | |
168 | }, | |
169 | }, { | |
170 | 'url': 'https://www.fux.com/embed/195359', | |
171 | 'only_matching': True, | |
172 | }, { | |
173 | 'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow', | |
174 | 'only_matching': True, | |
175 | }] | |
176 | ||
177 | ||
178 | class PornTubeIE(FourTubeBaseIE): | |
179 | _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?porntube\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)' | |
180 | _URL_TEMPLATE = 'https://www.porntube.com/videos/video_%s' | |
15bf2ca0 | 181 | _TKN_HOST = 'tkn.porntube.com' |
b3c65153 S |
182 | _TESTS = [{ |
183 | 'url': 'https://www.porntube.com/videos/teen-couple-doing-anal_7089759', | |
184 | 'info_dict': { | |
185 | 'id': '7089759', | |
186 | 'ext': 'mp4', | |
187 | 'title': 'Teen couple doing anal', | |
188 | 'uploader': 'Alexy', | |
15bf2ca0 | 189 | 'uploader_id': '91488', |
b3c65153 S |
190 | 'upload_date': '20150606', |
191 | 'timestamp': 1433595647, | |
192 | 'duration': 5052, | |
193 | 'view_count': int, | |
194 | 'like_count': int, | |
b3c65153 S |
195 | 'age_limit': 18, |
196 | }, | |
197 | 'params': { | |
198 | 'skip_download': True, | |
199 | }, | |
127103b6 S |
200 | }, { |
201 | 'url': 'https://www.porntube.com/videos/squirting-teen-ballerina-ecg_1331406', | |
202 | 'info_dict': { | |
203 | 'id': '1331406', | |
204 | 'ext': 'mp4', | |
205 | 'title': 'Squirting Teen Ballerina on ECG', | |
206 | 'uploader': 'Exploited College Girls', | |
207 | 'uploader_id': '665', | |
208 | 'channel': 'Exploited College Girls', | |
209 | 'channel_id': '665', | |
210 | 'upload_date': '20130920', | |
211 | 'timestamp': 1379685485, | |
212 | 'duration': 851, | |
213 | 'view_count': int, | |
214 | 'like_count': int, | |
215 | 'age_limit': 18, | |
216 | }, | |
217 | 'params': { | |
218 | 'skip_download': True, | |
219 | }, | |
b3c65153 S |
220 | }, { |
221 | 'url': 'https://www.porntube.com/embed/7089759', | |
222 | 'only_matching': True, | |
223 | }, { | |
224 | 'url': 'https://m.porntube.com/videos/teen-couple-doing-anal_7089759', | |
225 | 'only_matching': True, | |
226 | }] | |
227 | ||
15bf2ca0 | 228 | def _real_extract(self, url): |
5ad28e7f | 229 | mobj = self._match_valid_url(url) |
15bf2ca0 S |
230 | video_id, display_id = mobj.group('id', 'display_id') |
231 | ||
232 | webpage = self._download_webpage(url, display_id) | |
233 | ||
234 | video = self._parse_json( | |
235 | self._search_regex( | |
236 | r'INITIALSTATE\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1', | |
237 | webpage, 'data', group='value'), video_id, | |
238 | transform_source=lambda x: compat_urllib_parse_unquote( | |
239 | compat_b64decode(x).decode('utf-8')))['page']['video'] | |
240 | ||
241 | title = video['title'] | |
242 | media_id = video['mediaId'] | |
243 | sources = [compat_str(e['height']) | |
244 | for e in video['encodings'] if e.get('height')] | |
245 | formats = self._extract_formats(url, video_id, media_id, sources) | |
246 | ||
247 | thumbnail = url_or_none(video.get('masterThumb')) | |
248 | uploader = try_get(video, lambda x: x['user']['username'], compat_str) | |
127103b6 S |
249 | uploader_id = str_or_none(try_get( |
250 | video, lambda x: x['user']['id'], int)) | |
251 | channel = try_get(video, lambda x: x['channel']['name'], compat_str) | |
252 | channel_id = str_or_none(try_get( | |
253 | video, lambda x: x['channel']['id'], int)) | |
15bf2ca0 S |
254 | like_count = int_or_none(video.get('likes')) |
255 | dislike_count = int_or_none(video.get('dislikes')) | |
256 | view_count = int_or_none(video.get('playsQty')) | |
257 | duration = int_or_none(video.get('durationInSeconds')) | |
258 | timestamp = unified_timestamp(video.get('publishedAt')) | |
259 | ||
260 | return { | |
261 | 'id': video_id, | |
262 | 'title': title, | |
263 | 'formats': formats, | |
264 | 'thumbnail': thumbnail, | |
127103b6 S |
265 | 'uploader': uploader or channel, |
266 | 'uploader_id': uploader_id or channel_id, | |
267 | 'channel': channel, | |
268 | 'channel_id': channel_id, | |
15bf2ca0 S |
269 | 'timestamp': timestamp, |
270 | 'like_count': like_count, | |
271 | 'dislike_count': dislike_count, | |
272 | 'view_count': view_count, | |
273 | 'duration': duration, | |
274 | 'age_limit': 18, | |
275 | } | |
276 | ||
b3c65153 S |
277 | |
278 | class PornerBrosIE(FourTubeBaseIE): | |
279 | _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?pornerbros\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)' | |
280 | _URL_TEMPLATE = 'https://www.pornerbros.com/videos/video_%s' | |
c9856648 | 281 | _TKN_HOST = 'token.pornerbros.com' |
b3c65153 S |
282 | _TESTS = [{ |
283 | 'url': 'https://www.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369', | |
284 | 'md5': '6516c8ac63b03de06bc8eac14362db4f', | |
285 | 'info_dict': { | |
286 | 'id': '181369', | |
287 | 'ext': 'mp4', | |
288 | 'title': 'Skinny brunette takes big cock down her anal hole', | |
289 | 'uploader': 'PornerBros HD', | |
290 | 'uploader_id': 'pornerbros-hd', | |
291 | 'upload_date': '20130130', | |
292 | 'timestamp': 1359527401, | |
293 | 'duration': 1224, | |
294 | 'view_count': int, | |
295 | 'categories': list, | |
296 | 'age_limit': 18, | |
297 | }, | |
298 | 'params': { | |
299 | 'skip_download': True, | |
300 | }, | |
301 | }, { | |
302 | 'url': 'https://www.pornerbros.com/embed/181369', | |
303 | 'only_matching': True, | |
304 | }, { | |
305 | 'url': 'https://m.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369', | |
306 | 'only_matching': True, | |
307 | }] |