logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

redbulltv.py (9332B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_HTTPError
  6. from ..utils import (
  7. float_or_none,
  8. ExtractorError,
  9. )
  10. class RedBullTVIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?redbull(?:\.tv|\.com(?:/[^/]+)?(?:/tv)?)(?:/events/[^/]+)?/(?:videos?|live|(?:film|episode)s)/(?P<id>AP-\w+)'
  12. _TESTS = [{
  13. # film
  14. 'url': 'https://www.redbull.tv/video/AP-1Q6XCDTAN1W11',
  15. 'md5': 'fb0445b98aa4394e504b413d98031d1f',
  16. 'info_dict': {
  17. 'id': 'AP-1Q6XCDTAN1W11',
  18. 'ext': 'mp4',
  19. 'title': 'ABC of... WRC - ABC of... S1E6',
  20. 'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31',
  21. 'duration': 1582.04,
  22. },
  23. }, {
  24. # episode
  25. 'url': 'https://www.redbull.tv/video/AP-1PMHKJFCW1W11',
  26. 'info_dict': {
  27. 'id': 'AP-1PMHKJFCW1W11',
  28. 'ext': 'mp4',
  29. 'title': 'Grime - Hashtags S2E4',
  30. 'description': 'md5:5546aa612958c08a98faaad4abce484d',
  31. 'duration': 904,
  32. },
  33. 'params': {
  34. 'skip_download': True,
  35. },
  36. }, {
  37. 'url': 'https://www.redbull.com/int-en/tv/video/AP-1UWHCAR9S1W11/rob-meets-sam-gaze?playlist=playlists::3f81040a-2f31-4832-8e2e-545b1d39d173',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'https://www.redbull.com/us-en/videos/AP-1YM9QCYE52111',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'https://www.redbull.com/us-en/events/AP-1XV2K61Q51W11/live/AP-1XUJ86FDH1W11',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'https://www.redbull.com/int-en/films/AP-1ZSMAW8FH2111',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'https://www.redbull.com/int-en/episodes/AP-1TQWK7XE11W11',
  50. 'only_matching': True,
  51. }]
  52. def extract_info(self, video_id):
  53. session = self._download_json(
  54. 'https://api.redbull.tv/v3/session', video_id,
  55. note='Downloading access token', query={
  56. 'category': 'personal_computer',
  57. 'os_family': 'http',
  58. })
  59. if session.get('code') == 'error':
  60. raise ExtractorError('%s said: %s' % (
  61. self.IE_NAME, session['message']))
  62. token = session['token']
  63. try:
  64. video = self._download_json(
  65. 'https://api.redbull.tv/v3/products/' + video_id,
  66. video_id, note='Downloading video information',
  67. headers={'Authorization': token}
  68. )
  69. except ExtractorError as e:
  70. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
  71. error_message = self._parse_json(
  72. e.cause.read().decode(), video_id)['error']
  73. raise ExtractorError('%s said: %s' % (
  74. self.IE_NAME, error_message), expected=True)
  75. raise
  76. title = video['title'].strip()
  77. formats = self._extract_m3u8_formats(
  78. 'https://dms.redbull.tv/v3/%s/%s/playlist.m3u8' % (video_id, token),
  79. video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
  80. self._sort_formats(formats)
  81. subtitles = {}
  82. for resource in video.get('resources', []):
  83. if resource.startswith('closed_caption_'):
  84. splitted_resource = resource.split('_')
  85. if splitted_resource[2]:
  86. subtitles.setdefault('en', []).append({
  87. 'url': 'https://resources.redbull.tv/%s/%s' % (video_id, resource),
  88. 'ext': splitted_resource[2],
  89. })
  90. subheading = video.get('subheading')
  91. if subheading:
  92. title += ' - %s' % subheading
  93. return {
  94. 'id': video_id,
  95. 'title': title,
  96. 'description': video.get('long_description') or video.get(
  97. 'short_description'),
  98. 'duration': float_or_none(video.get('duration'), scale=1000),
  99. 'formats': formats,
  100. 'subtitles': subtitles,
  101. }
  102. def _real_extract(self, url):
  103. video_id = self._match_id(url)
  104. return self.extract_info(video_id)
  105. class RedBullEmbedIE(RedBullTVIE):
  106. _VALID_URL = r'https?://(?:www\.)?redbull\.com/embed/(?P<id>rrn:content:[^:]+:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}:[a-z]{2}-[A-Z]{2,3})'
  107. _TESTS = [{
  108. # HLS manifest accessible only using assetId
  109. 'url': 'https://www.redbull.com/embed/rrn:content:episode-videos:f3021f4f-3ed4-51ac-915a-11987126e405:en-INT',
  110. 'only_matching': True,
  111. }]
  112. _VIDEO_ESSENSE_TMPL = '''... on %s {
  113. videoEssence {
  114. attributes
  115. }
  116. }'''
  117. def _real_extract(self, url):
  118. rrn_id = self._match_id(url)
  119. asset_id = self._download_json(
  120. 'https://edge-graphql.crepo-production.redbullaws.com/v1/graphql',
  121. rrn_id, headers={
  122. 'Accept': 'application/json',
  123. 'API-KEY': 'e90a1ff11335423998b100c929ecc866',
  124. }, query={
  125. 'query': '''{
  126. resource(id: "%s", enforceGeoBlocking: false) {
  127. %s
  128. %s
  129. }
  130. }''' % (rrn_id, self._VIDEO_ESSENSE_TMPL % 'LiveVideo', self._VIDEO_ESSENSE_TMPL % 'VideoResource'),
  131. })['data']['resource']['videoEssence']['attributes']['assetId']
  132. return self.extract_info(asset_id)
  133. class RedBullTVRrnContentIE(InfoExtractor):
  134. _VALID_URL = r'https?://(?:www\.)?redbull\.com/(?P<region>[a-z]{2,3})-(?P<lang>[a-z]{2})/tv/(?:video|live|film)/(?P<id>rrn:content:[^:]+:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
  135. _TESTS = [{
  136. 'url': 'https://www.redbull.com/int-en/tv/video/rrn:content:live-videos:e3e6feb4-e95f-50b7-962a-c70f8fd13c73/mens-dh-finals-fort-william',
  137. 'only_matching': True,
  138. }, {
  139. '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',
  140. 'only_matching': True,
  141. }, {
  142. 'url': 'https://www.redbull.com/int-en/tv/film/rrn:content:films:d1f4d00e-4c04-5d19-b510-a805ffa2ab83/follow-me',
  143. 'only_matching': True,
  144. }]
  145. def _real_extract(self, url):
  146. region, lang, rrn_id = re.search(self._VALID_URL, url).groups()
  147. rrn_id += ':%s-%s' % (lang, region.upper())
  148. return self.url_result(
  149. 'https://www.redbull.com/embed/' + rrn_id,
  150. RedBullEmbedIE.ie_key(), rrn_id)
  151. class RedBullIE(InfoExtractor):
  152. _VALID_URL = r'https?://(?:www\.)?redbull\.com/(?P<region>[a-z]{2,3})-(?P<lang>[a-z]{2})/(?P<type>(?:episode|film|(?:(?:recap|trailer)-)?video)s|live)/(?!AP-|rrn:content:)(?P<id>[^/?#&]+)'
  153. _TESTS = [{
  154. 'url': 'https://www.redbull.com/int-en/episodes/grime-hashtags-s02-e04',
  155. 'md5': 'db8271a7200d40053a1809ed0dd574ff',
  156. 'info_dict': {
  157. 'id': 'AA-1MT8DQWA91W14',
  158. 'ext': 'mp4',
  159. 'title': 'Grime - Hashtags S2E4',
  160. 'description': 'md5:5546aa612958c08a98faaad4abce484d',
  161. },
  162. }, {
  163. 'url': 'https://www.redbull.com/int-en/films/kilimanjaro-mountain-of-greatness',
  164. 'only_matching': True,
  165. }, {
  166. 'url': 'https://www.redbull.com/int-en/recap-videos/uci-mountain-bike-world-cup-2017-mens-xco-finals-from-vallnord',
  167. 'only_matching': True,
  168. }, {
  169. 'url': 'https://www.redbull.com/int-en/trailer-videos/kings-of-content',
  170. 'only_matching': True,
  171. }, {
  172. 'url': 'https://www.redbull.com/int-en/videos/tnts-style-red-bull-dance-your-style-s1-e12',
  173. 'only_matching': True,
  174. }, {
  175. 'url': 'https://www.redbull.com/int-en/live/mens-dh-finals-fort-william',
  176. 'only_matching': True,
  177. }, {
  178. # only available on the int-en website so a fallback is need for the API
  179. # https://www.redbull.com/v3/api/graphql/v1/v3/query/en-GB>en-INT?filter[uriSlug]=fia-wrc-saturday-recap-estonia&rb3Schema=v1:hero
  180. 'url': 'https://www.redbull.com/gb-en/live/fia-wrc-saturday-recap-estonia',
  181. 'only_matching': True,
  182. }]
  183. _INT_FALLBACK_LIST = ['de', 'en', 'es', 'fr']
  184. _LAT_FALLBACK_MAP = ['ar', 'bo', 'car', 'cl', 'co', 'mx', 'pe']
  185. def _real_extract(self, url):
  186. region, lang, filter_type, display_id = re.search(self._VALID_URL, url).groups()
  187. if filter_type == 'episodes':
  188. filter_type = 'episode-videos'
  189. elif filter_type == 'live':
  190. filter_type = 'live-videos'
  191. regions = [region.upper()]
  192. if region != 'int':
  193. if region in self._LAT_FALLBACK_MAP:
  194. regions.append('LAT')
  195. if lang in self._INT_FALLBACK_LIST:
  196. regions.append('INT')
  197. locale = '>'.join(['%s-%s' % (lang, reg) for reg in regions])
  198. rrn_id = self._download_json(
  199. 'https://www.redbull.com/v3/api/graphql/v1/v3/query/' + locale,
  200. display_id, query={
  201. 'filter[type]': filter_type,
  202. 'filter[uriSlug]': display_id,
  203. 'rb3Schema': 'v1:hero',
  204. })['data']['id']
  205. return self.url_result(
  206. 'https://www.redbull.com/embed/' + rrn_id,
  207. RedBullEmbedIE.ie_key(), rrn_id)