]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tnaflix.py
debian/control: Mark compliance with policy 4.1.1. No further changes needed.
[youtubedl] / youtube_dl / extractor / tnaflix.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import compat_str
7 from ..utils import (
8 fix_xml_ampersands,
9 float_or_none,
10 int_or_none,
11 parse_duration,
12 str_to_int,
13 unescapeHTML,
14 xpath_text,
15 )
16
17
18 class TNAFlixNetworkBaseIE(InfoExtractor):
19 # May be overridden in descendants if necessary
20 _CONFIG_REGEX = [
21 r'flashvars\.config\s*=\s*escape\("([^"]+)"',
22 r'<input[^>]+name="config\d?" value="([^"]+)"',
23 ]
24 _TITLE_REGEX = r'<input[^>]+name="title" value="([^"]+)"'
25 _DESCRIPTION_REGEX = r'<input[^>]+name="description" value="([^"]+)"'
26 _UPLOADER_REGEX = r'<input[^>]+name="username" value="([^"]+)"'
27 _VIEW_COUNT_REGEX = None
28 _COMMENT_COUNT_REGEX = None
29 _AVERAGE_RATING_REGEX = None
30 _CATEGORIES_REGEX = r'<li[^>]*>\s*<span[^>]+class="infoTitle"[^>]*>Categories:</span>\s*<span[^>]+class="listView"[^>]*>(.+?)</span>\s*</li>'
31
32 def _extract_thumbnails(self, flix_xml):
33
34 def get_child(elem, names):
35 for name in names:
36 child = elem.find(name)
37 if child is not None:
38 return child
39
40 timeline = get_child(flix_xml, ['timeline', 'rolloverBarImage'])
41 if timeline is None:
42 return
43
44 pattern_el = get_child(timeline, ['imagePattern', 'pattern'])
45 if pattern_el is None or not pattern_el.text:
46 return
47
48 first_el = get_child(timeline, ['imageFirst', 'first'])
49 last_el = get_child(timeline, ['imageLast', 'last'])
50 if first_el is None or last_el is None:
51 return
52
53 first_text = first_el.text
54 last_text = last_el.text
55 if not first_text.isdigit() or not last_text.isdigit():
56 return
57
58 first = int(first_text)
59 last = int(last_text)
60 if first > last:
61 return
62
63 width = int_or_none(xpath_text(timeline, './imageWidth', 'thumbnail width'))
64 height = int_or_none(xpath_text(timeline, './imageHeight', 'thumbnail height'))
65
66 return [{
67 'url': self._proto_relative_url(pattern_el.text.replace('#', compat_str(i)), 'http:'),
68 'width': width,
69 'height': height,
70 } for i in range(first, last + 1)]
71
72 def _real_extract(self, url):
73 mobj = re.match(self._VALID_URL, url)
74 video_id = mobj.group('id')
75 display_id = mobj.group('display_id') if 'display_id' in mobj.groupdict() else video_id
76
77 webpage = self._download_webpage(url, display_id)
78
79 cfg_url = self._proto_relative_url(self._html_search_regex(
80 self._CONFIG_REGEX, webpage, 'flashvars.config', default=None), 'http:')
81
82 if not cfg_url:
83 inputs = self._hidden_inputs(webpage)
84 cfg_url = ('https://cdn-fck.tnaflix.com/tnaflix/%s.fid?key=%s&VID=%s&premium=1&vip=1&alpha'
85 % (inputs['vkey'], inputs['nkey'], video_id))
86
87 cfg_xml = self._download_xml(
88 cfg_url, display_id, 'Downloading metadata',
89 transform_source=fix_xml_ampersands)
90
91 formats = []
92
93 def extract_video_url(vl):
94 return re.sub(r'speed=\d+', 'speed=', unescapeHTML(vl.text))
95
96 video_link = cfg_xml.find('./videoLink')
97 if video_link is not None:
98 formats.append({
99 'url': extract_video_url(video_link),
100 'ext': xpath_text(cfg_xml, './videoConfig/type', 'type', default='flv'),
101 })
102
103 for item in cfg_xml.findall('./quality/item'):
104 video_link = item.find('./videoLink')
105 if video_link is None:
106 continue
107 res = item.find('res')
108 format_id = None if res is None else res.text
109 height = int_or_none(self._search_regex(
110 r'^(\d+)[pP]', format_id, 'height', default=None))
111 formats.append({
112 'url': self._proto_relative_url(extract_video_url(video_link), 'http:'),
113 'format_id': format_id,
114 'height': height,
115 })
116
117 self._sort_formats(formats)
118
119 thumbnail = self._proto_relative_url(
120 xpath_text(cfg_xml, './startThumb', 'thumbnail'), 'http:')
121 thumbnails = self._extract_thumbnails(cfg_xml)
122
123 title = None
124 if self._TITLE_REGEX:
125 title = self._html_search_regex(
126 self._TITLE_REGEX, webpage, 'title', default=None)
127 if not title:
128 title = self._og_search_title(webpage)
129
130 age_limit = self._rta_search(webpage) or 18
131
132 duration = parse_duration(self._html_search_meta(
133 'duration', webpage, 'duration', default=None))
134
135 def extract_field(pattern, name):
136 return self._html_search_regex(pattern, webpage, name, default=None) if pattern else None
137
138 description = extract_field(self._DESCRIPTION_REGEX, 'description')
139 uploader = extract_field(self._UPLOADER_REGEX, 'uploader')
140 view_count = str_to_int(extract_field(self._VIEW_COUNT_REGEX, 'view count'))
141 comment_count = str_to_int(extract_field(self._COMMENT_COUNT_REGEX, 'comment count'))
142 average_rating = float_or_none(extract_field(self._AVERAGE_RATING_REGEX, 'average rating'))
143
144 categories_str = extract_field(self._CATEGORIES_REGEX, 'categories')
145 categories = [c.strip() for c in categories_str.split(',')] if categories_str is not None else []
146
147 return {
148 'id': video_id,
149 'display_id': display_id,
150 'title': title,
151 'description': description,
152 'thumbnail': thumbnail,
153 'thumbnails': thumbnails,
154 'duration': duration,
155 'age_limit': age_limit,
156 'uploader': uploader,
157 'view_count': view_count,
158 'comment_count': comment_count,
159 'average_rating': average_rating,
160 'categories': categories,
161 'formats': formats,
162 }
163
164
165 class TNAFlixNetworkEmbedIE(TNAFlixNetworkBaseIE):
166 _VALID_URL = r'https?://player\.(?:tna|emp)flix\.com/video/(?P<id>\d+)'
167
168 _TITLE_REGEX = r'<title>([^<]+)</title>'
169
170 _TESTS = [{
171 'url': 'https://player.tnaflix.com/video/6538',
172 'info_dict': {
173 'id': '6538',
174 'display_id': '6538',
175 'ext': 'mp4',
176 'title': 'Educational xxx video',
177 'thumbnail': r're:https?://.*\.jpg$',
178 'age_limit': 18,
179 },
180 'params': {
181 'skip_download': True,
182 },
183 }, {
184 'url': 'https://player.empflix.com/video/33051',
185 'only_matching': True,
186 }]
187
188 @staticmethod
189 def _extract_urls(webpage):
190 return [url for _, url in re.findall(
191 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.(?:tna|emp)flix\.com/video/\d+)\1',
192 webpage)]
193
194
195 class TNAFlixIE(TNAFlixNetworkBaseIE):
196 _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/[^/]+/(?P<display_id>[^/]+)/video(?P<id>\d+)'
197
198 _TITLE_REGEX = r'<title>(.+?) - (?:TNAFlix Porn Videos|TNAFlix\.com)</title>'
199 _DESCRIPTION_REGEX = r'(?s)>Description:</[^>]+>(.+?)<'
200 _UPLOADER_REGEX = r'<i>\s*Verified Member\s*</i>\s*<h\d+>(.+?)<'
201 _CATEGORIES_REGEX = r'(?s)<span[^>]*>Categories:</span>(.+?)</div>'
202
203 _TESTS = [{
204 # anonymous uploader, no categories
205 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878',
206 'md5': 'ecf3498417d09216374fc5907f9c6ec0',
207 'info_dict': {
208 'id': '553878',
209 'display_id': 'Carmella-Decesare-striptease',
210 'ext': 'mp4',
211 'title': 'Carmella Decesare - striptease',
212 'thumbnail': r're:https?://.*\.jpg$',
213 'duration': 91,
214 'age_limit': 18,
215 'categories': ['Porn Stars'],
216 }
217 }, {
218 # non-anonymous uploader, categories
219 'url': 'https://www.tnaflix.com/teen-porn/Educational-xxx-video/video6538',
220 'md5': '0f5d4d490dbfd117b8607054248a07c0',
221 'info_dict': {
222 'id': '6538',
223 'display_id': 'Educational-xxx-video',
224 'ext': 'mp4',
225 'title': 'Educational xxx video',
226 'description': 'md5:b4fab8f88a8621c8fabd361a173fe5b8',
227 'thumbnail': r're:https?://.*\.jpg$',
228 'duration': 164,
229 'age_limit': 18,
230 'uploader': 'bobwhite39',
231 'categories': ['Amateur Porn', 'Squirting Videos', 'Teen Girls 18+'],
232 }
233 }, {
234 'url': 'https://www.tnaflix.com/amateur-porn/bunzHD-Ms.Donk/video358632',
235 'only_matching': True,
236 }]
237
238
239 class EMPFlixIE(TNAFlixNetworkBaseIE):
240 _VALID_URL = r'https?://(?:www\.)?empflix\.com/videos/(?P<display_id>.+?)-(?P<id>[0-9]+)\.html'
241
242 _UPLOADER_REGEX = r'<span[^>]+class="infoTitle"[^>]*>Uploaded By:</span>(.+?)</li>'
243
244 _TESTS = [{
245 'url': 'http://www.empflix.com/videos/Amateur-Finger-Fuck-33051.html',
246 'md5': 'b1bc15b6412d33902d6e5952035fcabc',
247 'info_dict': {
248 'id': '33051',
249 'display_id': 'Amateur-Finger-Fuck',
250 'ext': 'mp4',
251 'title': 'Amateur Finger Fuck',
252 'description': 'Amateur solo finger fucking.',
253 'thumbnail': r're:https?://.*\.jpg$',
254 'duration': 83,
255 'age_limit': 18,
256 'uploader': 'cwbike',
257 'categories': ['Amateur', 'Anal', 'Fisting', 'Home made', 'Solo'],
258 }
259 }, {
260 'url': 'http://www.empflix.com/videos/[AROMA][ARMD-718]-Aoi-Yoshino-Sawa-25826.html',
261 'only_matching': True,
262 }]
263
264
265 class MovieFapIE(TNAFlixNetworkBaseIE):
266 _VALID_URL = r'https?://(?:www\.)?moviefap\.com/videos/(?P<id>[0-9a-f]+)/(?P<display_id>[^/]+)\.html'
267
268 _VIEW_COUNT_REGEX = r'<br>Views\s*<strong>([\d,.]+)</strong>'
269 _COMMENT_COUNT_REGEX = r'<span[^>]+id="comCount"[^>]*>([\d,.]+)</span>'
270 _AVERAGE_RATING_REGEX = r'Current Rating\s*<br>\s*<strong>([\d.]+)</strong>'
271 _CATEGORIES_REGEX = r'(?s)<div[^>]+id="vid_info"[^>]*>\s*<div[^>]*>.+?</div>(.*?)<br>'
272
273 _TESTS = [{
274 # normal, multi-format video
275 'url': 'http://www.moviefap.com/videos/be9867c9416c19f54a4a/experienced-milf-amazing-handjob.html',
276 'md5': '26624b4e2523051b550067d547615906',
277 'info_dict': {
278 'id': 'be9867c9416c19f54a4a',
279 'display_id': 'experienced-milf-amazing-handjob',
280 'ext': 'mp4',
281 'title': 'Experienced MILF Amazing Handjob',
282 'description': 'Experienced MILF giving an Amazing Handjob',
283 'thumbnail': r're:https?://.*\.jpg$',
284 'age_limit': 18,
285 'uploader': 'darvinfred06',
286 'view_count': int,
287 'comment_count': int,
288 'average_rating': float,
289 'categories': ['Amateur', 'Masturbation', 'Mature', 'Flashing'],
290 }
291 }, {
292 # quirky single-format case where the extension is given as fid, but the video is really an flv
293 'url': 'http://www.moviefap.com/videos/e5da0d3edce5404418f5/jeune-couple-russe.html',
294 'md5': 'fa56683e291fc80635907168a743c9ad',
295 'info_dict': {
296 'id': 'e5da0d3edce5404418f5',
297 'display_id': 'jeune-couple-russe',
298 'ext': 'flv',
299 'title': 'Jeune Couple Russe',
300 'description': 'Amateur',
301 'thumbnail': r're:https?://.*\.jpg$',
302 'age_limit': 18,
303 'uploader': 'whiskeyjar',
304 'view_count': int,
305 'comment_count': int,
306 'average_rating': float,
307 'categories': ['Amateur', 'Teen'],
308 }
309 }]