1 from .common
import InfoExtractor
2 from ..networking
.exceptions
import HTTPError
12 from ..utils
.traversal
import traverse_obj
15 class OlympicsReplayIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:www\.)?olympics\.com/[a-z]{2}/(?:paris-2024/)?(?:replay|videos?|original-series/episode)/(?P<id>[\w-]+)'
18 'url': 'https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays',
20 'id': 'f6a0753c-8e6f-4b7d-a435-027054a4f8e9',
22 'title': '+109kg (H) Groupe A - Haltérophilie | Replay de Tokyo 2020',
23 'upload_date': '20210801',
24 'timestamp': 1627797600,
25 'description': 'md5:c66af4a5bc7429dbcc43d15845ff03b3',
26 'thumbnail': 'https://img.olympics.com/images/image/private/t_1-1_1280/primary/nua4o7zwyaznoaejpbk2',
30 'url': 'https://olympics.com/en/original-series/episode/b-boys-and-b-girls-take-the-spotlight-breaking-life-road-to-paris-2024',
32 'id': '32633650-c5ee-4280-8b94-fb6defb6a9b5',
34 'title': 'B-girl Nicka - Breaking Life, Road to Paris 2024 | Episode 1',
35 'upload_date': '20240517',
36 'timestamp': 1715948200,
37 'description': 'md5:f63d728a41270ec628f6ac33ce471bb1',
38 'thumbnail': 'https://img.olympics.com/images/image/private/t_1-1_1280/primary/a3j96l7j6so3vyfijby1',
42 'url': 'https://olympics.com/en/paris-2024/videos/men-s-preliminaries-gbr-esp-ned-rsa-hockey-olympic-games-paris-2024',
44 'id': '3d96db23-8eee-4b7c-8ef5-488a0361026c',
46 'title': 'Men\'s Preliminaries GBR-ESP & NED-RSA | Hockey | Olympic Games Paris 2024',
47 'upload_date': '20240727',
48 'timestamp': 1722066600,
50 'skip': 'Geo-restricted to RU, BR, BT, NP, TM, BD, TL',
52 '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',
54 'id': 'a42f37ab-8a74-41d0-a7d9-af27b7b02a90',
56 'title': 'md5:c7cfbc9918636a98e66400a812e4d407',
57 'upload_date': '20240729',
58 'timestamp': 1722288600,
63 def _extract_from_nextjs_data(self
, webpage
, video_id
):
64 data
= traverse_obj(self
._search
_nextjs
_data
(webpage
, video_id
, default
={}), (
65 'props', 'pageProps', 'page', 'items',
66 lambda _
, v
: v
['name'] == 'videoPlaylist', 'data', 'currentVideo', {dict}
, any
))
70 geo_countries
= traverse_obj(data
, ('countries', ..., {str}
))
71 if traverse_obj(data
, ('geoRestrictedVideo', {bool}
)):
72 self
.raise_geo_restricted(countries
=geo_countries
)
74 is_live
= traverse_obj(data
, ('streamingStatus', {str}
)) == 'LIVE'
75 m3u8_url
= traverse_obj(data
, ('videoUrl', {url_or_none}
)) or data
['streamUrl']
76 tokenized_url
= self
._tokenize
_url
(m3u8_url
, data
['jwtToken'], is_live
, video_id
)
79 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(
80 tokenized_url
, video_id
, 'mp4', m3u8_id
='hls')
81 except ExtractorError
as e
:
82 if isinstance(e
.cause
, HTTPError
) and 'georestricted' in e
.cause
.msg
:
83 self
.raise_geo_restricted(countries
=geo_countries
)
88 'subtitles': subtitles
,
90 **traverse_obj(data
, {
91 'id': ('videoID', {str}
),
92 'title': ('title', {str}
),
93 'timestamp': ('contentDate', {parse_iso8601}
),
97 def _tokenize_url(self
, url
, token
, is_live
, video_id
):
98 return self
._download
_json
(
99 'https://metering.olympics.com/tokengenerator', video_id
,
100 'Downloading tokenized m3u8 url', query
={
102 'url': update_url(url
, query
=None),
103 'service-id': 'live' if is_live
else 'vod',
107 def _legacy_tokenize_url(self
, url
, video_id
):
108 return self
._download
_json
(
109 'https://olympics.com/tokenGenerator', video_id
,
110 'Downloading legacy tokenized m3u8 url', query
={'url': url
})
112 def _real_extract(self
, url
):
113 video_id
= self
._match
_id
(url
)
114 webpage
= self
._download
_webpage
(url
, video_id
)
116 if info
:= self
._extract
_from
_nextjs
_data
(webpage
, video_id
):
119 title
= self
._html
_search
_meta
(('title', 'og:title', 'twitter:title'), webpage
)
120 video_uuid
= self
._html
_search
_meta
('episode_uid', webpage
)
121 m3u8_url
= self
._html
_search
_meta
('video_url', webpage
)
122 json_ld
= self
._search
_json
_ld
(webpage
, video_uuid
)
123 thumbnails_list
= json_ld
.get('image')
124 if not thumbnails_list
:
125 thumbnails_list
= self
._html
_search
_regex
(
126 r
'["\']image
["\']:\s*["\']([^
"\']+)["\']', webpage, 'images
', default='')
127 thumbnails_list = thumbnails_list.replace('[', '').replace(']', '').split(',')
128 thumbnails_list = [thumbnail.strip() for thumbnail in thumbnails_list]
130 for thumbnail in thumbnails_list:
131 width_a, height_a, width = self._search_regex(
132 r'/images
/image
/private
/t_(?P
<width_a
>\d
+)-(?P
<height_a
>\d
+)_(?P
<width
>\d
+)/primary
/[\W\w\d
]+',
133 thumbnail, 'thumb
', group=(1, 2, 3), default=(None, None, None))
134 width_a, height_a, width = int_or_none(width_a), int_or_none(height_a), int_or_none(width)
138 'height
': int_or_none(try_get(width, lambda x: x * height_a / width_a)),
141 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
142 self._legacy_tokenize_url(m3u8_url, video_uuid), video_uuid, 'mp4
', m3u8_id='hls
')
147 'thumbnails
': thumbnails,
149 'subtitles
': subtitles,