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.

56 lines
2.0 KiB

  1. from __future__ import unicode_literals
  2. import os
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse_urlparse,
  7. compat_urllib_request,
  8. )
  9. class XTubeIE(InfoExtractor):
  10. _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>xtube\.com/watch\.php\?v=(?P<videoid>[^/?&]+))'
  11. _TEST = {
  12. 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_',
  13. 'file': 'kVTUy_G222_.mp4',
  14. 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab',
  15. 'info_dict': {
  16. "title": "strange erotica",
  17. "description": "surreal gay themed erotica...almost an ET kind of thing",
  18. "uploader": "greenshowers",
  19. "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, 'title')
  30. video_uploader = self._html_search_regex(r'so_s\.addVariable\("owner_u", "([^"]+)', webpage, 'uploader', fatal=False)
  31. video_description = self._html_search_regex(r'<p class="video_description">([^<]+)', webpage, 'description', fatal=False)
  32. video_url= self._html_search_regex(r'var videoMp4 = "([^"]+)', webpage, '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. }