extremetube.py 2.0 KB

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