]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/olympics.py
[Olympics] Add replay extractor (#905)
[yt-dlp.git] / yt_dlp / extractor / olympics.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import unified_strdate
6
7
8 class OlympicsReplayIE(InfoExtractor):
9 _VALID_URL = r'(?:https?://)(?:www\.)?olympics\.com/tokyo-2020/(?:[a-z]{2}/)?replay/(?P<id>[^/#&?]+)'
10 _TESTS = [{
11 'url': 'https://olympics.com/tokyo-2020/en/replay/300622eb-abc0-43ea-b03b-c5f2d429ec7b/jumping-team-qualifier',
12 'info_dict': {
13 'id': '300622eb-abc0-43ea-b03b-c5f2d429ec7b',
14 'ext': 'mp4',
15 'title': 'Jumping Team Qualifier',
16 'release_date': '20210806',
17 'upload_date': '20210713',
18 },
19 'params': {
20 'format': 'bv',
21 },
22 }, {
23 'url': 'https://olympics.com/tokyo-2020/en/replay/bd242924-4b22-49a5-a846-f1d4c809250d/mens-bronze-medal-match-hun-esp',
24 'only_matching': True,
25 }]
26
27 def _real_extract(self, url):
28 id = self._match_id(url)
29 # The parameters are hardcoded in the webpage, it's not necessary to download the webpage just for these parameters.
30 # If in downloading webpage serves other functions aswell, then extract these parameters from it.
31 token_url = 'https://appovptok.ovpobs.tv/api/identity/app/token?api_key=OTk5NDcxOjpvY3N3LWFwaXVzZXI%3D&api_secret=ODY4ODM2MjE3ODMwYmVjNTAxMWZlMDJiMTYxZmY0MjFiMjMwMjllMjJmNDA1YWRiYzA5ODcxYTZjZTljZDkxOTo6NTM2NWIzNjRlMTM1ZmI2YWNjNmYzMGMzOGM3NzZhZTY%3D'
32 token = self._download_webpage(token_url, id)
33 headers = {'x-obs-app-token': token}
34 data_json = self._download_json(f'https://appocswtok.ovpobs.tv/api/schedule-sessions/{id}?include=stream',
35 id, headers=headers)
36 meta_data = data_json['data']['attributes']
37 for t_dict in data_json['included']:
38 if t_dict.get('type') == 'Stream':
39 stream_data = t_dict['attributes']
40 m3u8_url = self._download_json(
41 'https://meteringtok.ovpobs.tv/api/playback-sessions', id, headers=headers, query={
42 'alias': stream_data['alias'],
43 'stream': stream_data['stream'],
44 'type': 'vod'
45 })['data']['attributes']['url']
46 formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, id)
47 self._sort_formats(formats)
48
49 return {
50 'id': id,
51 'title': meta_data['title'],
52 'release_date': unified_strdate(meta_data.get('start') or meta_data.get('broadcastPublished')),
53 'upload_date': unified_strdate(meta_data.get('publishedAt')),
54 'formats': formats,
55 'subtitles': subtitles,
56 }