]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/sportdeutschland.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / sportdeutschland.py
CommitLineData
704df56d 1from .common import InfoExtractor
1cc79574 2from ..utils import (
45db3572 3 join_nonempty,
4 strip_or_none,
5e1a54f6
FR
5 traverse_obj,
6 unified_timestamp,
704df56d
PH
7)
8
9
10class SportDeutschlandIE(InfoExtractor):
10db0d2f 11 _VALID_URL = r'https?://sportdeutschland\.tv/(?P<id>(?:[^/]+/)?[^?#/&]+)'
3524cc25 12 _TESTS = [{
5e1a54f6 13 'url': 'https://sportdeutschland.tv/blauweissbuchholztanzsport/buchholzer-formationswochenende-2023-samstag-1-bundesliga-landesliga',
704df56d 14 'info_dict': {
45db3572 15 'id': '9839a5c7-0dbb-48a8-ab63-3b408adc7b54',
704df56d 16 'ext': 'mp4',
5e1a54f6 17 'title': 'Buchholzer Formationswochenende 2023 - Samstag - 1. Bundesliga / Landesliga',
45db3572 18 'display_id': 'blauweissbuchholztanzsport/buchholzer-formationswochenende-2023-samstag-1-bundesliga-landesliga',
5e1a54f6
FR
19 'description': 'md5:a288c794a5ee69e200d8f12982f81a87',
20 'live_status': 'was_live',
21 'channel': 'Blau-Weiss Buchholz Tanzsport',
22 'channel_url': 'https://sportdeutschland.tv/blauweissbuchholztanzsport',
23 'channel_id': '93ec33c9-48be-43b6-b404-e016b64fdfa3',
5e1a54f6
FR
24 'duration': 32447,
25 'upload_date': '20230114',
45db3572 26 'timestamp': 1673733618,
add96eb9 27 },
10db0d2f 28 }, {
5e1a54f6 29 'url': 'https://sportdeutschland.tv/deutscherbadmintonverband/bwf-tour-1-runde-feld-1-yonex-gainward-german-open-2022-0',
10db0d2f 30 'info_dict': {
45db3572 31 'id': '95c80c52-6b9a-4ae9-9197-984145adfced',
5e1a54f6
FR
32 'ext': 'mp4',
33 'title': 'BWF Tour: 1. Runde Feld 1 - YONEX GAINWARD German Open 2022',
45db3572 34 'display_id': 'deutscherbadmintonverband/bwf-tour-1-runde-feld-1-yonex-gainward-german-open-2022-0',
5e1a54f6
FR
35 'description': 'md5:2afb5996ceb9ac0b2ac81f563d3a883e',
36 'live_status': 'was_live',
37 'channel': 'Deutscher Badminton Verband',
38 'channel_url': 'https://sportdeutschland.tv/deutscherbadmintonverband',
39 'channel_id': '93ca5866-2551-49fc-8424-6db35af58920',
5e1a54f6
FR
40 'duration': 41097,
41 'upload_date': '20220309',
42 'timestamp': 1646860727.0,
add96eb9 43 },
45db3572 44 }, {
45 'url': 'https://sportdeutschland.tv/ggcbremen/formationswochenende-latein-2023',
46 'info_dict': {
47 'id': '9889785e-55b0-4d97-a72a-ce9a9f157cce',
48 'title': 'Formationswochenende Latein 2023 - Samstag',
49 'display_id': 'ggcbremen/formationswochenende-latein-2023',
50 'description': 'md5:6e4060d40ff6a8f8eeb471b51a8f08b2',
51 'live_status': 'was_live',
52 'channel': 'Grün-Gold-Club Bremen e.V.',
53 'channel_id': '9888f04e-bb46-4c7f-be47-df960a4167bb',
54 'channel_url': 'https://sportdeutschland.tv/ggcbremen',
55 },
56 'playlist_count': 3,
57 'playlist': [{
58 'info_dict': {
59 'id': '988e1fea-9d44-4fab-8c72-3085fb667547',
60 'ext': 'mp4',
61 'channel_url': 'https://sportdeutschland.tv/ggcbremen',
62 'channel_id': '9888f04e-bb46-4c7f-be47-df960a4167bb',
63 'channel': 'Grün-Gold-Club Bremen e.V.',
64 'duration': 86,
65 'title': 'Formationswochenende Latein 2023 - Samstag Part 1',
66 'upload_date': '20230225',
67 'timestamp': 1677349909,
68 'live_status': 'was_live',
add96eb9 69 },
70 }],
45db3572 71 }, {
72 'url': 'https://sportdeutschland.tv/dtb/gymnastik-international-tag-1',
73 'info_dict': {
74 'id': '95d71b8a-370a-4b87-ad16-94680da18528',
75 'ext': 'mp4',
76 'title': r're:Gymnastik International - Tag 1 .+',
77 'display_id': 'dtb/gymnastik-international-tag-1',
78 'channel_id': '936ecef1-2f4a-4e08-be2f-68073cb7ecab',
79 'channel': 'Deutscher Turner-Bund',
80 'channel_url': 'https://sportdeutschland.tv/dtb',
81 'description': 'md5:07a885dde5838a6f0796ee21dc3b0c52',
82 'live_status': 'is_live',
83 },
84 'skip': 'live',
3524cc25 85 }]
704df56d 86
45db3572 87 def _process_video(self, asset_id, video):
88 is_live = video['type'] == 'mux_live'
89 token = self._download_json(
90 f'https://api.sportdeutschland.tv/api/frontend/asset-token/{asset_id}',
91 video['id'], query={'type': video['type'], 'playback_id': video['src']})['token']
92 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
93 f'https://stream.mux.com/{video["src"]}.m3u8?token={token}', video['id'], live=is_live)
94
95 return {
96 'is_live': is_live,
97 'formats': formats,
98 'subtitles': subtitles,
99 **traverse_obj(video, {
100 'id': 'id',
101 'duration': ('duration', {lambda x: float(x) > 0 and float(x)}),
add96eb9 102 'timestamp': ('created_at', {unified_timestamp}),
45db3572 103 }),
104 }
105
704df56d 106 def _real_extract(self, url):
10db0d2f 107 display_id = self._match_id(url)
5e1a54f6 108 meta = self._download_json(
45db3572 109 f'https://api.sportdeutschland.tv/api/stateless/frontend/assets/{display_id}',
10db0d2f 110 display_id, query={'access_token': 'true'})
5e1a54f6 111
10db0d2f 112 info = {
45db3572 113 'display_id': display_id,
5e1a54f6 114 **traverse_obj(meta, {
45db3572 115 'id': (('id', 'uuid'), ),
5e1a54f6
FR
116 'title': (('title', 'name'), {strip_or_none}),
117 'description': 'description',
118 'channel': ('profile', 'name'),
119 'channel_id': ('profile', 'id'),
120 'is_live': 'currently_live',
45db3572 121 'was_live': 'was_live',
122 'channel_url': ('profile', 'slug', {lambda x: f'https://sportdeutschland.tv/{x}'}),
add96eb9 123 }, get_all=False),
10db0d2f 124 }
5e1a54f6 125
45db3572 126 parts = traverse_obj(meta, (('livestream', ('videos', ...)), ))
127 entries = [{
128 'title': join_nonempty(info.get('title'), f'Part {i}', delim=' '),
129 **traverse_obj(info, {'channel': 'channel', 'channel_id': 'channel_id',
130 'channel_url': 'channel_url', 'was_live': 'was_live'}),
131 **self._process_video(info['id'], video),
132 } for i, video in enumerate(parts, 1)]
392389b7 133
45db3572 134 return {
135 '_type': 'multi_video',
136 **info,
137 'entries': entries,
138 } if len(entries) > 1 else {
139 **info,
140 **entries[0],
141 'title': info.get('title'),
5e1a54f6 142 }