]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/xhamster.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
25 class XHamsterIE(InfoExtractor
):
26 _DOMAINS
= r
'(?:xhamster\.(?:com|one|desi)|xhms\.pro|xhamster\d+\.com)'
31 movies/(?P<id>[\dA-Za-z]+)/(?P<display_id>[^/]*)\.html|
32 videos/(?P<display_id_2>[^/]*)-(?P<id_2>[\dA-Za-z]+)
36 'url': 'https://xhamster.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
37 'md5': '98b4687efb1ffd331c4197854dc09e8f',
40 'display_id': 'femaleagent-shy-beauty-takes-the-bait',
42 'title': 'FemaleAgent Shy beauty takes the bait',
43 'timestamp': 1350194821,
44 'upload_date': '20121014',
45 'uploader': 'Ruseful2011',
50 'url': 'https://xhamster.com/videos/britney-spears-sexy-booty-2221348?hd=',
53 'display_id': 'britney-spears-sexy-booty',
55 'title': 'Britney Spears Sexy Booty',
56 'timestamp': 1379123460,
57 'upload_date': '20130914',
58 'uploader': 'jojo747400',
63 'skip_download': True,
66 # empty seo, unavailable via new URL schema
67 'url': 'http://xhamster.com/movies/5667973/.html',
72 'timestamp': 1454948101,
73 'upload_date': '20160208',
74 'uploader': 'parejafree',
79 'skip_download': True,
83 'url': 'https://m.xhamster.com/videos/cute-teen-jacqueline-solo-masturbation-8559111',
84 'only_matching': True,
86 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
87 'only_matching': True,
89 # This video is visible for marcoalfa123456's friends only
90 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
91 'only_matching': True,
94 'url': 'https://pt.xhamster.com/videos/euro-pedal-pumping-7937821',
95 'only_matching': True,
97 'url': 'https://xhamster.one/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
98 'only_matching': True,
100 'url': 'https://xhamster.desi/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
101 'only_matching': True,
103 'url': 'https://xhamster2.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
104 'only_matching': True,
106 'url': 'https://xhamster11.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
107 'only_matching': True,
109 'url': 'https://xhamster26.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
110 'only_matching': True,
112 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
113 'only_matching': True,
115 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
116 'only_matching': True,
118 'url': 'http://de.xhamster.com/videos/skinny-girl-fucks-herself-hard-in-the-forest-xhnBJZx',
119 'only_matching': True,
122 def _real_extract(self
, url
):
123 mobj
= self
._match
_valid
_url
(url
)
124 video_id
= mobj
.group('id') or mobj
.group('id_2')
125 display_id
= mobj
.group('display_id') or mobj
.group('display_id_2')
127 desktop_url
= re
.sub(r
'^(https?://(?:.+?\.)?)m\.', r
'\1', url
)
128 webpage
, urlh
= self
._download
_webpage
_handle
(desktop_url
, video_id
)
130 error
= self
._html
_search
_regex
(
131 r
'<div[^>]+id=["\']videoClosed
["\'][^>]*>(.+?)</div>',
132 webpage, 'error', default=None)
134 raise ExtractorError(error, expected=True)
136 age_limit = self._rta_search(webpage)
139 return int_or_none(self._search_regex(
140 r'^(\d+)[pP]', s, 'height', default=None))
142 initials = self._parse_json(
144 (r'window\.initials\s*=\s*({.+?})\s*;\s*</script>',
145 r'window\.initials\s*=\s*({.+?})\s*;'), webpage, 'initials',
147 video_id, fatal=False)
149 video = initials['videoModel']
150 title = video['title']
154 sources = try_get(video, lambda x: x['sources'], dict) or {}
155 for format_id, formats_dict in sources.items():
156 if not isinstance(formats_dict, dict):
158 download_sources = try_get(sources, lambda x: x['download'], dict) or {}
159 for quality, format_dict in download_sources.items():
160 if not isinstance(format_dict, dict):
162 format_sizes[quality] = float_or_none(format_dict.get('size'))
163 for quality, format_item in formats_dict.items():
164 if format_id == 'download':
165 # Download link takes some time to be generated,
168 format_url = format_item
169 format_url = url_or_none(format_url)
170 if not format_url or format_url in format_urls:
172 format_urls.add(format_url)
174 'format_id': '%s-%s' % (format_id, quality),
176 'ext': determine_ext(format_url, 'mp4'),
177 'height': get_height(quality),
178 'filesize': format_sizes.get(quality),
180 'Referer': urlh.geturl(),
183 xplayer_sources = try_get(
184 initials, lambda x: x['xplayerSettings']['sources'], dict)
186 hls_sources = xplayer_sources.get('hls')
187 if isinstance(hls_sources, dict):
188 for hls_format_key in ('url', 'fallback'):
189 hls_url = hls_sources.get(hls_format_key)
192 hls_url = urljoin(url, hls_url)
193 if not hls_url or hls_url in format_urls:
195 format_urls.add(hls_url)
196 formats.extend(self._extract_m3u8_formats(
197 hls_url, video_id, 'mp4', entry_protocol='m3u8_native',
198 m3u8_id='hls', fatal=False))
199 standard_sources = xplayer_sources.get('standard')
200 if isinstance(standard_sources, dict):
201 for format_id, formats_list in standard_sources.items():
202 if not isinstance(formats_list, list):
204 for standard_format in formats_list:
205 if not isinstance(standard_format, dict):
207 for standard_format_key in ('url', 'fallback'):
208 standard_url = standard_format.get(standard_format_key)
211 standard_url = urljoin(url, standard_url)
212 if not standard_url or standard_url in format_urls:
214 format_urls.add(standard_url)
215 ext = determine_ext(standard_url, 'mp4')
217 formats.extend(self._extract_m3u8_formats(
218 standard_url, video_id, 'mp4', entry_protocol='m3u8_native',
219 m3u8_id='hls', fatal=False))
221 quality = (str_or_none(standard_format.get('quality'))
222 or str_or_none(standard_format.get('label'))
225 'format_id': '%s-%s' % (format_id, quality),
228 'height': get_height(quality),
229 'filesize': format_sizes.get(quality),
231 'Referer': standard_url,
234 self._sort_formats(formats)
236 categories_list = video.get('categories')
237 if isinstance(categories_list, list):
239 for c in categories_list:
240 if not isinstance(c, dict):
242 c_name = c.get('name')
243 if isinstance(c_name, compat_str):
244 categories.append(c_name)
248 uploader_url = url_or_none(try_get(video, lambda x: x['author']['pageURL']))
252 'display_id': display_id,
254 'description': video.get('description'),
255 'timestamp': int_or_none(video.get('created')),
257 video, lambda x: x['author']['name'], compat_str),
258 'uploader_url': uploader_url,
259 'uploader_id': uploader_url.split('/')[-1] if uploader_url else None,
260 'thumbnail': video.get('thumbURL'),
261 'duration': int_or_none(video.get('duration')),
262 'view_count': int_or_none(video.get('views')),
263 'like_count': int_or_none(try_get(
264 video, lambda x: x['rating']['likes'], int)),
265 'dislike_count': int_or_none(try_get(
266 video, lambda x: x['rating']['dislikes'], int)),
267 'comment_count': int_or_none(video.get('views')),
268 'age_limit': age_limit,
269 'categories': categories,
273 # Old layout fallback
275 title = self._html_search_regex(
276 [r'<h1[^>]*>([^<]+)</h1>',
277 r'<meta[^>]+itemprop=".*?caption
.*?
"[^>]+content="(.+?
)"',
278 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
284 sources = self._parse_json(
286 r'sources\s*:\s*({.+?})\s*,?\s*\n', webpage, 'sources',
288 video_id, fatal=False)
289 for format_id, format_url in sources.items():
290 format_url = url_or_none(format_url)
293 if format_url in format_urls:
295 format_urls.add(format_url)
297 'format_id': format_id,
299 'height': get_height(format_id),
302 video_url = self._search_regex(
303 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
304 r'''<a\s+href=(?P<q>["'])(?P
<mp4
>.+?
)(?P
=q
)\s
+class=["']mp4Thumb''',
305 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
306 webpage, 'video url
', group='mp4
', default=None)
307 if video_url and video_url not in format_urls:
312 self._sort_formats(formats)
314 # Only a few videos have an description
315 mobj = re.search(r'<span
>Description
: </span
>([^
<]+)', webpage)
316 description = mobj.group(1) if mobj else None
318 upload_date = unified_strdate(self._search_regex(
319 r'hint
=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
320 webpage, 'upload date', fatal=False))
322 uploader = self._html_search_regex(
323 r'<span[^>]+itemprop=["\']author
[^
>]+><a
[^
>]+><span
[^
>]+>([^
<]+)',
324 webpage, 'uploader
', default='anonymous
')
326 thumbnail = self._search_regex(
327 [r'''["']thumbUrl
["']\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
328 r'''<video[^>]+"poster"=(?P<q>["'])(?P
<thumbnail
>.+?
)(?P
=q
)[^
>]*>'''],
329 webpage, 'thumbnail', fatal=False, group='thumbnail')
331 duration = parse_duration(self._search_regex(
332 [r'<[^<]+\bitemprop=["\']duration["\'][^<]+\bcontent=["\'](.+?)["\']',
333 r'Runtime:\s*</span>\s*([\d:]+)'], webpage,
334 'duration', fatal=False))
336 view_count = int_or_none(self._search_regex(
337 r'content=["\']User(?:View|Play)s:(\d+)',
338 webpage, 'view count', fatal=False))
340 mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
341 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
343 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
344 comment_count = mobj.group('commentcount') if mobj else 0
346 categories_html = self._search_regex(
347 r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
348 'categories', default=None)
349 categories = [clean_html(category) for category in re.findall(
350 r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
354 'display_id': display_id,
356 'description': description,
357 'upload_date': upload_date,
358 'uploader': uploader,
359 'uploader_id': uploader.lower() if uploader else None,
360 'thumbnail': thumbnail,
361 'duration': duration,
362 'view_count': view_count,
363 'like_count': int_or_none(like_count),
364 'dislike_count': int_or_none(dislike_count),
365 'comment_count': int_or_none(comment_count),
366 'age_limit': age_limit,
367 'categories': categories,
372 class XHamsterEmbedIE(InfoExtractor):
373 _VALID_URL = r'https?://(?:.+?\.)?%s/xembed\.php\?video=(?P<id>\d+)' % XHamsterIE._DOMAINS
375 'url': 'http://xhamster.com/xembed.php?video=3328539',
379 'title': 'Pen Masturbation',
380 'timestamp': 1406581861,
381 'upload_date': '20140728',
382 'uploader': 'ManyakisArt',
389 def _extract_urls(webpage):
390 return [url for _, url in re.findall(
391 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
394 def _real_extract(self, url):
395 video_id = self._match_id(url)
397 webpage = self._download_webpage(url, video_id)
399 video_url = self._search_regex(
400 r'href="(https?://xhamster\.com/(?:movies/{0}/[^"]*\.html|videos/[^/]*-{0})[^"]*)"'.format(video_id),
401 webpage, 'xhamster url', default=None)
404 vars = self._parse_json(
405 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
407 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
409 return self.url_result(video_url, 'XHamster')
412 class XHamsterUserIE(InfoExtractor):
413 _VALID_URL = r'https?://(?:.+?\.)?%s/users/(?P<id>[^/?#&]+)' % XHamsterIE._DOMAINS
415 # Paginated user profile
416 'url': 'https://xhamster.com/users/netvideogirls/videos',
418 'id': 'netvideogirls',
420 'playlist_mincount': 267,
422 # Non-paginated user profile
423 'url': 'https://xhamster.com/users/firatkaan/videos',
427 'playlist_mincount': 1,
430 def _entries(self, user_id):
431 next_page_url = 'https://xhamster.com/users/%s/videos/1' % user_id
432 for pagenum in itertools.count(1):
433 page = self._download_webpage(
434 next_page_url, user_id, 'Downloading page %s' % pagenum)
435 for video_tag in re.findall(
436 r'(<a[^>]+class=["\'].*?\bvideo-thumb__image-container[^>]+>)',
438 video = extract_attributes(video_tag)
439 video_url = url_or_none(video.get('href'))
440 if not video_url or not XHamsterIE.suitable(video_url):
442 video_id = XHamsterIE._match_id(video_url)
443 yield self.url_result(
444 video_url, ie=XHamsterIE.ie_key(), video_id=video_id)
445 mobj = re.search(r'<a[^>]+data-page=["\']next[^>]+>', page)
448 next_page = extract_attributes(mobj.group(0))
449 next_page_url = url_or_none(next_page.get('href'))
450 if not next_page_url:
453 def _real_extract(self, url):
454 user_id = self._match_id(url)
455 return self.playlist_result(self._entries(user_id), user_id)