1 from __future__ import unicode_literals
5 from .common import InfoExtractor
15 class XHamsterIE(InfoExtractor):
16 _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',
23 'title': 'FemaleAgent Shy beauty takes the bait',
24 'upload_date': '20121014',
25 'uploader_id': 'Ruseful2011',
31 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
35 'title': 'Britney Spears Sexy Booty',
36 'upload_date': '20130914',
37 'uploader_id': 'jojo747400',
43 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
44 'only_matching': True,
48 def _real_extract(self, url):
49 def extract_video_url(webpage):
50 mp4 = re.search(r'<video\s+.*?file="([^"]+)".*?>', webpage)
52 raise ExtractorError('Unable to extract media URL')
57 return '<div class=\'icon iconHD\'' in webpage
59 mobj = re.match(self._VALID_URL, url)
61 video_id = mobj.group('id')
62 seo = mobj.group('seo')
63 proto = mobj.group('proto')
64 mrss_url = '%s://xhamster.com/movies/%s/%s.html' % (proto, video_id, seo)
65 webpage = self._download_webpage(mrss_url, video_id)
67 title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>', webpage, 'title')
69 # Only a few videos have an description
70 mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
71 description = mobj.group(1) if mobj else None
73 upload_date = self._html_search_regex(r'hint=\'(\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}\'',
74 webpage, 'upload date', fatal=False)
76 upload_date = unified_strdate(upload_date)
78 uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
79 webpage, 'uploader id', default='anonymous')
81 thumbnail = self._html_search_regex(r'<video\s+.*?poster="([^"]+)".*?>', webpage, 'thumbnail', fatal=False)
83 duration = parse_duration(self._html_search_regex(r'<span>Runtime:</span> (\d+:\d+)</div>',
84 webpage, 'duration', fatal=False))
86 view_count = self._html_search_regex(r'<span>Views:</span> ([^<]+)</div>', webpage, 'view count', fatal=False)
88 view_count = str_to_int(view_count)
90 mobj = re.search(r"hint='(?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes'", webpage)
91 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
93 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
94 comment_count = mobj.group('commentcount') if mobj else 0
96 age_limit = self._rta_search(webpage)
100 video_url = extract_video_url(webpage)
103 'format_id': 'hd' if hd else 'sd',
108 mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
109 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
111 video_url = extract_video_url(webpage)
118 self._sort_formats(formats)
123 'description': description,
124 'upload_date': upload_date,
125 'uploader_id': uploader_id,
126 'thumbnail': thumbnail,
127 'duration': duration,
128 'view_count': view_count,
129 'like_count': int_or_none(like_count),
130 'dislike_count': int_or_none(dislike_count),
131 'comment_count': int_or_none(comment_count),
132 'age_limit': age_limit,
137 class XHamsterEmbedIE(InfoExtractor):
138 _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
140 'url': 'http://xhamster.com/xembed.php?video=3328539',
144 'title': 'Pen Masturbation',
145 'upload_date': '20140728',
146 'uploader_id': 'anonymous',
153 def _extract_urls(webpage):
154 return [url for _, url in re.findall(
155 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
158 def _real_extract(self, url):
159 video_id = self._match_id(url)
161 webpage = self._download_webpage(url, video_id)
163 video_url = self._search_regex(
164 r'href="(https?://xhamster\.com/movies/%s/[^"]+\.html[^"]*)"' % video_id,
165 webpage, 'xhamster url')
167 return self.url_result(video_url, 'XHamster')