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.

95 lines
3.4 KiB

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