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.

73 lines
2.8 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. compat_urllib_parse,
  5. unescapeHTML,
  6. determine_ext,
  7. ExtractorError,
  8. )
  9. class XHamsterIE(InfoExtractor):
  10. """Information Extractor for xHamster"""
  11. _VALID_URL = r'(?:http://)?(?P<url>(?:www\.)?xhamster\.com/movies/(?P<id>[0-9]+)/.*\.html(?:\?.*)?)'
  12. _TEST = {
  13. u'url': u'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
  14. u'file': u'1509445.flv',
  15. u'md5': u'9f48e0e8d58e3076bb236ff412ab62fa',
  16. u'info_dict': {
  17. u"upload_date": u"20121014",
  18. u"uploader_id": u"Ruseful2011",
  19. u"title": u"FemaleAgent Shy beauty takes the bait"
  20. }
  21. }
  22. def _real_extract(self,url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. mrss_url = 'http://' + mobj.group('url')
  26. webpage = self._download_webpage(mrss_url, video_id)
  27. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  28. if mobj is None:
  29. raise ExtractorError(u'Unable to extract media URL')
  30. if len(mobj.group('server')) == 0:
  31. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  32. else:
  33. video_url = mobj.group('server')+'/key='+mobj.group('file')
  34. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  35. webpage, u'title')
  36. # Only a few videos have an description
  37. mobj = re.search('<span>Description: </span>(?P<description>[^<]+)', webpage)
  38. if mobj:
  39. video_description = unescapeHTML(mobj.group('description'))
  40. else:
  41. video_description = None
  42. 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)
  43. if mobj:
  44. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  45. else:
  46. video_upload_date = None
  47. self._downloader.report_warning(u'Unable to extract upload date')
  48. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  49. webpage, u'uploader id', default=u'anonymous')
  50. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  51. webpage, u'thumbnail', fatal=False)
  52. return [{
  53. 'id': video_id,
  54. 'url': video_url,
  55. 'ext': determine_ext(video_url),
  56. 'title': video_title,
  57. 'description': video_description,
  58. 'upload_date': video_upload_date,
  59. 'uploader_id': video_uploader_id,
  60. 'thumbnail': video_thumbnail
  61. }]