1 from __future__ import unicode_literals
5 from .common import InfoExtractor
14 class XHamsterIE(InfoExtractor):
15 """Information Extractor for xHamster"""
16 _VALID_URL = r'(?:http://)?(?:www\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?'
18 'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
19 'file': '1509445.flv',
20 'md5': '9f48e0e8d58e3076bb236ff412ab62fa',
22 "upload_date": "20121014",
23 "uploader_id": "Ruseful2011",
24 "title": "FemaleAgent Shy beauty takes the bait",
29 'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
30 'file': '2221348.flv',
31 'md5': 'e767b9475de189320f691f49c679c4c7',
33 "upload_date": "20130914",
34 "uploader_id": "jojo747400",
35 "title": "Britney Spears Sexy Booty",
40 def _real_extract(self,url):
41 def extract_video_url(webpage):
42 mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
44 raise ExtractorError(u'Unable to extract media URL')
45 if len(mobj.group('server')) == 0:
46 return compat_urllib_parse.unquote(mobj.group('file'))
48 return mobj.group('server')+'/key='+mobj.group('file')
50 def extract_mp4_video_url(webpage):
51 mp4 = re.search(r'<a href=\"(.+?)\" class=\"mp4Play\"',webpage)
58 return webpage.find('<div class=\'icon iconHD\'') != -1
60 mobj = re.match(self._VALID_URL, url)
62 video_id = mobj.group('id')
63 seo = mobj.group('seo')
64 mrss_url = 'http://xhamster.com/movies/%s/%s.html' % (video_id, seo)
65 webpage = self._download_webpage(mrss_url, video_id)
67 video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
70 # Only a few videos have an description
71 mobj = re.search('<span>Description: </span>(?P<description>[^<]+)', webpage)
73 video_description = unescapeHTML(mobj.group('description'))
75 video_description = None
77 mobj = re.search(r'hint=\'(?P<upload_date_Y>[0-9]{4})-(?P<upload_date_m>[0-9]{2})-(?P<upload_date_d>[0-9]{2}) [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3,4}\'', webpage)
79 video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
81 video_upload_date = None
82 self._downloader.report_warning(u'Unable to extract upload date')
84 video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
85 webpage, 'uploader id', default=u'anonymous')
87 video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
88 webpage, 'thumbnail', fatal=False)
90 age_limit = self._rta_search(webpage)
94 video_url = extract_video_url(webpage)
97 'ext': determine_ext(video_url),
98 'format': 'hd' if hd else 'sd',
99 'format_id': 'hd' if hd else 'sd',
102 video_mp4_url = extract_mp4_video_url(webpage)
103 if (not video_mp4_url is None) and (formats[0]['ext'] != 'mp4'):
105 'url': video_mp4_url,
107 'format': 'hd' if hd else 'sd',
108 'format_id': 'hd' if hd else 'sd',
112 webpage = self._download_webpage(mrss_url+'?hd', video_id)
114 video_url = extract_video_url(webpage)
117 'ext': determine_ext(video_url),
124 'title': video_title,
126 'description': video_description,
127 'upload_date': video_upload_date,
128 'uploader_id': video_uploader_id,
129 'thumbnail': video_thumbnail,
130 'age_limit': age_limit,