1 from __future__ import unicode_literals
5 from .common import InfoExtractor
16 class XHamsterIE(InfoExtractor):
19 (?:.+?\.)?xhamster\.com/
21 movies/(?P<id>\d+)/(?P<display_id>[^/]*)\.html|
22 videos/(?P<display_id_2>[^/]*)-(?P<id_2>\d+)
27 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
28 'md5': '8281348b8d3c53d39fffb377d24eac4e',
32 'title': 'FemaleAgent Shy beauty takes the bait',
33 'upload_date': '20121014',
34 'uploader': 'Ruseful2011',
37 'categories': ['Fake Hub', 'Amateur', 'MILFs', 'POV', 'Boss', 'Office', 'Oral', 'Reality', 'Sexy'],
40 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
44 'title': 'Britney Spears Sexy Booty',
45 'upload_date': '20130914',
46 'uploader': 'jojo747400',
49 'categories': ['Britney Spears', 'Celebrities', 'HD Videos', 'Sexy', 'Sexy Booty'],
52 'skip_download': True,
56 'url': 'http://xhamster.com/movies/5667973/.html',
61 'upload_date': '20160208',
62 'uploader': 'parejafree',
65 'categories': ['Amateur', 'Blowjobs'],
68 'skip_download': True,
71 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
72 'only_matching': True,
74 # This video is visible for marcoalfa123456's friends only
75 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
76 'only_matching': True,
79 'url': 'https://pt.xhamster.com/videos/euro-pedal-pumping-7937821',
80 'only_matching': True,
83 def _real_extract(self, url):
84 def extract_video_url(webpage, name):
85 return self._search_regex(
86 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
87 r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
88 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
89 webpage, name, group='mp4')
92 return '<div class=\'icon iconHD\'' in webpage
94 mobj = re.match(self._VALID_URL, url)
96 video_id = mobj.group('id') or mobj.group('id_2')
97 display_id = mobj.group('display_id') or mobj.group('display_id_2')
99 webpage = self._download_webpage(url, video_id)
101 error = self._html_search_regex(
102 r'<div[^>]+id=["\']videoClosed["\'][^>]*>(.+?)</div>',
103 webpage, 'error', default=None)
105 raise ExtractorError(error, expected=True)
107 title = self._html_search_regex(
108 [r'<h1[^>]*>([^<]+)</h1>',
109 r'<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"',
110 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
113 # Only a few videos have an description
114 mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
115 description = mobj.group(1) if mobj else None
117 upload_date = unified_strdate(self._search_regex(
118 r'hint=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
119 webpage, 'upload date', fatal=False))
121 uploader = self._html_search_regex(
122 r'<span[^>]+itemprop=["\']author[^>]+><a[^>]+><span[^>]+>([^<]+)',
123 webpage, 'uploader', default='anonymous')
125 thumbnail = self._search_regex(
126 [r'''thumb\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
127 r'''<video[^>]+poster=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
128 webpage, 'thumbnail', fatal=False, group='thumbnail')
130 duration = parse_duration(self._search_regex(
131 r'Runtime:\s*</span>\s*([\d:]+)', webpage,
132 'duration', fatal=False))
134 view_count = int_or_none(self._search_regex(
135 r'content=["\']User(?:View|Play)s:(\d+)',
136 webpage, 'view count', fatal=False))
138 mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
139 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
141 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
142 comment_count = mobj.group('commentcount') if mobj else 0
144 age_limit = self._rta_search(webpage)
148 format_id = 'hd' if hd else 'sd'
150 video_url = extract_video_url(webpage, format_id)
153 'format_id': 'hd' if hd else 'sd',
158 mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
159 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
161 video_url = extract_video_url(webpage, 'hd')
168 self._sort_formats(formats)
170 categories_html = self._search_regex(
171 r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
172 'categories', default=None)
173 categories = [clean_html(category) for category in re.findall(
174 r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
179 'description': description,
180 'upload_date': upload_date,
181 'uploader': uploader,
182 'thumbnail': thumbnail,
183 'duration': duration,
184 'view_count': view_count,
185 'like_count': int_or_none(like_count),
186 'dislike_count': int_or_none(dislike_count),
187 'comment_count': int_or_none(comment_count),
188 'age_limit': age_limit,
189 'categories': categories,
194 class XHamsterEmbedIE(InfoExtractor):
195 _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
197 'url': 'http://xhamster.com/xembed.php?video=3328539',
201 'title': 'Pen Masturbation',
202 'upload_date': '20140728',
203 'uploader_id': 'anonymous',
210 def _extract_urls(webpage):
211 return [url for _, url in re.findall(
212 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
215 def _real_extract(self, url):
216 video_id = self._match_id(url)
218 webpage = self._download_webpage(url, video_id)
220 video_url = self._search_regex(
221 r'href="(https?://xhamster\.com/movies/%s/[^"]*\.html[^"]*)"' % video_id,
222 webpage, 'xhamster url', default=None)
225 vars = self._parse_json(
226 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
228 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
230 return self.url_result(video_url, 'XHamster')