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.

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