1 from __future__ import unicode_literals
5 from .common import InfoExtractor
16 class XHamsterIE(InfoExtractor):
17 _VALID_URL = r'(?P<proto>https?)://(?:.+?\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.*?)\.html(?:\?.*)?'
19 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
20 'md5': '8281348b8d3c53d39fffb377d24eac4e',
24 'title': 'FemaleAgent Shy beauty takes the bait',
25 'upload_date': '20121014',
26 'uploader': 'Ruseful2011',
29 'categories': ['Fake Hub', 'Amateur', 'MILFs', 'POV', 'Boss', 'Office', 'Oral', 'Reality', 'Sexy'],
32 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
36 'title': 'Britney Spears Sexy Booty',
37 'upload_date': '20130914',
38 'uploader': 'jojo747400',
41 'categories': ['Britney Spears', 'Celebrities', 'HD Videos', 'Sexy', 'Sexy Booty'],
44 'skip_download': True,
48 'url': 'http://xhamster.com/movies/5667973/.html',
53 'upload_date': '20160208',
54 'uploader': 'parejafree',
57 'categories': ['Amateur', 'Blowjobs'],
60 'skip_download': True,
63 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
64 'only_matching': True,
66 # This video is visible for marcoalfa123456's friends only
67 'url': 'https://it.xhamster.com/movies/7263980/la_mia_vicina.html',
68 'only_matching': True,
71 def _real_extract(self, url):
72 def extract_video_url(webpage, name):
73 return self._search_regex(
74 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
75 r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
76 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
77 webpage, name, group='mp4')
80 return '<div class=\'icon iconHD\'' in webpage
82 mobj = re.match(self._VALID_URL, url)
84 video_id = mobj.group('id')
85 seo = mobj.group('seo')
86 proto = mobj.group('proto')
87 mrss_url = '%s://xhamster.com/movies/%s/%s.html' % (proto, video_id, seo)
88 webpage = self._download_webpage(mrss_url, video_id)
90 error = self._html_search_regex(
91 r'<div[^>]+id=["\']videoClosed["\'][^>]*>(.+?)</div>',
92 webpage, 'error', default=None)
94 raise ExtractorError(error, expected=True)
96 title = self._html_search_regex(
97 [r'<h1[^>]*>([^<]+)</h1>',
98 r'<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"',
99 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
102 # Only a few videos have an description
103 mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
104 description = mobj.group(1) if mobj else None
106 upload_date = unified_strdate(self._search_regex(
107 r'hint=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
108 webpage, 'upload date', fatal=False))
110 uploader = self._html_search_regex(
111 r'<span[^>]+itemprop=["\']author[^>]+><a[^>]+><span[^>]+>([^<]+)',
112 webpage, 'uploader', default='anonymous')
114 thumbnail = self._search_regex(
115 [r'''thumb\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
116 r'''<video[^>]+poster=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
117 webpage, 'thumbnail', fatal=False, group='thumbnail')
119 duration = parse_duration(self._search_regex(
120 r'Runtime:\s*</span>\s*([\d:]+)', webpage,
121 'duration', fatal=False))
123 view_count = int_or_none(self._search_regex(
124 r'content=["\']User(?:View|Play)s:(\d+)',
125 webpage, 'view count', fatal=False))
127 mobj = re.search(r'hint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes', webpage)
128 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
130 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
131 comment_count = mobj.group('commentcount') if mobj else 0
133 age_limit = self._rta_search(webpage)
137 format_id = 'hd' if hd else 'sd'
139 video_url = extract_video_url(webpage, format_id)
142 'format_id': 'hd' if hd else 'sd',
147 mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
148 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
150 video_url = extract_video_url(webpage, 'hd')
157 self._sort_formats(formats)
159 categories_html = self._search_regex(
160 r'(?s)<table.+?(<span>Categories:.+?)</table>', webpage,
161 'categories', default=None)
162 categories = [clean_html(category) for category in re.findall(
163 r'<a[^>]+>(.+?)</a>', categories_html)] if categories_html else None
168 'description': description,
169 'upload_date': upload_date,
170 'uploader': uploader,
171 'thumbnail': thumbnail,
172 'duration': duration,
173 'view_count': view_count,
174 'like_count': int_or_none(like_count),
175 'dislike_count': int_or_none(dislike_count),
176 'comment_count': int_or_none(comment_count),
177 'age_limit': age_limit,
178 'categories': categories,
183 class XHamsterEmbedIE(InfoExtractor):
184 _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
186 'url': 'http://xhamster.com/xembed.php?video=3328539',
190 'title': 'Pen Masturbation',
191 'upload_date': '20140728',
192 'uploader_id': 'anonymous',
199 def _extract_urls(webpage):
200 return [url for _, url in re.findall(
201 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
204 def _real_extract(self, url):
205 video_id = self._match_id(url)
207 webpage = self._download_webpage(url, video_id)
209 video_url = self._search_regex(
210 r'href="(https?://xhamster\.com/movies/%s/[^"]*\.html[^"]*)"' % video_id,
211 webpage, 'xhamster url', default=None)
214 vars = self._parse_json(
215 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
217 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
219 return self.url_result(video_url, 'XHamster')