1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_str
20 class XHamsterIE(InfoExtractor):
21 _DOMAINS = r'(?:xhamster\.(?:com|one|desi)|xhms\.pro|xhamster[27]\.com)'
26 movies/(?P<id>\d+)/(?P<display_id>[^/]*)\.html|
27 videos/(?P<display_id_2>[^/]*)-(?P<id_2>\d+)
31 'url': 'https://xhamster.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
32 'md5': '98b4687efb1ffd331c4197854dc09e8f',
35 'display_id': 'femaleagent-shy-beauty-takes-the-bait',
37 'title': 'FemaleAgent Shy beauty takes the bait',
38 'timestamp': 1350194821,
39 'upload_date': '20121014',
40 'uploader': 'Ruseful2011',
45 'url': 'https://xhamster.com/videos/britney-spears-sexy-booty-2221348?hd=',
48 'display_id': 'britney-spears-sexy-booty',
50 'title': 'Britney Spears Sexy Booty',
51 'timestamp': 1379123460,
52 'upload_date': '20130914',
53 'uploader': 'jojo747400',
58 'skip_download': True,
61 # empty seo, unavailable via new URL schema
62 'url': 'http://xhamster.com/movies/5667973/.html',
67 'timestamp': 1454948101,
68 'upload_date': '20160208',
69 'uploader': 'parejafree',
74 'skip_download': True,
78 'url': 'https://m.xhamster.com/videos/cute-teen-jacqueline-solo-masturbation-8559111',
79 'only_matching': True,
81 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
82 'only_matching': True,
84 # This video is visible for marcoalfa123456's friends only
85 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
86 'only_matching': True,
89 'url': 'https://pt.xhamster.com/videos/euro-pedal-pumping-7937821',
90 'only_matching': True,
92 'url': 'https://xhamster.one/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
93 'only_matching': True,
95 'url': 'https://xhamster.desi/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
96 'only_matching': True,
98 'url': 'https://xhamster2.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445',
99 'only_matching': True,
101 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
102 'only_matching': True,
104 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
105 'only_matching': True,
108 def _real_extract(self, url):
109 mobj = re.match(self._VALID_URL, url)
110 video_id = mobj.group('id') or mobj.group('id_2')
111 display_id = mobj.group('display_id') or mobj.group('display_id_2')
113 desktop_url = re.sub(r'^(https?://(?:.+?\.)?)m\.', r'\1', url)
114 webpage = self._download_webpage(desktop_url, video_id)
116 error = self._html_search_regex(
117 r'<div[^>]+id=["\']videoClosed["\'][^>]*>(.+?)</div>',
118 webpage, 'error', default=None)
120 raise ExtractorError(error, expected=True)
122 age_limit = self._rta_search(webpage)
125 return int_or_none(self._search_regex(
126 r'^(\d+)[pP]', s, 'height', default=None))
128 initials = self._parse_json(
130 r'window\.initials\s*=\s*({.+?})\s*;\s*\n', webpage, 'initials',
132 video_id, fatal=False)
134 video = initials['videoModel']
135 title = video['title']
137 for format_id, formats_dict in video['sources'].items():
138 if not isinstance(formats_dict, dict):
140 for quality, format_item in formats_dict.items():
141 if format_id == 'download':
142 # Download link takes some time to be generated,
145 if not isinstance(format_item, dict):
147 format_url = format_item.get('link')
148 filesize = int_or_none(
149 format_item.get('size'), invscale=1000000)
151 format_url = format_item
153 format_url = url_or_none(format_url)
157 'format_id': '%s-%s' % (format_id, quality),
159 'ext': determine_ext(format_url, 'mp4'),
160 'height': get_height(quality),
161 'filesize': filesize,
163 self._sort_formats(formats)
165 categories_list = video.get('categories')
166 if isinstance(categories_list, list):
168 for c in categories_list:
169 if not isinstance(c, dict):
171 c_name = c.get('name')
172 if isinstance(c_name, compat_str):
173 categories.append(c_name)
179 'display_id': display_id,
181 'description': video.get('description'),
182 'timestamp': int_or_none(video.get('created')),
184 video, lambda x: x['author']['name'], compat_str),
185 'thumbnail': video.get('thumbURL'),
186 'duration': int_or_none(video.get('duration')),
187 'view_count': int_or_none(video.get('views')),
188 'like_count': int_or_none(try_get(
189 video, lambda x: x['rating']['likes'], int)),
190 'dislike_count': int_or_none(try_get(
191 video, lambda x: x['rating']['dislikes'], int)),
192 'comment_count': int_or_none(video.get('views')),
193 'age_limit': age_limit,
194 'categories': categories,
198 # Old layout fallback
200 title = self._html_search_regex(
201 [r'<h1[^>]*>([^<]+)</h1>',
202 r'<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"',
203 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
209 sources = self._parse_json(
211 r'sources\s*:\s*({.+?})\s*,?\s*\n', webpage, 'sources',
213 video_id, fatal=False)
214 for format_id, format_url in sources.items():
215 format_url = url_or_none(format_url)
218 if format_url in format_urls:
220 format_urls.add(format_url)
222 'format_id': format_id,
224 'height': get_height(format_id),
227 video_url = self._search_regex(
228 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
229 r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
230 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
231 webpage, 'video url', group='mp4', default=None)
232 if video_url and video_url not in format_urls:
237 self._sort_formats(formats)
239 # Only a few videos have an description
240 mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
241 description = mobj.group(1) if mobj else None
243 upload_date = unified_strdate(self._search_regex(
244 r'hint=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
245 webpage, 'upload date', fatal=False))
247 uploader = self._html_search_regex(
248 r'<span[^>]+itemprop=["\']author[^>]+><a[^>]+><span[^>]+>([^<]+)',
249 webpage, 'uploader', default='anonymous')
251 thumbnail = self._search_regex(
252 [r'''["']thumbUrl["']\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
253 r'''<video[^>]+"poster"=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
254 webpage, 'thumbnail', fatal=False, group='thumbnail')
256 duration = parse_duration(self._search_regex(
257 [r'<[^<]+\bitemprop=["\']duration["\'][^<]+\bcontent=["\'](.+?)["\']',
258 r'Runtime:\s*</span>\s*([\d:]+)'], webpage,
259 'duration', fatal=False))
261 view_count = int_or_none(self._search_regex(
262 r'content=["\']User(?:View|Play)s:(\d+)',
263 webpage, 'view count', fatal=False))
265 mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
266 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
268 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
269 comment_count = mobj.group('commentcount') if mobj else 0
271 categories_html = self._search_regex(
272 r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
273 'categories', default=None)
274 categories = [clean_html(category) for category in re.findall(
275 r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
279 'display_id': display_id,
281 'description': description,
282 'upload_date': upload_date,
283 'uploader': uploader,
284 'thumbnail': thumbnail,
285 'duration': duration,
286 'view_count': view_count,
287 'like_count': int_or_none(like_count),
288 'dislike_count': int_or_none(dislike_count),
289 'comment_count': int_or_none(comment_count),
290 'age_limit': age_limit,
291 'categories': categories,
296 class XHamsterEmbedIE(InfoExtractor):
297 _VALID_URL = r'https?://(?:.+?\.)?%s/xembed\.php\?video=(?P<id>\d+)' % XHamsterIE._DOMAINS
299 'url': 'http://xhamster.com/xembed.php?video=3328539',
303 'title': 'Pen Masturbation',
304 'timestamp': 1406581861,
305 'upload_date': '20140728',
306 'uploader': 'ManyakisArt',
313 def _extract_urls(webpage):
314 return [url for _, url in re.findall(
315 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
318 def _real_extract(self, url):
319 video_id = self._match_id(url)
321 webpage = self._download_webpage(url, video_id)
323 video_url = self._search_regex(
324 r'href="(https?://xhamster\.com/(?:movies/{0}/[^"]*\.html|videos/[^/]*-{0})[^"]*)"'.format(video_id),
325 webpage, 'xhamster url', default=None)
328 vars = self._parse_json(
329 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
331 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
333 return self.url_result(video_url, 'XHamster')