]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/eurosport.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / eurosport.py
CommitLineData
11734714
H
1from .common import InfoExtractor
2from ..utils import traverse_obj
3
4
5class EurosportIE(InfoExtractor):
45e87ea1 6 _VALID_URL = r'https?://www\.eurosport\.com/\w+/(?:[\w-]+/[\d-]+/)?[\w-]+_(?P<id>vid\d+)'
11734714
H
7 _TESTS = [{
8 'url': 'https://www.eurosport.com/tennis/roland-garros/2022/highlights-rafael-nadal-brushes-aside-caper-ruud-to-win-record-extending-14th-french-open-title_vid1694147/video.shtml',
9 'info_dict': {
10 'id': '2480939',
11 'ext': 'mp4',
12 'title': 'Highlights: Rafael Nadal brushes aside Caper Ruud to win record-extending 14th French Open title',
13 'description': 'md5:b564db73ecfe4b14ebbd8e62a3692c76',
14 'thumbnail': 'https://imgresizer.eurosport.com/unsafe/1280x960/smart/filters:format(jpeg)/origin-imgresizer.eurosport.com/2022/06/05/3388285-69245968-2560-1440.png',
15 'duration': 195.0,
16 'display_id': 'vid1694147',
17 'timestamp': 1654446698,
18 'upload_date': '20220605',
19 }
20 }, {
21 'url': 'https://www.eurosport.com/tennis/roland-garros/2022/watch-the-top-five-shots-from-men-s-final-as-rafael-nadal-beats-casper-ruud-to-seal-14th-french-open_vid1694283/video.shtml',
22 'info_dict': {
23 'id': '2481254',
24 'ext': 'mp4',
25 'title': 'md5:149dcc5dfb38ab7352acc008cc9fb071',
26 'duration': 130.0,
27 'thumbnail': 'https://imgresizer.eurosport.com/unsafe/1280x960/smart/filters:format(jpeg)/origin-imgresizer.eurosport.com/2022/06/05/3388422-69248708-2560-1440.png',
28 'description': 'md5:a0c8a7f6b285e48ae8ddbe7aa85cfee6',
29 'display_id': 'vid1694283',
30 'timestamp': 1654456090,
31 'upload_date': '20220605',
32 }
33 }, {
34 # geo-fence but can bypassed by xff
35 'url': 'https://www.eurosport.com/cycling/tour-de-france-femmes/2022/incredible-ride-marlen-reusser-storms-to-stage-4-win-at-tour-de-france-femmes_vid1722221/video.shtml',
36 'info_dict': {
37 'id': '2582552',
38 'ext': 'mp4',
39 'title': '‘Incredible ride!’ - Marlen Reusser storms to Stage 4 win at Tour de France Femmes',
40 'duration': 188.0,
41 'display_id': 'vid1722221',
42 'timestamp': 1658936167,
43 'thumbnail': 'https://imgresizer.eurosport.com/unsafe/1280x960/smart/filters:format(jpeg)/origin-imgresizer.eurosport.com/2022/07/27/3423347-69852108-2560-1440.jpg',
44 'description': 'md5:32bbe3a773ac132c57fb1e8cca4b7c71',
45 'upload_date': '20220727',
46 }
45e87ea1
H
47 }, {
48 'url': 'https://www.eurosport.com/football/champions-league/2022-2023/pep-guardiola-emotionally-destroyed-after-manchester-city-win-over-bayern-munich-in-champions-league_vid1896254/video.shtml',
49 'info_dict': {
50 'id': '3096477',
51 'ext': 'mp4',
52 'title': 'md5:82edc17370124c7a19b3cf518517583b',
53 'duration': 84.0,
54 'description': 'md5:b3f44ef7f5b5b95b24a273b163083feb',
55 'thumbnail': 'https://imgresizer.eurosport.com/unsafe/1280x960/smart/filters:format(jpeg)/origin-imgresizer.eurosport.com/2023/04/12/3682873-74947393-2560-1440.jpg',
56 'timestamp': 1681292028,
57 'upload_date': '20230412',
58 'display_id': 'vid1896254',
59 }
60 }, {
61 'url': 'https://www.eurosport.com/football/last-year-s-semi-final-pain-was-still-there-pep-guardiola-after-man-city-reach-cl-final_vid1914115/video.shtml',
62 'info_dict': {
63 'id': '3149108',
64 'ext': 'mp4',
65 'title': '\'Last year\'s semi-final pain was still there\' - Pep Guardiola after Man City reach CL final',
66 'description': 'md5:89ef142fe0170a66abab77fac2955d8e',
67 'display_id': 'vid1914115',
68 'timestamp': 1684403618,
69 'thumbnail': 'https://imgresizer.eurosport.com/unsafe/1280x960/smart/filters:format(jpeg)/origin-imgresizer.eurosport.com/2023/05/18/3707254-75435008-2560-1440.jpg',
70 'duration': 105.0,
71 'upload_date': '20230518',
72 }
11734714
H
73 }]
74
75 _TOKEN = None
76
77 # actually defined in https://netsport.eurosport.io/?variables={"databaseId":<databaseId>,"playoutType":"VDP"}&extensions={"persistedQuery":{"version":1 ..
78 # but this method require to get sha256 hash
79 _GEO_COUNTRIES = ['DE', 'NL', 'EU', 'IT', 'FR'] # Not complete list but it should work
80
81 def _real_initialize(self):
82 if EurosportIE._TOKEN is None:
83 EurosportIE._TOKEN = self._download_json(
84 'https://eu3-prod-direct.eurosport.com/token?realm=eurosport', None,
85 'Trying to get token')['data']['attributes']['token']
86
87 def _real_extract(self, url):
88 display_id = self._match_id(url)
89 webpage = self._download_webpage(url, display_id)
90
91 json_data = self._download_json(
92 f'https://eu3-prod-direct.eurosport.com/playback/v2/videoPlaybackInfo/sourceSystemId/eurosport-{display_id}',
93 display_id, query={'usePreAuth': True}, headers={'Authorization': f'Bearer {EurosportIE._TOKEN}'})['data']
94
95 json_ld_data = self._search_json_ld(webpage, display_id)
96
97 formats, subtitles = [], {}
98 for stream_type in json_data['attributes']['streaming']:
99 if stream_type == 'hls':
100 fmts, subs = self._extract_m3u8_formats_and_subtitles(
101 traverse_obj(json_data, ('attributes', 'streaming', stream_type, 'url')), display_id, ext='mp4')
102 elif stream_type == 'dash':
103 fmts, subs = self._extract_mpd_formats_and_subtitles(
104 traverse_obj(json_data, ('attributes', 'streaming', stream_type, 'url')), display_id)
105 elif stream_type == 'mss':
106 fmts, subs = self._extract_ism_formats_and_subtitles(
107 traverse_obj(json_data, ('attributes', 'streaming', stream_type, 'url')), display_id)
108
109 formats.extend(fmts)
110 self._merge_subtitles(subs, target=subtitles)
111
11734714
H
112 return {
113 'id': json_data['id'],
114 'title': json_ld_data.get('title') or self._og_search_title(webpage),
115 'display_id': display_id,
116 'formats': formats,
117 'subtitles': subtitles,
118 'thumbnails': json_ld_data.get('thumbnails'),
119 'description': (json_ld_data.get('description')
120 or self._html_search_meta(['og:description', 'description'], webpage)),
121 'duration': json_ld_data.get('duration'),
122 'timestamp': json_ld_data.get('timestamp'),
123 }