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': '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': '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, name):
50 return self._search_regex(
51 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
52 r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
53 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
54 webpage, name, group='mp4')
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 = self._html_search_regex(
79 r"<a href='[^']+xhamster\.com/user/[^>]+>(?P<uploader>[^<]+)",
80 webpage, 'uploader', default='anonymous')
82 thumbnail = self._search_regex(
83 [r'''thumb\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
84 r'''<video[^>]+poster=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
85 webpage, 'thumbnail', fatal=False, group='thumbnail')
87 duration = parse_duration(self._html_search_regex(r'<span>Runtime:</span> (\d+:\d+)</div>',
88 webpage, 'duration', fatal=False))
90 view_count = self._html_search_regex(r'<span>Views:</span> ([^<]+)</div>', webpage, 'view count', fatal=False)
92 view_count = str_to_int(view_count)
94 mobj = re.search(r"hint='(?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes'", webpage)
95 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
97 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
98 comment_count = mobj.group('commentcount') if mobj else 0
100 age_limit = self._rta_search(webpage)
104 format_id = 'hd' if hd else 'sd'
106 video_url = extract_video_url(webpage, format_id)
109 'format_id': 'hd' if hd else 'sd',
114 mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
115 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
117 video_url = extract_video_url(webpage, 'hd')
124 self._sort_formats(formats)
129 'description': description,
130 'upload_date': upload_date,
131 'uploader': uploader,
132 'thumbnail': thumbnail,
133 'duration': duration,
134 'view_count': view_count,
135 'like_count': int_or_none(like_count),
136 'dislike_count': int_or_none(dislike_count),
137 'comment_count': int_or_none(comment_count),
138 'age_limit': age_limit,
143 class XHamsterEmbedIE(InfoExtractor):
144 _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
146 'url': 'http://xhamster.com/xembed.php?video=3328539',
150 'title': 'Pen Masturbation',
151 'upload_date': '20140728',
152 'uploader_id': 'anonymous',
159 def _extract_urls(webpage):
160 return [url for _, url in re.findall(
161 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
164 def _real_extract(self, url):
165 video_id = self._match_id(url)
167 webpage = self._download_webpage(url, video_id)
169 video_url = self._search_regex(
170 r'href="(https?://xhamster\.com/movies/%s/[^"]+\.html[^"]*)"' % video_id,
171 webpage, 'xhamster url')
173 return self.url_result(video_url, 'XHamster')