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.

60 lines
1.9 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import base64
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. unified_strdate,
  7. int_or_none,
  8. )
  9. class VideoTtIE(InfoExtractor):
  10. ID_NAME = 'video.tt'
  11. IE_DESC = 'video.tt - Your True Tube'
  12. _VALID_URL = r'http://(?:www\.)?video\.tt/(?:video/|watch_video\.php\?v=)(?P<id>[\da-zA-Z]{9})'
  13. _TEST = {
  14. 'url': 'http://www.video.tt/watch_video.php?v=amd5YujV8',
  15. 'md5': 'b13aa9e2f267effb5d1094443dff65ba',
  16. 'info_dict': {
  17. 'id': 'amd5YujV8',
  18. 'ext': 'flv',
  19. 'title': 'Motivational video Change your mind in just 2.50 mins',
  20. 'description': '',
  21. 'upload_date': '20130827',
  22. 'uploader': 'joseph313',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. settings = self._download_json(
  29. 'http://www.video.tt/player_control/settings.php?v=%s' % video_id, video_id,
  30. 'Downloading video JSON')['settings']
  31. video = settings['video_details']['video']
  32. formats = [
  33. {
  34. 'url': base64.b64decode(res['u']).decode('utf-8'),
  35. 'ext': 'flv',
  36. 'format_id': res['l'],
  37. } for res in settings['res'] if res['u']
  38. ]
  39. return {
  40. 'id': video_id,
  41. 'title': video['title'],
  42. 'description': video['description'],
  43. 'thumbnail': settings['config']['thumbnail'],
  44. 'upload_date': unified_strdate(video['added']),
  45. 'uploader': video['owner'],
  46. 'view_count': int_or_none(video['view_count']),
  47. 'comment_count': None if video.get('comment_count') == '--' else int_or_none(video['comment_count']),
  48. 'like_count': int_or_none(video['liked']),
  49. 'dislike_count': int_or_none(video['disliked']),
  50. 'formats': formats,
  51. }