]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/fifa.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / fifa.py
CommitLineData
cbc6ee10 1from .common import InfoExtractor
cbc6ee10
B
2from ..utils import (
3 int_or_none,
4 traverse_obj,
5 unified_timestamp,
6)
7
8
9class FifaIE(InfoExtractor):
b634ba74 10 _VALID_URL = r'https?://www\.fifa\.com/fifaplus/(?P<locale>\w{2})/watch/([^#?]+/)?(?P<id>\w+)'
cbc6ee10
B
11 _TESTS = [{
12 'url': 'https://www.fifa.com/fifaplus/en/watch/7on10qPcnyLajDDU3ntg6y',
13 'info_dict': {
14 'id': '7on10qPcnyLajDDU3ntg6y',
15 'title': 'Italy v France | Final | 2006 FIFA World Cup Germany™ | Full Match Replay',
16 'description': 'md5:f4520d0ee80529c8ba4134a7d692ff8b',
17 'ext': 'mp4',
170a0313 18 'categories': ['FIFA Tournaments'],
13f930ab 19 'thumbnail': 'https://digitalhub.fifa.com/transform/135e2656-3a51-407b-8810-6c34bec5b59b/FMR_2006_Italy_France_Final_Hero',
170a0313 20 'duration': 8165,
13f930ab 21 'release_timestamp': 1152403200,
22 'release_date': '20060709',
cbc6ee10
B
23 },
24 'params': {'skip_download': 'm3u8'},
25 }, {
26 'url': 'https://www.fifa.com/fifaplus/pt/watch/1cg5r5Qt6Qt12ilkDgb1sV',
27 'info_dict': {
28 'id': '1cg5r5Qt6Qt12ilkDgb1sV',
170a0313 29 'title': 'Brazil v Germany | Semi-finals | 2014 FIFA World Cup Brazil™ | Extended Highlights',
30 'description': 'md5:d908c74ee66322b804ae2e521b02a855',
cbc6ee10
B
31 'ext': 'mp4',
32 'categories': ['FIFA Tournaments', 'Highlights'],
33 'thumbnail': 'https://digitalhub.fifa.com/transform/d8fe6f61-276d-4a73-a7fe-6878a35fd082/FIFAPLS_100EXTHL_2014BRAvGER_TMB',
170a0313 34 'duration': 902,
cbc6ee10
B
35 'release_timestamp': 1404777600,
36 'release_date': '20140708',
37 },
38 'params': {'skip_download': 'm3u8'},
39 }, {
40 'url': 'https://www.fifa.com/fifaplus/fr/watch/3C6gQH9C2DLwzNx7BMRQdp',
41 'info_dict': {
42 'id': '3C6gQH9C2DLwzNx7BMRQdp',
170a0313 43 'title': 'Josimar goal against Northern Ireland | Classic Goals',
44 'description': 'md5:cbe7e7bb52f603c9f1fe9a4780fe983b',
cbc6ee10
B
45 'ext': 'mp4',
46 'categories': ['FIFA Tournaments', 'Goal'],
47 'duration': 28,
48 'thumbnail': 'https://digitalhub.fifa.com/transform/f9301391-f8d9-48b5-823e-c093ac5e3e11/CG_MEN_1986_JOSIMAR',
49 },
50 'params': {'skip_download': 'm3u8'},
51 }]
52
53 def _real_extract(self, url):
54 video_id, locale = self._match_valid_url(url).group('id', 'locale')
55 webpage = self._download_webpage(url, video_id)
56
57 preconnect_link = self._search_regex(
13f930ab 58 r'<link\b[^>]+\brel\s*=\s*"preconnect"[^>]+href\s*=\s*"([^"]+)"', webpage, 'Preconnect Link')
cbc6ee10 59
cbc6ee10
B
60 video_details = self._download_json(
61 f'{preconnect_link}/sections/videoDetails/{video_id}', video_id, 'Downloading Video Details', fatal=False)
62
63 preplay_parameters = self._download_json(
061a17ab 64 f'{preconnect_link}/videoPlayerData/{video_id}', video_id, 'Downloading Preplay Parameters')['preplayParameters']
cbc6ee10 65
cbc6ee10 66 content_data = self._download_json(
13f930ab 67 'https://content.uplynk.com/preplay/{contentId}/multiple.json?{queryStr}&sig={signature}'.format(**preplay_parameters),
68 video_id, 'Downloading Content Data')
cbc6ee10 69
86925f63 70 formats, subtitles = self._extract_m3u8_formats_and_subtitles(content_data['playURL'], video_id)
cbc6ee10
B
71
72 return {
73 'id': video_id,
170a0313 74 'title': video_details.get('title'),
75 'description': video_details.get('description'),
76 'duration': int_or_none(video_details.get('duration')),
cbc6ee10
B
77 'release_timestamp': unified_timestamp(video_details.get('dateOfRelease')),
78 'categories': traverse_obj(video_details, (('videoCategory', 'videoSubcategory'),)),
79 'thumbnail': traverse_obj(video_details, ('backgroundImage', 'src')),
80 'formats': formats,
86925f63 81 'subtitles': subtitles,
cbc6ee10 82 }