extremetube.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 ExtremeTubeIE(InfoExtractor):
  10. _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>extremetube\.com/.*?video/.+?(?P<videoid>[0-9]+))(?:[/?&]|$)'
  11. _TESTS = [{
  12. u'url': u'http://www.extremetube.com/video/music-video-14-british-euro-brit-european-cumshots-swallow-652431',
  13. u'file': u'652431.mp4',
  14. u'md5': u'1fb9228f5e3332ec8c057d6ac36f33e0',
  15. u'info_dict': {
  16. u"title": u"Music Video 14 british euro brit european cumshots swallow",
  17. u"uploader": u"unknown",
  18. u"age_limit": 18,
  19. }
  20. }, {
  21. 'url': 'http://www.extremetube.com/gay/video/abcde-1234',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('videoid')
  27. url = 'http://www.' + mobj.group('url')
  28. req = compat_urllib_request.Request(url)
  29. req.add_header('Cookie', 'age_verified=1')
  30. webpage = self._download_webpage(req, video_id)
  31. video_title = self._html_search_regex(r'<h1 [^>]*?title="([^"]+)"[^>]*>\1<', webpage, u'title')
  32. uploader = self._html_search_regex(r'>Posted by:(?=<)(?:\s|<[^>]*>)*(.+?)\|', webpage, u'uploader', fatal=False)
  33. video_url = compat_urllib_parse.unquote(self._html_search_regex(r'video_url=(.+?)&amp;', webpage, u'video_url'))
  34. path = compat_urllib_parse_urlparse(video_url).path
  35. extension = os.path.splitext(path)[1][1:]
  36. format = path.split('/')[5].split('_')[:2]
  37. format = "-".join(format)
  38. return {
  39. 'id': video_id,
  40. 'title': video_title,
  41. 'uploader': uploader,
  42. 'url': video_url,
  43. 'ext': extension,
  44. 'format': format,
  45. 'format_id': format,
  46. 'age_limit': 18,
  47. }