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.

132 lines
4.7 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. float_or_none,
  7. sanitized_Request,
  8. )
  9. class AzubuIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?azubu\.tv/[^/]+#!/play/(?P<id>\d+)'
  11. _TESTS = [
  12. {
  13. 'url': 'http://www.azubu.tv/GSL#!/play/15575/2014-hot6-cup-last-big-match-ro8-day-1',
  14. 'md5': 'a88b42fcf844f29ad6035054bd9ecaf4',
  15. 'info_dict': {
  16. 'id': '15575',
  17. 'ext': 'mp4',
  18. 'title': '2014 HOT6 CUP LAST BIG MATCH Ro8 Day 1',
  19. 'description': 'md5:d06bdea27b8cc4388a90ad35b5c66c01',
  20. 'thumbnail': 're:^https?://.*\.jpe?g',
  21. 'timestamp': 1417523507.334,
  22. 'upload_date': '20141202',
  23. 'duration': 9988.7,
  24. 'uploader': 'GSL',
  25. 'uploader_id': 414310,
  26. 'view_count': int,
  27. },
  28. },
  29. {
  30. 'url': 'http://www.azubu.tv/FnaticTV#!/play/9344/-fnatic-at-worlds-2014:-toyz---%22i-love-rekkles,-he-has-amazing-mechanics%22-',
  31. 'md5': 'b72a871fe1d9f70bd7673769cdb3b925',
  32. 'info_dict': {
  33. 'id': '9344',
  34. 'ext': 'mp4',
  35. 'title': 'Fnatic at Worlds 2014: Toyz - "I love Rekkles, he has amazing mechanics"',
  36. 'description': 'md5:4a649737b5f6c8b5c5be543e88dc62af',
  37. 'thumbnail': 're:^https?://.*\.jpe?g',
  38. 'timestamp': 1410530893.320,
  39. 'upload_date': '20140912',
  40. 'duration': 172.385,
  41. 'uploader': 'FnaticTV',
  42. 'uploader_id': 272749,
  43. 'view_count': int,
  44. },
  45. },
  46. ]
  47. def _real_extract(self, url):
  48. video_id = self._match_id(url)
  49. data = self._download_json(
  50. 'http://www.azubu.tv/api/video/%s' % video_id, video_id)['data']
  51. title = data['title'].strip()
  52. description = data['description']
  53. thumbnail = data['thumbnail']
  54. view_count = data['view_count']
  55. uploader = data['user']['username']
  56. uploader_id = data['user']['id']
  57. stream_params = json.loads(data['stream_params'])
  58. timestamp = float_or_none(stream_params['creationDate'], 1000)
  59. duration = float_or_none(stream_params['length'], 1000)
  60. renditions = stream_params.get('renditions') or []
  61. video = stream_params.get('FLVFullLength') or stream_params.get('videoFullLength')
  62. if video:
  63. renditions.append(video)
  64. formats = [{
  65. 'url': fmt['url'],
  66. 'width': fmt['frameWidth'],
  67. 'height': fmt['frameHeight'],
  68. 'vbr': float_or_none(fmt['encodingRate'], 1000),
  69. 'filesize': fmt['size'],
  70. 'vcodec': fmt['videoCodec'],
  71. 'container': fmt['videoContainer'],
  72. } for fmt in renditions if fmt['url']]
  73. self._sort_formats(formats)
  74. return {
  75. 'id': video_id,
  76. 'title': title,
  77. 'description': description,
  78. 'thumbnail': thumbnail,
  79. 'timestamp': timestamp,
  80. 'duration': duration,
  81. 'uploader': uploader,
  82. 'uploader_id': uploader_id,
  83. 'view_count': view_count,
  84. 'formats': formats,
  85. }
  86. class AzubuLiveIE(InfoExtractor):
  87. _VALID_URL = r'https?://www.azubu.tv/(?P<id>[^/]+)$'
  88. _TEST = {
  89. 'url': 'http://www.azubu.tv/MarsTVMDLen',
  90. 'only_matching': True,
  91. }
  92. def _real_extract(self, url):
  93. user = self._match_id(url)
  94. info = self._download_json(
  95. 'http://api.azubu.tv/public/modules/last-video/{0}/info'.format(user),
  96. user)['data']
  97. if info['type'] != 'STREAM':
  98. raise ExtractorError('{0} is not streaming live'.format(user), expected=True)
  99. req = sanitized_Request(
  100. 'https://edge-elb.api.brightcove.com/playback/v1/accounts/3361910549001/videos/ref:' + info['reference_id'])
  101. req.add_header('Accept', 'application/json;pk=BCpkADawqM1gvI0oGWg8dxQHlgT8HkdE2LnAlWAZkOlznO39bSZX726u4JqnDsK3MDXcO01JxXK2tZtJbgQChxgaFzEVdHRjaDoxaOu8hHOO8NYhwdxw9BzvgkvLUlpbDNUuDoc4E4wxDToV')
  102. bc_info = self._download_json(req, user)
  103. m3u8_url = next(source['src'] for source in bc_info['sources'] if source['container'] == 'M2TS')
  104. formats = self._extract_m3u8_formats(m3u8_url, user, ext='mp4')
  105. self._sort_formats(formats)
  106. return {
  107. 'id': info['id'],
  108. 'title': self._live_title(info['title']),
  109. 'uploader_id': user,
  110. 'formats': formats,
  111. 'is_live': True,
  112. 'thumbnail': bc_info['poster'],
  113. }