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.

140 lines
5.1 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|uol.com.br)/[^/]+#!/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': r'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': r'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. 'skip': 'Channel offline',
  46. },
  47. ]
  48. def _real_extract(self, url):
  49. video_id = self._match_id(url)
  50. data = self._download_json(
  51. 'http://www.azubu.tv/api/video/%s' % video_id, video_id)['data']
  52. title = data['title'].strip()
  53. description = data.get('description')
  54. thumbnail = data.get('thumbnail')
  55. view_count = data.get('view_count')
  56. user = data.get('user', {})
  57. uploader = user.get('username')
  58. uploader_id = user.get('id')
  59. stream_params = json.loads(data['stream_params'])
  60. timestamp = float_or_none(stream_params.get('creationDate'), 1000)
  61. duration = float_or_none(stream_params.get('length'), 1000)
  62. renditions = stream_params.get('renditions') or []
  63. video = stream_params.get('FLVFullLength') or stream_params.get('videoFullLength')
  64. if video:
  65. renditions.append(video)
  66. if not renditions and not user.get('channel', {}).get('is_live', True):
  67. raise ExtractorError('%s said: channel is offline.' % self.IE_NAME, expected=True)
  68. formats = [{
  69. 'url': fmt['url'],
  70. 'width': fmt['frameWidth'],
  71. 'height': fmt['frameHeight'],
  72. 'vbr': float_or_none(fmt['encodingRate'], 1000),
  73. 'filesize': fmt['size'],
  74. 'vcodec': fmt['videoCodec'],
  75. 'container': fmt['videoContainer'],
  76. } for fmt in renditions if fmt['url']]
  77. self._sort_formats(formats)
  78. return {
  79. 'id': video_id,
  80. 'title': title,
  81. 'description': description,
  82. 'thumbnail': thumbnail,
  83. 'timestamp': timestamp,
  84. 'duration': duration,
  85. 'uploader': uploader,
  86. 'uploader_id': uploader_id,
  87. 'view_count': view_count,
  88. 'formats': formats,
  89. }
  90. class AzubuLiveIE(InfoExtractor):
  91. _VALID_URL = r'https?://(?:www\.)?azubu\.(?:tv|uol.com.br)/(?P<id>[^/]+)$'
  92. _TESTS = [{
  93. 'url': 'http://www.azubu.tv/MarsTVMDLen',
  94. 'only_matching': True,
  95. }, {
  96. 'url': 'http://azubu.uol.com.br/adolfz',
  97. 'only_matching': True,
  98. }]
  99. def _real_extract(self, url):
  100. user = self._match_id(url)
  101. info = self._download_json(
  102. 'http://api.azubu.tv/public/modules/last-video/{0}/info'.format(user),
  103. user)['data']
  104. if info['type'] != 'STREAM':
  105. raise ExtractorError('{0} is not streaming live'.format(user), expected=True)
  106. req = sanitized_Request(
  107. 'https://edge-elb.api.brightcove.com/playback/v1/accounts/3361910549001/videos/ref:' + info['reference_id'])
  108. req.add_header('Accept', 'application/json;pk=BCpkADawqM1gvI0oGWg8dxQHlgT8HkdE2LnAlWAZkOlznO39bSZX726u4JqnDsK3MDXcO01JxXK2tZtJbgQChxgaFzEVdHRjaDoxaOu8hHOO8NYhwdxw9BzvgkvLUlpbDNUuDoc4E4wxDToV')
  109. bc_info = self._download_json(req, user)
  110. m3u8_url = next(source['src'] for source in bc_info['sources'] if source['container'] == 'M2TS')
  111. formats = self._extract_m3u8_formats(m3u8_url, user, ext='mp4')
  112. self._sort_formats(formats)
  113. return {
  114. 'id': info['id'],
  115. 'title': self._live_title(info['title']),
  116. 'uploader_id': user,
  117. 'formats': formats,
  118. 'is_live': True,
  119. 'thumbnail': bc_info['poster'],
  120. }