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