[ie/dplay] Fix extractors (#10471)
[yt-dlp3.git] / yt_dlp / extractor / sportdeutschland.py
blob2d6acb8768aa43589cf1dc49591608a631cac74f
1 from .common import InfoExtractor
2 from ..utils import (
3 join_nonempty,
4 strip_or_none,
5 traverse_obj,
6 unified_timestamp,
10 class SportDeutschlandIE(InfoExtractor):
11 _VALID_URL = r'https?://sportdeutschland\.tv/(?P<id>(?:[^/]+/)?[^?#/&]+)'
12 _TESTS = [{
13 'url': 'https://sportdeutschland.tv/blauweissbuchholztanzsport/buchholzer-formationswochenende-2023-samstag-1-bundesliga-landesliga',
14 'info_dict': {
15 'id': '9839a5c7-0dbb-48a8-ab63-3b408adc7b54',
16 'ext': 'mp4',
17 'title': 'Buchholzer Formationswochenende 2023 - Samstag - 1. Bundesliga / Landesliga',
18 'display_id': 'blauweissbuchholztanzsport/buchholzer-formationswochenende-2023-samstag-1-bundesliga-landesliga',
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',
24 'duration': 32447,
25 'upload_date': '20230114',
26 'timestamp': 1673733618,
28 }, {
29 'url': 'https://sportdeutschland.tv/deutscherbadmintonverband/bwf-tour-1-runde-feld-1-yonex-gainward-german-open-2022-0',
30 'info_dict': {
31 'id': '95c80c52-6b9a-4ae9-9197-984145adfced',
32 'ext': 'mp4',
33 'title': 'BWF Tour: 1. Runde Feld 1 - YONEX GAINWARD German Open 2022',
34 'display_id': 'deutscherbadmintonverband/bwf-tour-1-runde-feld-1-yonex-gainward-german-open-2022-0',
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',
40 'duration': 41097,
41 'upload_date': '20220309',
42 'timestamp': 1646860727.0,
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',
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',
70 }],
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',
84 'skip': 'live',
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)
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)}),
102 'timestamp': ('created_at', {unified_timestamp}),
106 def _real_extract(self, url):
107 display_id = self._match_id(url)
108 meta = self._download_json(
109 f'https://api.sportdeutschland.tv/api/stateless/frontend/assets/{display_id}',
110 display_id, query={'access_token': 'true'})
112 info = {
113 'display_id': display_id,
114 **traverse_obj(meta, {
115 'id': (('id', 'uuid'), ),
116 'title': (('title', 'name'), {strip_or_none}),
117 'description': 'description',
118 'channel': ('profile', 'name'),
119 'channel_id': ('profile', 'id'),
120 'is_live': 'currently_live',
121 'was_live': 'was_live',
122 'channel_url': ('profile', 'slug', {lambda x: f'https://sportdeutschland.tv/{x}'}),
123 }, get_all=False),
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)]
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'),