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.

55 lines
2.0 KiB

  1. import os
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urllib_parse_urlparse,
  6. compat_urllib_request,
  7. compat_urllib_parse,
  8. )
  9. class XTubeIE(InfoExtractor):
  10. _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>xtube\.com/watch\.php\?v=(?P<videoid>[^/?&]+))'
  11. _TEST = {
  12. u'url': u'http://www.xtube.com/watch.php?v=kVTUy_G222_',
  13. u'file': u'kVTUy_G222_.mp4',
  14. u'md5': u'092fbdd3cbe292c920ef6fc6a8a9cdab',
  15. u'info_dict': {
  16. u"title": u"strange erotica",
  17. u"description": u"surreal gay themed erotica...almost an ET kind of thing",
  18. u"uploader": u"greenshowers",
  19. u"age_limit": 18,
  20. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('videoid')
  25. url = 'http://www.' + mobj.group('url')
  26. req = compat_urllib_request.Request(url)
  27. req.add_header('Cookie', 'age_verified=1')
  28. webpage = self._download_webpage(req, video_id)
  29. video_title = self._html_search_regex(r'<div class="p_5px[^>]*>([^<]+)', webpage, u'title')
  30. video_uploader = self._html_search_regex(r'so_s\.addVariable\("owner_u", "([^"]+)', webpage, u'uploader', fatal=False)
  31. video_description = self._html_search_regex(r'<p class="video_description">([^<]+)', webpage, u'description', default=None)
  32. video_url= self._html_search_regex(r'var videoMp4 = "([^"]+)', webpage, u'video_url').replace('\\/', '/')
  33. path = compat_urllib_parse_urlparse(video_url).path
  34. extension = os.path.splitext(path)[1][1:]
  35. format = path.split('/')[5].split('_')[:2]
  36. format[0] += 'p'
  37. format[1] += 'k'
  38. format = "-".join(format)
  39. return {
  40. 'id': video_id,
  41. 'title': video_title,
  42. 'uploader': video_uploader,
  43. 'description': video_description,
  44. 'url': video_url,
  45. 'ext': extension,
  46. 'format': format,
  47. 'format_id': format,
  48. 'age_limit': 18,
  49. }