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.

75 lines
2.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_parse_qs,
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. qualities,
  10. str_to_int,
  11. )
  12. class ExtremeTubeIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?(?P<url>extremetube\.com/.*?video/.+?(?P<id>[0-9]+))(?:[/?&]|$)'
  14. _TESTS = [{
  15. 'url': 'http://www.extremetube.com/video/music-video-14-british-euro-brit-european-cumshots-swallow-652431',
  16. 'md5': '344d0c6d50e2f16b06e49ca011d8ac69',
  17. 'info_dict': {
  18. 'id': '652431',
  19. 'ext': 'mp4',
  20. 'title': 'Music Video 14 british euro brit european cumshots swallow',
  21. 'uploader': 'unknown',
  22. 'view_count': int,
  23. 'age_limit': 18,
  24. }
  25. }, {
  26. 'url': 'http://www.extremetube.com/gay/video/abcde-1234',
  27. 'only_matching': True,
  28. }]
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. url = 'http://www.' + mobj.group('url')
  33. req = compat_urllib_request.Request(url)
  34. req.add_header('Cookie', 'age_verified=1')
  35. webpage = self._download_webpage(req, video_id)
  36. video_title = self._html_search_regex(
  37. r'<h1 [^>]*?title="([^"]+)"[^>]*>', webpage, 'title')
  38. uploader = self._html_search_regex(
  39. r'Uploaded by:\s*</strong>\s*(.+?)\s*</div>',
  40. webpage, 'uploader', fatal=False)
  41. view_count = str_to_int(self._html_search_regex(
  42. r'Views:\s*</strong>\s*<span>([\d,\.]+)</span>',
  43. webpage, 'view count', fatal=False))
  44. flash_vars = compat_parse_qs(self._search_regex(
  45. r'<param[^>]+?name="flashvars"[^>]+?value="([^"]+)"', webpage, 'flash vars'))
  46. formats = []
  47. quality = qualities(['180p', '240p', '360p', '480p', '720p', '1080p'])
  48. for k, vals in flash_vars.items():
  49. m = re.match(r'quality_(?P<quality>[0-9]+p)$', k)
  50. if m is not None:
  51. formats.append({
  52. 'format_id': m.group('quality'),
  53. 'quality': quality(m.group('quality')),
  54. 'url': vals[0],
  55. })
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'title': video_title,
  60. 'formats': formats,
  61. 'uploader': uploader,
  62. 'view_count': view_count,
  63. 'age_limit': 18,
  64. }