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.

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