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.

97 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_HTTPError
  5. from ..utils import (
  6. float_or_none,
  7. ExtractorError,
  8. )
  9. class RedBullTVIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?redbull\.tv/video/(?P<id>AP-\w+)'
  11. _TESTS = [{
  12. # film
  13. 'url': 'https://www.redbull.tv/video/AP-1Q6XCDTAN1W11',
  14. 'md5': 'fb0445b98aa4394e504b413d98031d1f',
  15. 'info_dict': {
  16. 'id': 'AP-1Q6XCDTAN1W11',
  17. 'ext': 'mp4',
  18. 'title': 'ABC of... WRC - ABC of... S1E6',
  19. 'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31',
  20. 'duration': 1582.04,
  21. },
  22. }, {
  23. # episode
  24. 'url': 'https://www.redbull.tv/video/AP-1PMHKJFCW1W11',
  25. 'info_dict': {
  26. 'id': 'AP-1PMHKJFCW1W11',
  27. 'ext': 'mp4',
  28. 'title': 'Grime - Hashtags S2E4',
  29. 'description': 'md5:b5f522b89b72e1e23216e5018810bb25',
  30. 'duration': 904.6,
  31. },
  32. 'params': {
  33. 'skip_download': True,
  34. },
  35. }]
  36. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. session = self._download_json(
  39. 'https://api.redbull.tv/v3/session', video_id,
  40. note='Downloading access token', query={
  41. 'category': 'personal_computer',
  42. 'os_family': 'http',
  43. })
  44. if session.get('code') == 'error':
  45. raise ExtractorError('%s said: %s' % (
  46. self.IE_NAME, session['message']))
  47. token = session['token']
  48. try:
  49. video = self._download_json(
  50. 'https://api.redbull.tv/v3/products/' + video_id,
  51. video_id, note='Downloading video information',
  52. headers={'Authorization': token}
  53. )
  54. except ExtractorError as e:
  55. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  56. error_message = self._parse_json(
  57. e.cause.read().decode(), video_id)['error']
  58. raise ExtractorError('%s said: %s' % (
  59. self.IE_NAME, error_message), expected=True)
  60. raise
  61. title = video['title'].strip()
  62. formats = self._extract_m3u8_formats(
  63. 'https://dms.redbull.tv/v3/%s/%s/playlist.m3u8' % (video_id, token),
  64. video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
  65. self._sort_formats(formats)
  66. subtitles = {}
  67. for resource in video.get('resources', []):
  68. if resource.startswith('closed_caption_'):
  69. splitted_resource = resource.split('_')
  70. if splitted_resource[2]:
  71. subtitles.setdefault('en', []).append({
  72. 'url': 'https://resources.redbull.tv/%s/%s' % (video_id, resource),
  73. 'ext': splitted_resource[2],
  74. })
  75. subheading = video.get('subheading')
  76. if subheading:
  77. title += ' - %s' % subheading
  78. return {
  79. 'id': video_id,
  80. 'title': title,
  81. 'description': video.get('long_description') or video.get(
  82. 'short_description'),
  83. 'duration': float_or_none(video.get('duration'), scale=1000),
  84. 'formats': formats,
  85. 'subtitles': subtitles,
  86. }