]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/fifa.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / fifa.py
CommitLineData
cbc6ee10
B
1from .common import InfoExtractor
2
3from ..utils import (
4 int_or_none,
5 traverse_obj,
6 unified_timestamp,
7)
8
9
10class FifaIE(InfoExtractor):
86925f63 11 _VALID_URL = r'https?://www.fifa.com/fifaplus/(?P<locale>\w{2})/watch/([^#?]+/)?(?P<id>\w+)'
cbc6ee10
B
12 _TESTS = [{
13 'url': 'https://www.fifa.com/fifaplus/en/watch/7on10qPcnyLajDDU3ntg6y',
14 'info_dict': {
15 'id': '7on10qPcnyLajDDU3ntg6y',
16 'title': 'Italy v France | Final | 2006 FIFA World Cup Germany™ | Full Match Replay',
17 'description': 'md5:f4520d0ee80529c8ba4134a7d692ff8b',
18 'ext': 'mp4',
170a0313 19 'categories': ['FIFA Tournaments'],
cbc6ee10 20 'thumbnail': 'https://digitalhub.fifa.com/transform/fa6f0b3e-a2e9-4cf7-9f32-53c57bcb7360/2006_Final_ITA_FRA',
170a0313 21 'duration': 8165,
cbc6ee10
B
22 },
23 'params': {'skip_download': 'm3u8'},
24 }, {
25 'url': 'https://www.fifa.com/fifaplus/pt/watch/1cg5r5Qt6Qt12ilkDgb1sV',
26 'info_dict': {
27 'id': '1cg5r5Qt6Qt12ilkDgb1sV',
170a0313 28 'title': 'Brazil v Germany | Semi-finals | 2014 FIFA World Cup Brazil™ | Extended Highlights',
29 'description': 'md5:d908c74ee66322b804ae2e521b02a855',
cbc6ee10
B
30 'ext': 'mp4',
31 'categories': ['FIFA Tournaments', 'Highlights'],
32 'thumbnail': 'https://digitalhub.fifa.com/transform/d8fe6f61-276d-4a73-a7fe-6878a35fd082/FIFAPLS_100EXTHL_2014BRAvGER_TMB',
170a0313 33 'duration': 902,
cbc6ee10
B
34 'release_timestamp': 1404777600,
35 'release_date': '20140708',
36 },
37 'params': {'skip_download': 'm3u8'},
38 }, {
39 'url': 'https://www.fifa.com/fifaplus/fr/watch/3C6gQH9C2DLwzNx7BMRQdp',
40 'info_dict': {
41 'id': '3C6gQH9C2DLwzNx7BMRQdp',
170a0313 42 'title': 'Josimar goal against Northern Ireland | Classic Goals',
43 'description': 'md5:cbe7e7bb52f603c9f1fe9a4780fe983b',
cbc6ee10
B
44 'ext': 'mp4',
45 'categories': ['FIFA Tournaments', 'Goal'],
46 'duration': 28,
47 'thumbnail': 'https://digitalhub.fifa.com/transform/f9301391-f8d9-48b5-823e-c093ac5e3e11/CG_MEN_1986_JOSIMAR',
48 },
49 'params': {'skip_download': 'm3u8'},
50 }]
51
52 def _real_extract(self, url):
53 video_id, locale = self._match_valid_url(url).group('id', 'locale')
54 webpage = self._download_webpage(url, video_id)
55
56 preconnect_link = self._search_regex(
57 r'<link[^>]+rel\s*=\s*"preconnect"[^>]+href\s*=\s*"([^"]+)"', webpage, 'Preconnect Link')
58
cbc6ee10
B
59 video_details = self._download_json(
60 f'{preconnect_link}/sections/videoDetails/{video_id}', video_id, 'Downloading Video Details', fatal=False)
61
62 preplay_parameters = self._download_json(
061a17ab 63 f'{preconnect_link}/videoPlayerData/{video_id}', video_id, 'Downloading Preplay Parameters')['preplayParameters']
cbc6ee10 64
170a0313 65 cid = preplay_parameters['contentId']
cbc6ee10
B
66 content_data = self._download_json(
67 f'https://content.uplynk.com/preplay/{cid}/multiple.json', video_id, 'Downloading Content Data', query={
68 'v': preplay_parameters['preplayAPIVersion'],
69 'tc': preplay_parameters['tokenCheckAlgorithmVersion'],
70 'rn': preplay_parameters['randomNumber'],
71 'exp': preplay_parameters['tokenExpirationDate'],
72 'ct': preplay_parameters['contentType'],
73 'cid': cid,
74 'mbtracks': preplay_parameters['tracksAssetNumber'],
75 'ad': preplay_parameters['adConfiguration'],
76 'ad.preroll': int(preplay_parameters['adPreroll']),
77 'ad.cmsid': preplay_parameters['adCMSSourceId'],
78 'ad.vid': preplay_parameters['adSourceVideoID'],
79 'sig': preplay_parameters['signature'],
80 })
81
86925f63 82 formats, subtitles = self._extract_m3u8_formats_and_subtitles(content_data['playURL'], video_id)
cbc6ee10
B
83
84 return {
85 'id': video_id,
170a0313 86 'title': video_details.get('title'),
87 'description': video_details.get('description'),
88 'duration': int_or_none(video_details.get('duration')),
cbc6ee10
B
89 'release_timestamp': unified_timestamp(video_details.get('dateOfRelease')),
90 'categories': traverse_obj(video_details, (('videoCategory', 'videoSubcategory'),)),
91 'thumbnail': traverse_obj(video_details, ('backgroundImage', 'src')),
92 'formats': formats,
86925f63 93 'subtitles': subtitles,
cbc6ee10 94 }