2021-09-07 17:35:27 +00:00
|
|
|
from .common import InfoExtractor
|
2024-07-31 01:50:20 +00:00
|
|
|
from ..networking.exceptions import HTTPError
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
int_or_none,
|
|
|
|
parse_iso8601,
|
2024-08-01 20:25:46 +00:00
|
|
|
parse_qs,
|
2024-07-31 01:50:20 +00:00
|
|
|
try_get,
|
2024-08-01 20:25:46 +00:00
|
|
|
update_url,
|
2024-07-31 01:50:20 +00:00
|
|
|
url_or_none,
|
|
|
|
)
|
|
|
|
from ..utils.traversal import traverse_obj
|
2021-09-07 17:35:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OlympicsReplayIE(InfoExtractor):
|
2024-07-31 01:50:20 +00:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?olympics\.com/[a-z]{2}/(?:paris-2024/)?(?:replay|videos?|original-series/episode)/(?P<id>[\w-]+)'
|
2021-09-07 17:35:27 +00:00
|
|
|
_TESTS = [{
|
2021-10-31 05:10:42 +00:00
|
|
|
'url': 'https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays',
|
2021-09-07 17:35:27 +00:00
|
|
|
'info_dict': {
|
2021-10-31 05:10:42 +00:00
|
|
|
'id': 'f6a0753c-8e6f-4b7d-a435-027054a4f8e9',
|
2021-09-07 17:35:27 +00:00
|
|
|
'ext': 'mp4',
|
2021-10-31 05:10:42 +00:00
|
|
|
'title': '+109kg (H) Groupe A - Haltérophilie | Replay de Tokyo 2020',
|
|
|
|
'upload_date': '20210801',
|
2024-07-31 01:50:20 +00:00
|
|
|
'timestamp': 1627797600,
|
2021-10-31 05:10:42 +00:00
|
|
|
'description': 'md5:c66af4a5bc7429dbcc43d15845ff03b3',
|
2024-07-31 01:50:20 +00:00
|
|
|
'thumbnail': 'https://img.olympics.com/images/image/private/t_1-1_1280/primary/nua4o7zwyaznoaejpbk2',
|
|
|
|
'duration': 7017.0,
|
2021-09-07 17:35:27 +00:00
|
|
|
},
|
|
|
|
}, {
|
2024-07-31 01:50:20 +00:00
|
|
|
'url': 'https://olympics.com/en/original-series/episode/b-boys-and-b-girls-take-the-spotlight-breaking-life-road-to-paris-2024',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '32633650-c5ee-4280-8b94-fb6defb6a9b5',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'B-girl Nicka - Breaking Life, Road to Paris 2024 | Episode 1',
|
|
|
|
'upload_date': '20240517',
|
|
|
|
'timestamp': 1715948200,
|
|
|
|
'description': 'md5:f63d728a41270ec628f6ac33ce471bb1',
|
|
|
|
'thumbnail': 'https://img.olympics.com/images/image/private/t_1-1_1280/primary/a3j96l7j6so3vyfijby1',
|
|
|
|
'duration': 1321.0,
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
'url': 'https://olympics.com/en/paris-2024/videos/men-s-preliminaries-gbr-esp-ned-rsa-hockey-olympic-games-paris-2024',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '3d96db23-8eee-4b7c-8ef5-488a0361026c',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Men\'s Preliminaries GBR-ESP & NED-RSA | Hockey | Olympic Games Paris 2024',
|
|
|
|
'upload_date': '20240727',
|
|
|
|
'timestamp': 1722066600,
|
|
|
|
},
|
|
|
|
'skip': 'Geo-restricted to RU, BR, BT, NP, TM, BD, TL',
|
|
|
|
}, {
|
|
|
|
'url': 'https://olympics.com/en/paris-2024/videos/dnp-suni-lee-i-have-goals-and-i-have-expectations-for-myself-but-i-also-am-trying-to-give-myself-grace',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'a42f37ab-8a74-41d0-a7d9-af27b7b02a90',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'md5:c7cfbc9918636a98e66400a812e4d407',
|
|
|
|
'upload_date': '20240729',
|
|
|
|
'timestamp': 1722288600,
|
|
|
|
},
|
2021-09-07 17:35:27 +00:00
|
|
|
}]
|
2024-07-31 01:50:20 +00:00
|
|
|
_GEO_BYPASS = False
|
|
|
|
|
|
|
|
def _extract_from_nextjs_data(self, webpage, video_id):
|
|
|
|
data = traverse_obj(self._search_nextjs_data(webpage, video_id, default={}), (
|
|
|
|
'props', 'pageProps', 'page', 'items',
|
|
|
|
lambda _, v: v['name'] == 'videoPlaylist', 'data', 'currentVideo', {dict}, any))
|
|
|
|
if not data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
geo_countries = traverse_obj(data, ('countries', ..., {str}))
|
|
|
|
if traverse_obj(data, ('geoRestrictedVideo', {bool})):
|
|
|
|
self.raise_geo_restricted(countries=geo_countries)
|
|
|
|
|
|
|
|
is_live = traverse_obj(data, ('streamingStatus', {str})) == 'LIVE'
|
|
|
|
m3u8_url = traverse_obj(data, ('videoUrl', {url_or_none})) or data['streamUrl']
|
2024-08-01 20:25:46 +00:00
|
|
|
tokenized_url = self._tokenize_url(m3u8_url, data['jwtToken'], is_live, video_id)
|
2024-07-31 01:50:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
|
|
|
tokenized_url, video_id, 'mp4', m3u8_id='hls')
|
|
|
|
except ExtractorError as e:
|
|
|
|
if isinstance(e.cause, HTTPError) and 'georestricted' in e.cause.msg:
|
|
|
|
self.raise_geo_restricted(countries=geo_countries)
|
|
|
|
raise
|
|
|
|
|
|
|
|
return {
|
|
|
|
'formats': formats,
|
|
|
|
'subtitles': subtitles,
|
|
|
|
'is_live': is_live,
|
|
|
|
**traverse_obj(data, {
|
|
|
|
'id': ('videoID', {str}),
|
|
|
|
'title': ('title', {str}),
|
|
|
|
'timestamp': ('contentDate', {parse_iso8601}),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
2024-08-01 20:25:46 +00:00
|
|
|
def _tokenize_url(self, url, token, is_live, video_id):
|
|
|
|
return self._download_json(
|
|
|
|
'https://metering.olympics.com/tokengenerator', video_id,
|
|
|
|
'Downloading tokenized m3u8 url', query={
|
|
|
|
**parse_qs(url),
|
|
|
|
'url': update_url(url, query=None),
|
|
|
|
'service-id': 'live' if is_live else 'vod',
|
|
|
|
'user-auth': token,
|
|
|
|
})['data']['url']
|
|
|
|
|
|
|
|
def _legacy_tokenize_url(self, url, video_id):
|
2024-07-31 01:50:20 +00:00
|
|
|
return self._download_json(
|
|
|
|
'https://olympics.com/tokenGenerator', video_id,
|
2024-08-01 20:25:46 +00:00
|
|
|
'Downloading legacy tokenized m3u8 url', query={'url': url})
|
2021-09-07 17:35:27 +00:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-06-11 23:09:58 +00:00
|
|
|
video_id = self._match_id(url)
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
2024-07-31 01:50:20 +00:00
|
|
|
|
|
|
|
if info := self._extract_from_nextjs_data(webpage, video_id):
|
|
|
|
return info
|
|
|
|
|
2021-10-31 05:10:42 +00:00
|
|
|
title = self._html_search_meta(('title', 'og:title', 'twitter:title'), webpage)
|
2024-07-31 01:50:20 +00:00
|
|
|
video_uuid = self._html_search_meta('episode_uid', webpage)
|
2021-10-31 05:10:42 +00:00
|
|
|
m3u8_url = self._html_search_meta('video_url', webpage)
|
2024-07-31 01:50:20 +00:00
|
|
|
json_ld = self._search_json_ld(webpage, video_uuid)
|
2021-10-31 05:10:42 +00:00
|
|
|
thumbnails_list = json_ld.get('image')
|
|
|
|
if not thumbnails_list:
|
|
|
|
thumbnails_list = self._html_search_regex(
|
|
|
|
r'["\']image["\']:\s*["\']([^"\']+)["\']', webpage, 'images', default='')
|
|
|
|
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,
|
2024-06-11 23:09:58 +00:00
|
|
|
'height': int_or_none(try_get(width, lambda x: x * height_a / width_a)),
|
2021-10-31 05:10:42 +00:00
|
|
|
})
|
2024-07-31 01:50:20 +00:00
|
|
|
|
|
|
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
2024-08-01 20:25:46 +00:00
|
|
|
self._legacy_tokenize_url(m3u8_url, video_uuid), video_uuid, 'mp4', m3u8_id='hls')
|
2021-09-07 17:35:27 +00:00
|
|
|
|
|
|
|
return {
|
2024-07-31 01:50:20 +00:00
|
|
|
'id': video_uuid,
|
2021-10-31 05:10:42 +00:00
|
|
|
'title': title,
|
|
|
|
'thumbnails': thumbnails,
|
2021-09-07 17:35:27 +00:00
|
|
|
'formats': formats,
|
|
|
|
'subtitles': subtitles,
|
2024-06-11 23:09:58 +00:00
|
|
|
**json_ld,
|
2021-09-07 17:35:27 +00:00
|
|
|
}
|