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