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.

93 lines
3.4 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse_urlparse,
  7. compat_urllib_request,
  8. int_or_none,
  9. str_to_int,
  10. )
  11. from ..aes import aes_decrypt_text
  12. class Tube8IE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?tube8\.com/(?:[^/]+/)+(?P<display_id>[^/]+)/(?P<id>\d+)'
  14. _TESTS = [
  15. {
  16. 'url': 'http://www.tube8.com/teen/kasia-music-video/229795/',
  17. 'md5': '44bf12b98313827dd52d35b8706a4ea0',
  18. 'info_dict': {
  19. 'id': '229795',
  20. 'display_id': 'kasia-music-video',
  21. 'ext': 'mp4',
  22. 'description': 'hot teen Kasia grinding',
  23. 'uploader': 'unknown',
  24. 'title': 'Kasia music video',
  25. 'age_limit': 18,
  26. }
  27. },
  28. {
  29. 'url': 'http://www.tube8.com/shemale/teen/blonde-cd-gets-kidnapped-by-two-blacks-and-punished-for-being-a-slutty-girl/19569151/',
  30. 'only_matching': True,
  31. },
  32. ]
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. video_id = mobj.group('id')
  36. display_id = mobj.group('display_id')
  37. req = compat_urllib_request.Request(url)
  38. req.add_header('Cookie', 'age_verified=1')
  39. webpage = self._download_webpage(req, display_id)
  40. flashvars = json.loads(self._html_search_regex(
  41. r'var flashvars\s*=\s*({.+?})', webpage, 'flashvars'))
  42. video_url = flashvars['video_url']
  43. if flashvars.get('encrypted') is True:
  44. video_url = aes_decrypt_text(video_url, flashvars['video_title'], 32).decode('utf-8')
  45. path = compat_urllib_parse_urlparse(video_url).path
  46. format_id = '-'.join(path.split('/')[4].split('_')[:2])
  47. thumbnail = flashvars.get('image_url')
  48. title = self._html_search_regex(
  49. r'videotitle\s*=\s*"([^"]+)', webpage, 'title')
  50. description = self._html_search_regex(
  51. r'>Description:</strong>(.+?)<', webpage, 'description', fatal=False)
  52. uploader = self._html_search_regex(
  53. r'<strong class="video-username">(?:<a href="[^"]+">)?([^<]+)(?:</a>)?</strong>',
  54. webpage, 'uploader', fatal=False)
  55. like_count = int_or_none(self._html_search_regex(
  56. r"rupVar\s*=\s*'(\d+)'", webpage, 'like count', fatal=False))
  57. dislike_count = int_or_none(self._html_search_regex(
  58. r"rdownVar\s*=\s*'(\d+)'", webpage, 'dislike count', fatal=False))
  59. view_count = self._html_search_regex(
  60. r'<strong>Views: </strong>([\d,\.]+)</li>', webpage, 'view count', fatal=False)
  61. if view_count:
  62. view_count = str_to_int(view_count)
  63. comment_count = self._html_search_regex(
  64. r'<span id="allCommentsCount">(\d+)</span>', webpage, 'comment count', fatal=False)
  65. if comment_count:
  66. comment_count = str_to_int(comment_count)
  67. return {
  68. 'id': video_id,
  69. 'display_id': display_id,
  70. 'url': video_url,
  71. 'title': title,
  72. 'description': description,
  73. 'thumbnail': thumbnail,
  74. 'uploader': uploader,
  75. 'format_id': format_id,
  76. 'view_count': view_count,
  77. 'like_count': like_count,
  78. 'dislike_count': dislike_count,
  79. 'comment_count': comment_count,
  80. 'age_limit': 18,
  81. }