You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.4 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. compat_urllib_parse,
  5. ExtractorError,
  6. )
  7. class XHamsterIE(InfoExtractor):
  8. """Information Extractor for xHamster"""
  9. _VALID_URL = r'(?:http://)?(?:www.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html'
  10. def _real_extract(self,url):
  11. mobj = re.match(self._VALID_URL, url)
  12. video_id = mobj.group('id')
  13. mrss_url = 'http://xhamster.com/movies/%s/.html' % video_id
  14. webpage = self._download_webpage(mrss_url, video_id)
  15. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  16. if mobj is None:
  17. raise ExtractorError(u'Unable to extract media URL')
  18. if len(mobj.group('server')) == 0:
  19. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  20. else:
  21. video_url = mobj.group('server')+'/key='+mobj.group('file')
  22. video_extension = video_url.split('.')[-1]
  23. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  24. webpage, u'title')
  25. # Can't see the description anywhere in the UI
  26. # video_description = self._html_search_regex(r'<span>Description: </span>(?P<description>[^<]+)',
  27. # webpage, u'description', fatal=False)
  28. # if video_description: video_description = unescapeHTML(video_description)
  29. 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)
  30. if mobj:
  31. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  32. else:
  33. video_upload_date = None
  34. self._downloader.report_warning(u'Unable to extract upload date')
  35. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  36. webpage, u'uploader id', default=u'anonymous')
  37. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  38. webpage, u'thumbnail', fatal=False)
  39. return [{
  40. 'id': video_id,
  41. 'url': video_url,
  42. 'ext': video_extension,
  43. 'title': video_title,
  44. # 'description': video_description,
  45. 'upload_date': video_upload_date,
  46. 'uploader_id': video_uploader_id,
  47. 'thumbnail': video_thumbnail
  48. }]