1 from __future__ import unicode_literals
5 from .common import InfoExtractor
14 class XHamsterIE(InfoExtractor):
15 _VALID_URL = r'(?P<proto>https?)://(?:.+?\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.*?)\.html(?:\?.*)?'
18 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
22 'title': 'FemaleAgent Shy beauty takes the bait',
23 'upload_date': '20121014',
24 'uploader': 'Ruseful2011',
30 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
34 'title': 'Britney Spears Sexy Booty',
35 'upload_date': '20130914',
36 'uploader': 'jojo747400',
42 'url': 'http://xhamster.com/movies/5667973/.html',
47 'upload_date': '20160208',
48 'uploader': 'parejafree',
54 'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
55 'only_matching': True,
59 def _real_extract(self, url):
60 def extract_video_url(webpage, name):
61 return self._search_regex(
62 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
63 r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
64 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
65 webpage, name, group='mp4')
68 return '<div class=\'icon iconHD\'' in webpage
70 mobj = re.match(self._VALID_URL, url)
72 video_id = mobj.group('id')
73 seo = mobj.group('seo')
74 proto = mobj.group('proto')
75 mrss_url = '%s://xhamster.com/movies/%s/%s.html' % (proto, video_id, seo)
76 webpage = self._download_webpage(mrss_url, video_id)
78 title = self._html_search_regex(
79 [r'<h1[^>]*>([^<]+)</h1>',
80 r'<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"',
81 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
84 # Only a few videos have an description
85 mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
86 description = mobj.group(1) if mobj else None
88 upload_date = unified_strdate(self._search_regex(
89 r'hint=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
90 webpage, 'upload date', fatal=False))
92 uploader = self._html_search_regex(
93 r'<span[^>]+itemprop=["\']author[^>]+><a[^>]+href=["\'].+?xhamster\.com/user/[^>]+>(?P<uploader>.+?)</a>',
94 webpage, 'uploader', default='anonymous')
96 thumbnail = self._search_regex(
97 [r'''thumb\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
98 r'''<video[^>]+poster=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
99 webpage, 'thumbnail', fatal=False, group='thumbnail')
101 duration = float_or_none(self._search_regex(
102 r'(["\'])duration\1\s*:\s*(["\'])(?P<duration>.+?)\2',
103 webpage, 'duration', fatal=False, group='duration'))
105 view_count = int_or_none(self._search_regex(
106 r'content=["\']User(?:View|Play)s:(\d+)',
107 webpage, 'view count', fatal=False))
109 mobj = re.search(r"hint='(?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes'", webpage)
110 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
112 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
113 comment_count = mobj.group('commentcount') if mobj else 0
115 age_limit = self._rta_search(webpage)
119 format_id = 'hd' if hd else 'sd'
121 video_url = extract_video_url(webpage, format_id)
124 'format_id': 'hd' if hd else 'sd',
129 mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
130 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
132 video_url = extract_video_url(webpage, 'hd')
139 self._sort_formats(formats)
144 'description': description,
145 'upload_date': upload_date,
146 'uploader': uploader,
147 'thumbnail': thumbnail,
148 'duration': duration,
149 'view_count': view_count,
150 'like_count': int_or_none(like_count),
151 'dislike_count': int_or_none(dislike_count),
152 'comment_count': int_or_none(comment_count),
153 'age_limit': age_limit,
158 class XHamsterEmbedIE(InfoExtractor):
159 _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
161 'url': 'http://xhamster.com/xembed.php?video=3328539',
165 'title': 'Pen Masturbation',
166 'upload_date': '20140728',
167 'uploader_id': 'anonymous',
174 def _extract_urls(webpage):
175 return [url for _, url in re.findall(
176 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
179 def _real_extract(self, url):
180 video_id = self._match_id(url)
182 webpage = self._download_webpage(url, video_id)
184 video_url = self._search_regex(
185 r'href="(https?://xhamster\.com/movies/%s/[^"]*\.html[^"]*)"' % video_id,
186 webpage, 'xhamster url', default=None)
189 vars = self._parse_json(
190 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
192 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
194 return self.url_result(video_url, 'XHamster')