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