]>
Commit | Line | Data |
---|---|---|
71407b3e | 1 | from .common import InfoExtractor |
b2f25dc2 | 2 | from ..utils import ( |
3 | int_or_none, | |
4 | try_get | |
5 | ) | |
71407b3e A |
6 | |
7 | ||
8 | class OlympicsReplayIE(InfoExtractor): | |
b2f25dc2 | 9 | _VALID_URL = r'https?://(?:www\.)?olympics\.com(?:/tokyo-2020)?/[a-z]{2}/(?:replay|video)/(?P<id>[^/#&?]+)' |
71407b3e | 10 | _TESTS = [{ |
b2f25dc2 | 11 | 'url': 'https://olympics.com/fr/video/men-s-109kg-group-a-weightlifting-tokyo-2020-replays', |
71407b3e | 12 | 'info_dict': { |
b2f25dc2 | 13 | 'id': 'f6a0753c-8e6f-4b7d-a435-027054a4f8e9', |
71407b3e | 14 | 'ext': 'mp4', |
b2f25dc2 | 15 | 'title': '+109kg (H) Groupe A - Haltérophilie | Replay de Tokyo 2020', |
16 | 'upload_date': '20210801', | |
17 | 'timestamp': 1627783200, | |
18 | 'description': 'md5:c66af4a5bc7429dbcc43d15845ff03b3', | |
069c6ccf | 19 | 'uploader': 'International Olympic Committee', |
71407b3e A |
20 | }, |
21 | 'params': { | |
b2f25dc2 | 22 | 'skip_download': True, |
71407b3e A |
23 | }, |
24 | }, { | |
25 | 'url': 'https://olympics.com/tokyo-2020/en/replay/bd242924-4b22-49a5-a846-f1d4c809250d/mens-bronze-medal-match-hun-esp', | |
26 | 'only_matching': True, | |
27 | }] | |
28 | ||
29 | def _real_extract(self, url): | |
30 | id = self._match_id(url) | |
b2f25dc2 | 31 | |
32 | webpage = self._download_webpage(url, id) | |
33 | title = self._html_search_meta(('title', 'og:title', 'twitter:title'), webpage) | |
34 | uuid = self._html_search_meta('episode_uid', webpage) | |
35 | m3u8_url = self._html_search_meta('video_url', webpage) | |
36 | json_ld = self._search_json_ld(webpage, uuid) | |
37 | thumbnails_list = json_ld.get('image') | |
38 | if not thumbnails_list: | |
39 | thumbnails_list = self._html_search_regex( | |
40 | r'["\']image["\']:\s*["\']([^"\']+)["\']', webpage, 'images', default='') | |
41 | thumbnails_list = thumbnails_list.replace('[', '').replace(']', '').split(',') | |
42 | thumbnails_list = [thumbnail.strip() for thumbnail in thumbnails_list] | |
43 | thumbnails = [] | |
44 | for thumbnail in thumbnails_list: | |
45 | width_a, height_a, width = self._search_regex( | |
46 | r'/images/image/private/t_(?P<width_a>\d+)-(?P<height_a>\d+)_(?P<width>\d+)/primary/[\W\w\d]+', | |
47 | thumbnail, 'thumb', group=(1, 2, 3), default=(None, None, None)) | |
48 | width_a, height_a, width = int_or_none(width_a), int_or_none(height_a), int_or_none(width) | |
49 | thumbnails.append({ | |
50 | 'url': thumbnail, | |
51 | 'width': width, | |
52 | 'height': int_or_none(try_get(width, lambda x: x * height_a / width_a)) | |
53 | }) | |
71407b3e | 54 | m3u8_url = self._download_json( |
b2f25dc2 | 55 | f'https://olympics.com/tokenGenerator?url={m3u8_url}', uuid, note='Downloading m3u8 url') |
2d3b3feb | 56 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, uuid, 'mp4', m3u8_id='hls') |
71407b3e A |
57 | |
58 | return { | |
b2f25dc2 | 59 | 'id': uuid, |
60 | 'title': title, | |
b2f25dc2 | 61 | 'thumbnails': thumbnails, |
71407b3e A |
62 | 'formats': formats, |
63 | 'subtitles': subtitles, | |
069c6ccf | 64 | **json_ld |
71407b3e | 65 | } |