mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-23 02:26:37 -05:00
parent
2f9e021299
commit
b2f25dc242
@ -2,22 +2,27 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import unified_strdate
|
from ..utils import (
|
||||||
|
int_or_none,
|
||||||
|
try_get
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OlympicsReplayIE(InfoExtractor):
|
class OlympicsReplayIE(InfoExtractor):
|
||||||
_VALID_URL = r'(?:https?://)(?:www\.)?olympics\.com/tokyo-2020/(?:[a-z]{2}/)?replay/(?P<id>[^/#&?]+)'
|
_VALID_URL = r'https?://(?:www\.)?olympics\.com(?:/tokyo-2020)?/[a-z]{2}/(?:replay|video)/(?P<id>[^/#&?]+)'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://olympics.com/tokyo-2020/en/replay/300622eb-abc0-43ea-b03b-c5f2d429ec7b/jumping-team-qualifier',
|
'url': 'https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '300622eb-abc0-43ea-b03b-c5f2d429ec7b',
|
'id': 'f6a0753c-8e6f-4b7d-a435-027054a4f8e9',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Jumping Team Qualifier',
|
'title': '+109kg (H) Groupe A - Haltérophilie | Replay de Tokyo 2020',
|
||||||
'release_date': '20210806',
|
'upload_date': '20210801',
|
||||||
'upload_date': '20210713',
|
'timestamp': 1627783200,
|
||||||
|
'description': 'md5:c66af4a5bc7429dbcc43d15845ff03b3',
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'format': 'bv',
|
'format': 'bestvideo',
|
||||||
|
'skip_download': True,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://olympics.com/tokyo-2020/en/replay/bd242924-4b22-49a5-a846-f1d4c809250d/mens-bronze-medal-match-hun-esp',
|
'url': 'https://olympics.com/tokyo-2020/en/replay/bd242924-4b22-49a5-a846-f1d4c809250d/mens-bronze-medal-match-hun-esp',
|
||||||
@ -26,31 +31,41 @@ class OlympicsReplayIE(InfoExtractor):
|
|||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
id = self._match_id(url)
|
id = self._match_id(url)
|
||||||
# The parameters are hardcoded in the webpage, it's not necessary to download the webpage just for these parameters.
|
|
||||||
# If in downloading webpage serves other functions aswell, then extract these parameters from it.
|
webpage = self._download_webpage(url, id)
|
||||||
token_url = 'https://appovptok.ovpobs.tv/api/identity/app/token?api_key=OTk5NDcxOjpvY3N3LWFwaXVzZXI%3D&api_secret=ODY4ODM2MjE3ODMwYmVjNTAxMWZlMDJiMTYxZmY0MjFiMjMwMjllMjJmNDA1YWRiYzA5ODcxYTZjZTljZDkxOTo6NTM2NWIzNjRlMTM1ZmI2YWNjNmYzMGMzOGM3NzZhZTY%3D'
|
title = self._html_search_meta(('title', 'og:title', 'twitter:title'), webpage)
|
||||||
token = self._download_webpage(token_url, id)
|
uuid = self._html_search_meta('episode_uid', webpage)
|
||||||
headers = {'x-obs-app-token': token}
|
m3u8_url = self._html_search_meta('video_url', webpage)
|
||||||
data_json = self._download_json(f'https://appocswtok.ovpobs.tv/api/schedule-sessions/{id}?include=stream',
|
json_ld = self._search_json_ld(webpage, uuid)
|
||||||
id, headers=headers)
|
thumbnails_list = json_ld.get('image')
|
||||||
meta_data = data_json['data']['attributes']
|
if not thumbnails_list:
|
||||||
for t_dict in data_json['included']:
|
thumbnails_list = self._html_search_regex(
|
||||||
if t_dict.get('type') == 'Stream':
|
r'["\']image["\']:\s*["\']([^"\']+)["\']', webpage, 'images', default='')
|
||||||
stream_data = t_dict['attributes']
|
thumbnails_list = thumbnails_list.replace('[', '').replace(']', '').split(',')
|
||||||
|
thumbnails_list = [thumbnail.strip() for thumbnail in thumbnails_list]
|
||||||
|
thumbnails = []
|
||||||
|
for thumbnail in thumbnails_list:
|
||||||
|
width_a, height_a, width = self._search_regex(
|
||||||
|
r'/images/image/private/t_(?P<width_a>\d+)-(?P<height_a>\d+)_(?P<width>\d+)/primary/[\W\w\d]+',
|
||||||
|
thumbnail, 'thumb', group=(1, 2, 3), default=(None, None, None))
|
||||||
|
width_a, height_a, width = int_or_none(width_a), int_or_none(height_a), int_or_none(width)
|
||||||
|
thumbnails.append({
|
||||||
|
'url': thumbnail,
|
||||||
|
'width': width,
|
||||||
|
'height': int_or_none(try_get(width, lambda x: x * height_a / width_a))
|
||||||
|
})
|
||||||
m3u8_url = self._download_json(
|
m3u8_url = self._download_json(
|
||||||
'https://meteringtok.ovpobs.tv/api/playback-sessions', id, headers=headers, query={
|
f'https://olympics.com/tokenGenerator?url={m3u8_url}', uuid, note='Downloading m3u8 url')
|
||||||
'alias': stream_data['alias'],
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, uuid, m3u8_id='hls')
|
||||||
'stream': stream_data['stream'],
|
|
||||||
'type': 'vod'
|
|
||||||
})['data']['attributes']['url']
|
|
||||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, id)
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': id,
|
'id': uuid,
|
||||||
'title': meta_data['title'],
|
'title': title,
|
||||||
'release_date': unified_strdate(meta_data.get('start') or meta_data.get('broadcastPublished')),
|
'timestamp': json_ld.get('timestamp'),
|
||||||
'upload_date': unified_strdate(meta_data.get('publishedAt')),
|
'description': json_ld.get('description'),
|
||||||
|
'thumbnails': thumbnails,
|
||||||
|
'duration': json_ld.get('duration'),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user