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.

83 lines
3.0 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/(?:[^/]+/){2}(?P<id>\d+)'
  14. _TEST = {
  15. 'url': 'http://www.tube8.com/teen/kasia-music-video/229795/',
  16. 'file': '229795.mp4',
  17. 'md5': 'e9e0b0c86734e5e3766e653509475db0',
  18. 'info_dict': {
  19. 'description': 'hot teen Kasia grinding',
  20. 'uploader': 'unknown',
  21. 'title': 'Kasia music video',
  22. 'age_limit': 18,
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. req = compat_urllib_request.Request(url)
  29. req.add_header('Cookie', 'age_verified=1')
  30. webpage = self._download_webpage(req, video_id)
  31. flashvars = json.loads(self._html_search_regex(
  32. r'var flashvars\s*=\s*({.+?})', webpage, 'flashvars'))
  33. video_url = flashvars['video_url']
  34. if flashvars.get('encrypted') is True:
  35. video_url = aes_decrypt_text(video_url, flashvars['video_title'], 32).decode('utf-8')
  36. path = compat_urllib_parse_urlparse(video_url).path
  37. format_id = '-'.join(path.split('/')[4].split('_')[:2])
  38. thumbnail = flashvars.get('image_url')
  39. title = self._html_search_regex(
  40. r'videotitle\s*=\s*"([^"]+)', webpage, 'title')
  41. description = self._html_search_regex(
  42. r'>Description:</strong>(.+?)<', webpage, 'description', fatal=False)
  43. uploader = self._html_search_regex(
  44. r'<strong class="video-username">(?:<a href="[^"]+">)?([^<]+)(?:</a>)?</strong>',
  45. webpage, 'uploader', fatal=False)
  46. like_count = int_or_none(self._html_search_regex(
  47. r"rupVar\s*=\s*'(\d+)'", webpage, 'like count', fatal=False))
  48. dislike_count = int_or_none(self._html_search_regex(
  49. r"rdownVar\s*=\s*'(\d+)'", webpage, 'dislike count', fatal=False))
  50. view_count = self._html_search_regex(
  51. r'<strong>Views: </strong>([\d,\.]+)</li>', webpage, 'view count', fatal=False)
  52. if view_count:
  53. view_count = str_to_int(view_count)
  54. comment_count = self._html_search_regex(
  55. r'<span id="allCommentsCount">(\d+)</span>', webpage, 'comment count', fatal=False)
  56. if comment_count:
  57. comment_count = str_to_int(comment_count)
  58. return {
  59. 'id': video_id,
  60. 'url': video_url,
  61. 'title': title,
  62. 'description': description,
  63. 'thumbnail': thumbnail,
  64. 'uploader': uploader,
  65. 'format_id': format_id,
  66. 'view_count': view_count,
  67. 'like_count': like_count,
  68. 'dislike_count': dislike_count,
  69. 'comment_count': comment_count,
  70. 'age_limit': 18,
  71. }