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.

84 lines
3.2 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://)?(?:www\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?'
  12. _TESTS = [{
  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. {
  23. u'url': u'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
  24. u'file': u'2221348.flv',
  25. u'md5': u'e767b9475de189320f691f49c679c4c7',
  26. u'info_dict': {
  27. u"upload_date": u"20130914",
  28. u"uploader_id": u"jojo747400",
  29. u"title": u"Britney Spears Sexy Booty"
  30. }
  31. }]
  32. def _real_extract(self,url):
  33. mobj = re.match(self._VALID_URL, url)
  34. video_id = mobj.group('id')
  35. seo = mobj.group('seo')
  36. mrss_url = 'http://xhamster.com/movies/%s/%s.html?hd' % (video_id, seo)
  37. webpage = self._download_webpage(mrss_url, video_id)
  38. mobj = re.search(r'\'srv\': \'(?P<server>[^\']*)\',\s*\'file\': \'(?P<file>[^\']+)\',', webpage)
  39. if mobj is None:
  40. raise ExtractorError(u'Unable to extract media URL')
  41. if len(mobj.group('server')) == 0:
  42. video_url = compat_urllib_parse.unquote(mobj.group('file'))
  43. else:
  44. video_url = mobj.group('server')+'/key='+mobj.group('file')
  45. video_title = self._html_search_regex(r'<title>(?P<title>.+?) - xHamster\.com</title>',
  46. webpage, u'title')
  47. # Only a few videos have an description
  48. mobj = re.search('<span>Description: </span>(?P<description>[^<]+)', webpage)
  49. if mobj:
  50. video_description = unescapeHTML(mobj.group('description'))
  51. else:
  52. video_description = None
  53. 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)
  54. if mobj:
  55. video_upload_date = mobj.group('upload_date_Y')+mobj.group('upload_date_m')+mobj.group('upload_date_d')
  56. else:
  57. video_upload_date = None
  58. self._downloader.report_warning(u'Unable to extract upload date')
  59. video_uploader_id = self._html_search_regex(r'<a href=\'/user/[^>]+>(?P<uploader_id>[^<]+)',
  60. webpage, u'uploader id', default=u'anonymous')
  61. video_thumbnail = self._search_regex(r'\'image\':\'(?P<thumbnail>[^\']+)\'',
  62. webpage, u'thumbnail', fatal=False)
  63. return [{
  64. 'id': video_id,
  65. 'url': video_url,
  66. 'ext': determine_ext(video_url),
  67. 'title': video_title,
  68. 'description': video_description,
  69. 'upload_date': video_upload_date,
  70. 'uploader_id': video_uploader_id,
  71. 'thumbnail': video_thumbnail
  72. }]