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': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
43 'only_matching': True,
47 def _real_extract(self, url):
48 def extract_video_url(webpage, name):
49 return self._search_regex(
50 [r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
51 r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
52 r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
53 webpage, name, group='mp4')
56 return '<div class=\'icon iconHD\'' in webpage
58 mobj = re.match(self._VALID_URL, url)
60 video_id = mobj.group('id')
61 seo = mobj.group('seo')
62 proto = mobj.group('proto')
63 mrss_url = '%s://xhamster.com/movies/%s/%s.html' % (proto, video_id, seo)
64 webpage = self._download_webpage(mrss_url, video_id)
66 title = self._html_search_regex(
67 [r'<h1[^>]*>([^<]+)</h1>',
68 r'<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"',
69 r'<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>'],
72 # Only a few videos have an description
73 mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
74 description = mobj.group(1) if mobj else None
76 upload_date = unified_strdate(self._search_regex(
77 r'hint=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}',
78 webpage, 'upload date', fatal=False))
80 uploader = self._html_search_regex(
81 r'<span[^>]+itemprop=["\']author[^>]+><a[^>]+href=["\'].+?xhamster\.com/user/[^>]+>(?P<uploader>.+?)</a>',
82 webpage, 'uploader', default='anonymous')
84 thumbnail = self._search_regex(
85 [r'''thumb\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
86 r'''<video[^>]+poster=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
87 webpage, 'thumbnail', fatal=False, group='thumbnail')
89 duration = float_or_none(self._search_regex(
90 r'(["\'])duration\1\s*:\s*(["\'])(?P<duration>.+?)\2',
91 webpage, 'duration', fatal=False, group='duration'))
93 view_count = int_or_none(self._search_regex(
94 r'content=["\']User(?:View|Play)s:(\d+)',
95 webpage, 'view count', fatal=False))
97 mobj = re.search(r"hint='(?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes'", webpage)
98 (like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
100 mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
101 comment_count = mobj.group('commentcount') if mobj else 0
103 age_limit = self._rta_search(webpage)
107 format_id = 'hd' if hd else 'sd'
109 video_url = extract_video_url(webpage, format_id)
112 'format_id': 'hd' if hd else 'sd',
117 mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
118 webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
120 video_url = extract_video_url(webpage, 'hd')
127 self._sort_formats(formats)
132 'description': description,
133 'upload_date': upload_date,
134 'uploader': uploader,
135 'thumbnail': thumbnail,
136 'duration': duration,
137 'view_count': view_count,
138 'like_count': int_or_none(like_count),
139 'dislike_count': int_or_none(dislike_count),
140 'comment_count': int_or_none(comment_count),
141 'age_limit': age_limit,
146 class XHamsterEmbedIE(InfoExtractor):
147 _VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
149 'url': 'http://xhamster.com/xembed.php?video=3328539',
153 'title': 'Pen Masturbation',
154 'upload_date': '20140728',
155 'uploader_id': 'anonymous',
162 def _extract_urls(webpage):
163 return [url for _, url in re.findall(
164 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
167 def _real_extract(self, url):
168 video_id = self._match_id(url)
170 webpage = self._download_webpage(url, video_id)
172 video_url = self._search_regex(
173 r'href="(https?://xhamster\.com/movies/%s/[^"]+\.html[^"]*)"' % video_id,
174 webpage, 'xhamster url', default=None)
177 vars = self._parse_json(
178 self._search_regex(r'vars\s*:\s*({.+?})\s*,\s*\n', webpage, 'vars'),
180 video_url = dict_get(vars, ('downloadLink', 'homepageLink', 'commentsLink', 'shareUrl'))
182 return self.url_result(video_url, 'XHamster')