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.

128 lines
4.8 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|\.com(?:/[^/]+)?(?:/tv)?)(?:/events/[^/]+)?/(?:videos?|live)/(?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. 'url': 'https://www.redbull.com/int-en/tv/video/AP-1UWHCAR9S1W11/rob-meets-sam-gaze?playlist=playlists::3f81040a-2f31-4832-8e2e-545b1d39d173',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'https://www.redbull.com/us-en/videos/AP-1YM9QCYE52111',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'https://www.redbull.com/us-en/events/AP-1XV2K61Q51W11/live/AP-1XUJ86FDH1W11',
  43. 'only_matching': True,
  44. }]
  45. def _real_extract(self, url):
  46. video_id = self._match_id(url)
  47. session = self._download_json(
  48. 'https://api.redbull.tv/v3/session', video_id,
  49. note='Downloading access token', query={
  50. 'category': 'personal_computer',
  51. 'os_family': 'http',
  52. })
  53. if session.get('code') == 'error':
  54. raise ExtractorError('%s said: %s' % (
  55. self.IE_NAME, session['message']))
  56. token = session['token']
  57. try:
  58. video = self._download_json(
  59. 'https://api.redbull.tv/v3/products/' + video_id,
  60. video_id, note='Downloading video information',
  61. headers={'Authorization': token}
  62. )
  63. except ExtractorError as e:
  64. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  65. error_message = self._parse_json(
  66. e.cause.read().decode(), video_id)['error']
  67. raise ExtractorError('%s said: %s' % (
  68. self.IE_NAME, error_message), expected=True)
  69. raise
  70. title = video['title'].strip()
  71. formats = self._extract_m3u8_formats(
  72. 'https://dms.redbull.tv/v3/%s/%s/playlist.m3u8' % (video_id, token),
  73. video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
  74. self._sort_formats(formats)
  75. subtitles = {}
  76. for resource in video.get('resources', []):
  77. if resource.startswith('closed_caption_'):
  78. splitted_resource = resource.split('_')
  79. if splitted_resource[2]:
  80. subtitles.setdefault('en', []).append({
  81. 'url': 'https://resources.redbull.tv/%s/%s' % (video_id, resource),
  82. 'ext': splitted_resource[2],
  83. })
  84. subheading = video.get('subheading')
  85. if subheading:
  86. title += ' - %s' % subheading
  87. return {
  88. 'id': video_id,
  89. 'title': title,
  90. 'description': video.get('long_description') or video.get(
  91. 'short_description'),
  92. 'duration': float_or_none(video.get('duration'), scale=1000),
  93. 'formats': formats,
  94. 'subtitles': subtitles,
  95. }
  96. class RedBullTVRrnContentIE(InfoExtractor):
  97. _VALID_URL = r'https?://(?:www\.)?redbull(?:\.tv|\.com(?:/[^/]+)?(?:/tv)?)/(?:video|live)/rrn:content:[^:]+:(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
  98. _TESTS = [{
  99. 'url': 'https://www.redbull.com/int-en/tv/video/rrn:content:live-videos:e3e6feb4-e95f-50b7-962a-c70f8fd13c73/mens-dh-finals-fort-william',
  100. 'only_matching': True,
  101. }, {
  102. 'url': 'https://www.redbull.com/int-en/tv/video/rrn:content:videos:a36a0f36-ff1b-5db8-a69d-ee11a14bf48b/tn-ts-style?playlist=rrn:content:event-profiles:83f05926-5de8-5389-b5e4-9bb312d715e8:extras',
  103. 'only_matching': True,
  104. }]
  105. def _real_extract(self, url):
  106. display_id = self._match_id(url)
  107. webpage = self._download_webpage(url, display_id)
  108. video_url = self._og_search_url(webpage)
  109. return self.url_result(
  110. video_url, ie=RedBullTVIE.ie_key(),
  111. video_id=RedBullTVIE._match_id(video_url))