extremetube.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_request
  5. from ..utils import (
  6. int_or_none,
  7. str_to_int,
  8. )
  9. class ExtremeTubeIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?(?P<url>extremetube\.com/.*?video/.+?(?P<id>[0-9]+))(?:[/?&]|$)'
  11. _TESTS = [{
  12. 'url': 'http://www.extremetube.com/video/music-video-14-british-euro-brit-european-cumshots-swallow-652431',
  13. 'md5': '344d0c6d50e2f16b06e49ca011d8ac69',
  14. 'info_dict': {
  15. 'id': '652431',
  16. 'ext': 'mp4',
  17. 'title': 'Music Video 14 british euro brit european cumshots swallow',
  18. 'uploader': 'unknown',
  19. 'view_count': int,
  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('id')
  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="([^"]+)"[^>]*>', webpage, 'title')
  35. uploader = self._html_search_regex(
  36. r'Uploaded by:\s*</strong>\s*(.+?)\s*</div>',
  37. webpage, 'uploader', fatal=False)
  38. view_count = str_to_int(self._html_search_regex(
  39. r'Views:\s*</strong>\s*<span>([\d,\.]+)</span>',
  40. webpage, 'view count', fatal=False))
  41. flash_vars = self._parse_json(
  42. self._search_regex(
  43. r'var\s+flashvars\s*=\s*({.+?});', webpage, 'flash vars'),
  44. video_id)
  45. formats = []
  46. for quality_key, video_url in flash_vars.items():
  47. height = int_or_none(self._search_regex(
  48. r'quality_(\d+)[pP]$', quality_key, 'height', default=None))
  49. if not height:
  50. continue
  51. f = {
  52. 'url': video_url,
  53. }
  54. mobj = re.search(
  55. r'/(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+', video_url)
  56. if mobj:
  57. height = int(mobj.group('height'))
  58. bitrate = int(mobj.group('bitrate'))
  59. f.update({
  60. 'format_id': '%dp-%dk' % (height, bitrate),
  61. 'height': height,
  62. 'tbr': bitrate,
  63. })
  64. else:
  65. f.update({
  66. 'format_id': '%dp' % height,
  67. 'height': height,
  68. })
  69. formats.append(f)
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'title': video_title,
  74. 'formats': formats,
  75. 'uploader': uploader,
  76. 'view_count': view_count,
  77. 'age_limit': 18,
  78. }