]>
Commit | Line | Data |
---|---|---|
704df56d | 1 | from .common import InfoExtractor |
5e1a54f6 | 2 | |
1cc79574 | 3 | from ..utils import ( |
5e1a54f6 FR |
4 | format_field, |
5 | traverse_obj, | |
6 | unified_timestamp, | |
7 | strip_or_none | |
704df56d PH |
8 | ) |
9 | ||
10 | ||
11 | class SportDeutschlandIE(InfoExtractor): | |
10db0d2f | 12 | _VALID_URL = r'https?://sportdeutschland\.tv/(?P<id>(?:[^/]+/)?[^?#/&]+)' |
3524cc25 | 13 | _TESTS = [{ |
5e1a54f6 | 14 | 'url': 'https://sportdeutschland.tv/blauweissbuchholztanzsport/buchholzer-formationswochenende-2023-samstag-1-bundesliga-landesliga', |
704df56d | 15 | 'info_dict': { |
5e1a54f6 | 16 | 'id': '983758e9-5829-454d-a3cf-eb27bccc3c94', |
704df56d | 17 | 'ext': 'mp4', |
5e1a54f6 FR |
18 | 'title': '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 | 'display_id': '9839a5c7-0dbb-48a8-ab63-3b408adc7b54', | |
25 | 'duration': 32447, | |
26 | 'upload_date': '20230114', | |
27 | 'timestamp': 1673730018.0, | |
28 | } | |
10db0d2f | 29 | }, { |
5e1a54f6 | 30 | 'url': 'https://sportdeutschland.tv/deutscherbadmintonverband/bwf-tour-1-runde-feld-1-yonex-gainward-german-open-2022-0', |
10db0d2f | 31 | 'info_dict': { |
5e1a54f6 FR |
32 | 'id': '95b97d9a-04f6-4880-9039-182985c33943', |
33 | 'ext': 'mp4', | |
34 | 'title': 'BWF Tour: 1. Runde Feld 1 - YONEX GAINWARD German Open 2022', | |
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 | 'display_id': '95c80c52-6b9a-4ae9-9197-984145adfced', | |
41 | 'duration': 41097, | |
42 | 'upload_date': '20220309', | |
43 | 'timestamp': 1646860727.0, | |
44 | } | |
3524cc25 | 45 | }] |
704df56d PH |
46 | |
47 | def _real_extract(self, url): | |
10db0d2f | 48 | display_id = self._match_id(url) |
5e1a54f6 FR |
49 | meta = self._download_json( |
50 | 'https://api.sportdeutschland.tv/api/stateless/frontend/assets/' + display_id, | |
10db0d2f | 51 | display_id, query={'access_token': 'true'}) |
5e1a54f6 FR |
52 | |
53 | asset_id = traverse_obj(meta, 'id', 'uuid') | |
54 | ||
10db0d2f | 55 | info = { |
56 | 'id': asset_id, | |
5e1a54f6 FR |
57 | 'channel_url': format_field(meta, ('profile', 'slug'), 'https://sportdeutschland.tv/%s'), |
58 | **traverse_obj(meta, { | |
59 | 'title': (('title', 'name'), {strip_or_none}), | |
60 | 'description': 'description', | |
61 | 'channel': ('profile', 'name'), | |
62 | 'channel_id': ('profile', 'id'), | |
63 | 'is_live': 'currently_live', | |
64 | 'was_live': 'was_live' | |
65 | }, get_all=False) | |
10db0d2f | 66 | } |
5e1a54f6 FR |
67 | |
68 | videos = meta.get('videos') or [] | |
69 | ||
10db0d2f | 70 | if len(videos) > 1: |
10db0d2f | 71 | info.update({ |
72 | '_type': 'multi_video', | |
5e1a54f6 FR |
73 | 'entries': self.processVideoOrStream(asset_id, video) |
74 | } for video in enumerate(videos) if video.get('formats')) | |
75 | ||
76 | elif len(videos) == 1: | |
77 | info.update( | |
78 | self.processVideoOrStream(asset_id, videos[0]) | |
79 | ) | |
80 | ||
81 | livestream = meta.get('livestream') | |
82 | ||
83 | if livestream is not None: | |
84 | info.update( | |
85 | self.processVideoOrStream(asset_id, livestream) | |
86 | ) | |
87 | ||
10db0d2f | 88 | return info |
5e1a54f6 FR |
89 | |
90 | def process_video_or_stream(self, asset_id, video): | |
91 | video_id = video['id'] | |
92 | video_src = video['src'] | |
93 | video_type = video['type'] | |
94 | ||
95 | token = self._download_json( | |
96 | f'https://api.sportdeutschland.tv/api/frontend/asset-token/{asset_id}', | |
97 | video_id, query={'type': video_type, 'playback_id': video_src})['token'] | |
98 | formats = self._extract_m3u8_formats(f'https://stream.mux.com/{video_src}.m3u8?token={token}', video_id) | |
99 | ||
100 | video_data = { | |
101 | 'display_id': video_id, | |
102 | 'formats': formats, | |
103 | } | |
104 | if video_type == 'mux_vod': | |
105 | video_data.update({ | |
106 | 'duration': video.get('duration'), | |
107 | 'timestamp': unified_timestamp(video.get('created_at')) | |
108 | }) | |
109 | ||
110 | return video_data |