]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/fourtube.py
[hidive] add support for authentication(closes #16534)
[youtube-dl.git] / 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 compat_urlparse
7 from ..utils import (
8     parse_duration,
9     parse_iso8601,
10     str_to_int,
11 )
12
13
14 class FourTubeBaseIE(InfoExtractor):
15     def _real_extract(self, url):
16         mobj = re.match(self._VALID_URL, url)
17         kind, video_id, display_id = mobj.group('kind', 'id', 'display_id')
18
19         if kind == 'm' or not display_id:
20             url = self._URL_TEMPLATE % video_id
21
22         webpage = self._download_webpage(url, video_id)
23
24         title = self._html_search_meta('name', webpage)
25         timestamp = parse_iso8601(self._html_search_meta(
26             'uploadDate', webpage))
27         thumbnail = self._html_search_meta('thumbnailUrl', webpage)
28         uploader_id = self._html_search_regex(
29             r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/([^/"]+)" title="Go to [^"]+ page">',
30             webpage, 'uploader id', fatal=False)
31         uploader = self._html_search_regex(
32             r'<a class="item-to-subscribe" href="[^"]+/(?:channel|user)s?/[^/"]+" title="Go to ([^"]+) page">',
33             webpage, 'uploader', fatal=False)
34
35         categories_html = self._search_regex(
36             r'(?s)><i class="icon icon-tag"></i>\s*Categories / Tags\s*.*?<ul class="[^"]*?list[^"]*?">(.*?)</ul>',
37             webpage, 'categories', fatal=False)
38         categories = None
39         if categories_html:
40             categories = [
41                 c.strip() for c in re.findall(
42                     r'(?s)<li><a.*?>(.*?)</a>', categories_html)]
43
44         view_count = str_to_int(self._search_regex(
45             r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserPlays:([0-9,]+)">',
46             webpage, 'view count', default=None))
47         like_count = str_to_int(self._search_regex(
48             r'<meta[^>]+itemprop="interactionCount"[^>]+content="UserLikes:([0-9,]+)">',
49             webpage, 'like count', default=None))
50         duration = parse_duration(self._html_search_meta('duration', webpage))
51
52         media_id = self._search_regex(
53             r'<button[^>]+data-id=(["\'])(?P<id>\d+)\1[^>]+data-quality=', webpage,
54             'media id', default=None, group='id')
55         sources = [
56             quality
57             for _, quality in re.findall(r'<button[^>]+data-quality=(["\'])(.+?)\1', webpage)]
58         if not (media_id and sources):
59             player_js = self._download_webpage(
60                 self._search_regex(
61                     r'<script[^>]id=(["\'])playerembed\1[^>]+src=(["\'])(?P<url>.+?)\2',
62                     webpage, 'player JS', group='url'),
63                 video_id, 'Downloading player JS')
64             params_js = self._search_regex(
65                 r'\$\.ajax\(url,\ opts\);\s*\}\s*\}\)\(([0-9,\[\] ]+)\)',
66                 player_js, 'initialization parameters')
67             params = self._parse_json('[%s]' % params_js, video_id)
68             media_id = params[0]
69             sources = ['%s' % p for p in params[2]]
70
71         token_url = 'https://tkn.kodicdn.com/{0}/desktop/{1}'.format(
72             media_id, '+'.join(sources))
73
74         parsed_url = compat_urlparse.urlparse(url)
75         tokens = self._download_json(token_url, video_id, data=b'', headers={
76             'Origin': '%s://%s' % (parsed_url.scheme, parsed_url.hostname),
77             'Referer': url,
78         })
79         formats = [{
80             'url': tokens[format]['token'],
81             'format_id': format + 'p',
82             'resolution': format + 'p',
83             'quality': int(format),
84         } for format in sources]
85         self._sort_formats(formats)
86
87         return {
88             'id': video_id,
89             'title': title,
90             'formats': formats,
91             'categories': categories,
92             'thumbnail': thumbnail,
93             'uploader': uploader,
94             'uploader_id': uploader_id,
95             'timestamp': timestamp,
96             'like_count': like_count,
97             'view_count': view_count,
98             'duration': duration,
99             'age_limit': 18,
100         }
101
102
103 class FourTubeIE(FourTubeBaseIE):
104     IE_NAME = '4tube'
105     _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?4tube\.com/(?:videos|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
106     _URL_TEMPLATE = 'https://www.4tube.com/videos/%s/video'
107     _TESTS = [{
108         'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
109         'md5': '6516c8ac63b03de06bc8eac14362db4f',
110         'info_dict': {
111             'id': '209733',
112             'ext': 'mp4',
113             'title': 'Hot Babe Holly Michaels gets her ass stuffed by black',
114             'uploader': 'WCP Club',
115             'uploader_id': 'wcp-club',
116             'upload_date': '20131031',
117             'timestamp': 1383263892,
118             'duration': 583,
119             'view_count': int,
120             'like_count': int,
121             'categories': list,
122             'age_limit': 18,
123         },
124     }, {
125         'url': 'http://www.4tube.com/embed/209733',
126         'only_matching': True,
127     }, {
128         'url': 'http://m.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
129         'only_matching': True,
130     }]
131
132
133 class FuxIE(FourTubeBaseIE):
134     _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?fux\.com/(?:video|embed)/(?P<id>\d+)(?:/(?P<display_id>[^/?#&]+))?'
135     _URL_TEMPLATE = 'https://www.fux.com/video/%s/video'
136     _TESTS = [{
137         'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow',
138         'info_dict': {
139             'id': '195359',
140             'ext': 'mp4',
141             'title': 'Awesome fucking in the kitchen ends with cum swallow',
142             'uploader': 'alenci2342',
143             'uploader_id': 'alenci2342',
144             'upload_date': '20131230',
145             'timestamp': 1388361660,
146             'duration': 289,
147             'view_count': int,
148             'like_count': int,
149             'categories': list,
150             'age_limit': 18,
151         },
152         'params': {
153             'skip_download': True,
154         },
155     }, {
156         'url': 'https://www.fux.com/embed/195359',
157         'only_matching': True,
158     }, {
159         'url': 'https://www.fux.com/video/195359/awesome-fucking-kitchen-ends-cum-swallow',
160         'only_matching': True,
161     }]
162
163
164 class PornTubeIE(FourTubeBaseIE):
165     _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?porntube\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)'
166     _URL_TEMPLATE = 'https://www.porntube.com/videos/video_%s'
167     _TESTS = [{
168         'url': 'https://www.porntube.com/videos/teen-couple-doing-anal_7089759',
169         'info_dict': {
170             'id': '7089759',
171             'ext': 'mp4',
172             'title': 'Teen couple doing anal',
173             'uploader': 'Alexy',
174             'uploader_id': 'Alexy',
175             'upload_date': '20150606',
176             'timestamp': 1433595647,
177             'duration': 5052,
178             'view_count': int,
179             'like_count': int,
180             'categories': list,
181             'age_limit': 18,
182         },
183         'params': {
184             'skip_download': True,
185         },
186     }, {
187         'url': 'https://www.porntube.com/embed/7089759',
188         'only_matching': True,
189     }, {
190         'url': 'https://m.porntube.com/videos/teen-couple-doing-anal_7089759',
191         'only_matching': True,
192     }]
193
194
195 class PornerBrosIE(FourTubeBaseIE):
196     _VALID_URL = r'https?://(?:(?P<kind>www|m)\.)?pornerbros\.com/(?:videos/(?P<display_id>[^/]+)_|embed/)(?P<id>\d+)'
197     _URL_TEMPLATE = 'https://www.pornerbros.com/videos/video_%s'
198     _TESTS = [{
199         'url': 'https://www.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369',
200         'md5': '6516c8ac63b03de06bc8eac14362db4f',
201         'info_dict': {
202             'id': '181369',
203             'ext': 'mp4',
204             'title': 'Skinny brunette takes big cock down her anal hole',
205             'uploader': 'PornerBros HD',
206             'uploader_id': 'pornerbros-hd',
207             'upload_date': '20130130',
208             'timestamp': 1359527401,
209             'duration': 1224,
210             'view_count': int,
211             'categories': list,
212             'age_limit': 18,
213         },
214         'params': {
215             'skip_download': True,
216         },
217     }, {
218         'url': 'https://www.pornerbros.com/embed/181369',
219         'only_matching': True,
220     }, {
221         'url': 'https://m.pornerbros.com/videos/skinny-brunette-takes-big-cock-down-her-anal-hole_181369',
222         'only_matching': True,
223     }]