3 from .common 
import InfoExtractor
 
  12 class XHamsterIE(InfoExtractor
): 
  13     """Information Extractor for xHamster""" 
  14     _VALID_URL 
= r
'(?:http://)?(?:www\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?' 
  16         u
'url': u
'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html', 
  17         u
'file': u
'1509445.flv', 
  18         u
'md5': u
'9f48e0e8d58e3076bb236ff412ab62fa', 
  20             u
"upload_date": u
"20121014",  
  21             u
"uploader_id": u
"Ruseful2011",  
  22             u
"title": u
"FemaleAgent Shy beauty takes the bait", 
  27         u
'url': u
'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd', 
  28         u
'file': u
'2221348.flv', 
  29         u
'md5': u
'e767b9475de189320f691f49c679c4c7', 
  31             u
"upload_date": u
"20130914", 
  32             u
"uploader_id": u
"jojo747400", 
  33             u
"title": u
"Britney Spears  Sexy Booty", 
  38     def _real_extract(self
,url
): 
  39         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  41         video_id 
= mobj
.group('id') 
  42         seo 
= mobj
.group('seo') 
  43         mrss_url 
= 'http://xhamster.com/movies/%s/%s.html?hd' % (video_id
, seo
) 
  44         webpage 
= self
._download
_webpage
(mrss_url
, video_id
) 
  46         mobj 
= re
.search(r
'\'srv
\': \'(?P
<server
>[^
\']*)\',\s
*\'file\': \'(?P
<file>[^
\']+)\',', webpage) 
  48             raise ExtractorError(u'Unable to extract media URL
') 
  49         if len(mobj.group('server
')) == 0: 
  50             video_url = compat_urllib_parse.unquote(mobj.group('file')) 
  52             video_url = mobj.group('server
')+'/key
='+mobj.group('file') 
  54         video_title = self._html_search_regex(r'<title
>(?P
<title
>.+?
) - xHamster\
.com
</title
>', 
  57         # Only a few videos have an description 
  58         mobj = re.search('<span
>Description
: </span
>(?P
<description
>[^
<]+)', webpage) 
  60             video_description = unescapeHTML(mobj.group('description
')) 
  62             video_description = None 
  64         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) 
  66             video_upload_date = mobj.group('upload_date_Y
')+mobj.group('upload_date_m
')+mobj.group('upload_date_d
') 
  68             video_upload_date = None 
  69             self._downloader.report_warning(u'Unable to extract upload date
') 
  71         video_uploader_id = self._html_search_regex(r'<a href
=\'/user
/[^
>]+>(?P
<uploader_id
>[^
<]+)', 
  72             webpage, u'uploader 
id', default=u'anonymous
') 
  74         video_thumbnail = self._search_regex(r'\'image
\':\'(?P
<thumbnail
>[^
\']+)\'', 
  75             webpage, u'thumbnail
', fatal=False) 
  77         age_limit = self._rta_search(webpage) 
  82             'ext
':      determine_ext(video_url), 
  84             'description
': video_description, 
  85             'upload_date
': video_upload_date, 
  86             'uploader_id
': video_uploader_id, 
  87             'thumbnail
': video_thumbnail, 
  88             'age_limit
': age_limit,