mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 02:42:30 +00:00
[redbull] improve extraction
- extract 1080p quality - correct ttml subtitle ext - catch api errors - reduce request size
This commit is contained in:
parent
5db83d79bf
commit
ba448445b8
@ -2,11 +2,13 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..compat import compat_HTTPError
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
float_or_none,
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
try_get,
|
try_get,
|
||||||
unified_timestamp,
|
# unified_timestamp,
|
||||||
|
ExtractorError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -15,15 +17,15 @@ class RedBullTVIE(InfoExtractor):
|
|||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
# film
|
# film
|
||||||
'url': 'https://www.redbull.tv/video/AP-1Q756YYX51W11/abc-of-wrc',
|
'url': 'https://www.redbull.tv/video/AP-1Q756YYX51W11/abc-of-wrc',
|
||||||
'md5': '78e860f631d7a846e712fab8c5fe2c38',
|
'md5': 'fb0445b98aa4394e504b413d98031d1f',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'AP-1Q756YYX51W11',
|
'id': 'AP-1Q756YYX51W11',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'ABC of...WRC',
|
'title': 'ABC of...WRC',
|
||||||
'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31',
|
'description': 'md5:5c7ed8f4015c8492ecf64b6ab31e7d31',
|
||||||
'duration': 1582.04,
|
'duration': 1582.04,
|
||||||
'timestamp': 1488405786,
|
# 'timestamp': 1488405786,
|
||||||
'upload_date': '20170301',
|
# 'upload_date': '20170301',
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
# episode
|
# episode
|
||||||
@ -34,8 +36,8 @@ class RedBullTVIE(InfoExtractor):
|
|||||||
'title': 'Grime - Hashtags S2 E4',
|
'title': 'Grime - Hashtags S2 E4',
|
||||||
'description': 'md5:334b741c8c1ce65be057eab6773c1cf5',
|
'description': 'md5:334b741c8c1ce65be057eab6773c1cf5',
|
||||||
'duration': 904.6,
|
'duration': 904.6,
|
||||||
'timestamp': 1487290093,
|
# 'timestamp': 1487290093,
|
||||||
'upload_date': '20170217',
|
# 'upload_date': '20170217',
|
||||||
'series': 'Hashtags',
|
'series': 'Hashtags',
|
||||||
'season_number': 2,
|
'season_number': 2,
|
||||||
'episode_number': 4,
|
'episode_number': 4,
|
||||||
@ -48,29 +50,40 @@ class RedBullTVIE(InfoExtractor):
|
|||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
access_token = self._download_json(
|
session = self._download_json(
|
||||||
'https://api-v2.redbull.tv/start', video_id,
|
'https://api-v2.redbull.tv/session', video_id,
|
||||||
note='Downloading access token', query={
|
note='Downloading access token', query={
|
||||||
'build': '4.0.9',
|
'build': '4.370.0',
|
||||||
'category': 'smartphone',
|
'category': 'personal_computer',
|
||||||
'os_version': 23,
|
'os_version': '1.0',
|
||||||
'os_family': 'android',
|
'os_family': 'http',
|
||||||
})['auth']['access_token']
|
})
|
||||||
|
if session.get('code') == 'error':
|
||||||
|
raise ExtractorError('%s said: %s' % (
|
||||||
|
self.IE_NAME, session['message']))
|
||||||
|
auth = '%s %s' % (session.get('token_type', 'Bearer'), session['access_token'])
|
||||||
|
|
||||||
info = self._download_json(
|
try:
|
||||||
'https://api-v2.redbull.tv/views/%s' % video_id,
|
info = self._download_json(
|
||||||
video_id, note='Downloading video information',
|
'https://api-v2.redbull.tv/content/%s' % video_id,
|
||||||
headers={'Authorization': 'Bearer ' + access_token}
|
video_id, note='Downloading video information',
|
||||||
)['blocks'][0]['top'][0]
|
headers={'Authorization': auth}
|
||||||
|
)
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, compat_HTTPError) and e.cause.code == 404:
|
||||||
|
error_message = self._parse_json(
|
||||||
|
e.cause.read().decode(), video_id)['message']
|
||||||
|
raise ExtractorError('%s said: %s' % (
|
||||||
|
self.IE_NAME, error_message), expected=True)
|
||||||
|
raise
|
||||||
|
|
||||||
video = info['video_product']
|
video = info['video_product']
|
||||||
|
|
||||||
title = info['title'].strip()
|
title = info['title'].strip()
|
||||||
m3u8_url = video['url']
|
|
||||||
|
|
||||||
formats = self._extract_m3u8_formats(
|
formats = self._extract_m3u8_formats(
|
||||||
m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
video['url'], video_id, 'mp4', 'm3u8_native')
|
||||||
m3u8_id='hls')
|
self._sort_formats(formats)
|
||||||
|
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
for _, captions in (try_get(
|
for _, captions in (try_get(
|
||||||
@ -82,9 +95,12 @@ def _real_extract(self, url):
|
|||||||
caption_url = caption.get('url')
|
caption_url = caption.get('url')
|
||||||
if not caption_url:
|
if not caption_url:
|
||||||
continue
|
continue
|
||||||
|
ext = caption.get('format')
|
||||||
|
if ext == 'xml':
|
||||||
|
ext = 'ttml'
|
||||||
subtitles.setdefault(caption.get('lang') or 'en', []).append({
|
subtitles.setdefault(caption.get('lang') or 'en', []).append({
|
||||||
'url': caption_url,
|
'url': caption_url,
|
||||||
'ext': caption.get('format'),
|
'ext': ext,
|
||||||
})
|
})
|
||||||
|
|
||||||
subheading = info.get('subheading')
|
subheading = info.get('subheading')
|
||||||
@ -97,7 +113,7 @@ def _real_extract(self, url):
|
|||||||
'description': info.get('long_description') or info.get(
|
'description': info.get('long_description') or info.get(
|
||||||
'short_description'),
|
'short_description'),
|
||||||
'duration': float_or_none(video.get('duration'), scale=1000),
|
'duration': float_or_none(video.get('duration'), scale=1000),
|
||||||
'timestamp': unified_timestamp(info.get('published')),
|
# 'timestamp': unified_timestamp(info.get('published')),
|
||||||
'series': info.get('show_title'),
|
'series': info.get('show_title'),
|
||||||
'season_number': int_or_none(info.get('season_number')),
|
'season_number': int_or_none(info.get('season_number')),
|
||||||
'episode_number': int_or_none(info.get('episode_number')),
|
'episode_number': int_or_none(info.get('episode_number')),
|
||||||
|
Loading…
Reference in New Issue
Block a user