]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/fourtube.py
[extractor] Fix bug in 617f658b7ec1193749848c1b7343acab125dbc46
[yt-dlp.git] / yt_dlp / extractor / fourtube.py
1 import re
2
3 from .common import InfoExtractor
4 from ..compat import (
5 compat_b64decode,
6 compat_str,
7 compat_urllib_parse_unquote,
8 compat_urlparse,
9 )
10 from ..utils import (
11 int_or_none,
12 parse_duration,
13 parse_iso8601,
14 str_or_none,
15 str_to_int,
16 try_get,
17 unified_timestamp,
18 url_or_none,
19 )
20
21
22 class FourTubeBaseIE(InfoExtractor):
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
41 def _real_extract(self, url):
42 mobj = self._match_valid_url(url)
43 kind, video_id, display_id = mobj.group('kind', 'id', 'display_id')
44
45 if kind == 'm' or not display_id:
46 url = self._URL_TEMPLATE % video_id
47
48 webpage = self._download_webpage(url, video_id)
49
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(
55 r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/([^/"]+)" title="Go to [^"]+ page">',
56 webpage, 'uploader id', fatal=False)
57 uploader = self._html_search_regex(
58 r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/[^/"]+" title="Go to ([^"]+) page">',
59 webpage, 'uploader', fatal=False)
60
61 categories_html = self._search_regex(
62 r'(?s)><i class="icon icon-tag"></i>\s*Categories / Tags\s*.*?<ul class="[^"]*?list[^"]*?">(.*?)</ul>',
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)]
69
70 view_count = str_to_int(self._search_regex(
71 r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:([0-9,]+)">',
72 webpage, 'view count', default=None))
73 like_count = str_to_int(self._search_regex(
74 r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserLikes:([0-9,]+)">',
75 webpage, 'like count', default=None))
76 duration = parse_duration(self._html_search_meta('duration', webpage))
77
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]]
96
97 formats = self._extract_formats(url, video_id, media_id, sources)
98
99 return {
100 'id': video_id,
101 'title': title,
102 'formats': formats,
103 'categories': categories,
104 'thumbnail': thumbnail,
105 'uploader': uploader,
106 'uploader_id': uploader_id,
107 'timestamp': timestamp,
108 'like_count': like_count,
109 'view_count': view_count,
110 'duration': duration,
111 'age_limit': 18,
112 }
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'
119 _TKN_HOST = 'token.4tube.com'
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'
149 _TKN_HOST = 'token.fux.com'
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'
181 _TKN_HOST = 'tkn.porntube.com'
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',
189 'uploader_id': '91488',
190 'upload_date': '20150606',
191 'timestamp': 1433595647,
192 'duration': 5052,
193 'view_count': int,
194 'like_count': int,
195 'age_limit': 18,
196 },
197 'params': {
198 'skip_download': True,
199 },
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 },
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
228 def _real_extract(self, url):
229 mobj = self._match_valid_url(url)
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)
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))
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,
265 'uploader': uploader or channel,
266 'uploader_id': uploader_id or channel_id,
267 'channel': channel,
268 'channel_id': channel_id,
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
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'
281 _TKN_HOST = 'token.pornerbros.com'
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 }]