]>
Commit | Line | Data |
---|---|---|
e1d168e5 | 1 | from .common import InfoExtractor |
8bdd16b4 | 2 | from ..utils import ( |
3 | determine_ext, | |
4 | float_or_none, | |
5 | int_or_none, | |
6 | unified_timestamp, | |
7 | urlencode_postdata, | |
8 | url_or_none, | |
9 | ) | |
e1d168e5 AS |
10 | |
11 | ||
12 | class ServusIE(InfoExtractor): | |
3b5399ce S |
13 | _VALID_URL = r'''(?x) |
14 | https?:// | |
15 | (?:www\.)? | |
16 | (?: | |
17 | servus\.com/(?:(?:at|de)/p/[^/]+|tv/videos)| | |
8bdd16b4 | 18 | (?:servustv|pm-wissen)\.com/videos |
3b5399ce S |
19 | ) |
20 | /(?P<id>[aA]{2}-\w+|\d+-\d+) | |
21 | ''' | |
e1d168e5 | 22 | _TESTS = [{ |
3b5399ce S |
23 | # new URL schema |
24 | 'url': 'https://www.servustv.com/videos/aa-1t6vbu5pw1w12/', | |
8bdd16b4 | 25 | 'md5': '60474d4c21f3eb148838f215c37f02b9', |
e1d168e5 AS |
26 | 'info_dict': { |
27 | 'id': 'AA-1T6VBU5PW1W12', | |
28 | 'ext': 'mp4', | |
55b8588f | 29 | 'title': 'Die Grünen aus Sicht des Volkes', |
8bdd16b4 | 30 | 'alt_title': 'Talk im Hangar-7 Voxpops Gruene', |
55b8588f S |
31 | 'description': 'md5:1247204d85783afe3682644398ff2ec4', |
32 | 'thumbnail': r're:^https?://.*\.jpg', | |
8bdd16b4 | 33 | 'duration': 62.442, |
34 | 'timestamp': 1605193976, | |
35 | 'upload_date': '20201112', | |
36 | 'series': 'Talk im Hangar-7', | |
37 | 'season': 'Season 9', | |
38 | 'season_number': 9, | |
39 | 'episode': 'Episode 31 - September 14', | |
40 | 'episode_number': 31, | |
e1d168e5 | 41 | } |
3b5399ce S |
42 | }, { |
43 | # old URL schema | |
44 | 'url': 'https://www.servus.com/de/p/Die-Gr%C3%BCnen-aus-Sicht-des-Volkes/AA-1T6VBU5PW1W12/', | |
45 | 'only_matching': True, | |
e1d168e5 AS |
46 | }, { |
47 | 'url': 'https://www.servus.com/at/p/Wie-das-Leben-beginnt/1309984137314-381415152/', | |
48 | 'only_matching': True, | |
55b8588f S |
49 | }, { |
50 | 'url': 'https://www.servus.com/tv/videos/aa-1t6vbu5pw1w12/', | |
51 | 'only_matching': True, | |
52 | }, { | |
53 | 'url': 'https://www.servus.com/tv/videos/1380889096408-1235196658/', | |
54 | 'only_matching': True, | |
8bdd16b4 | 55 | }, { |
56 | 'url': 'https://www.pm-wissen.com/videos/aa-24mus4g2w2112/', | |
57 | 'only_matching': True, | |
e1d168e5 AS |
58 | }] |
59 | ||
60 | def _real_extract(self, url): | |
55b8588f | 61 | video_id = self._match_id(url).upper() |
e1d168e5 | 62 | |
8bdd16b4 | 63 | token = self._download_json( |
64 | 'https://auth.redbullmediahouse.com/token', video_id, | |
65 | 'Downloading token', data=urlencode_postdata({ | |
66 | 'grant_type': 'client_credentials', | |
67 | }), headers={ | |
68 | 'Authorization': 'Basic SVgtMjJYNEhBNFdEM1cxMTpEdDRVSkFLd2ZOMG5IMjB1NGFBWTBmUFpDNlpoQ1EzNA==', | |
69 | }) | |
70 | access_token = token['access_token'] | |
71 | token_type = token.get('token_type', 'Bearer') | |
e1d168e5 | 72 | |
8bdd16b4 | 73 | video = self._download_json( |
74 | 'https://sparkle-api.liiift.io/api/v1/stv/channels/international/assets/%s' % video_id, | |
75 | video_id, 'Downloading video JSON', headers={ | |
76 | 'Authorization': '%s %s' % (token_type, access_token), | |
77 | }) | |
78 | ||
79 | formats = [] | |
80 | thumbnail = None | |
81 | for resource in video['resources']: | |
82 | if not isinstance(resource, dict): | |
83 | continue | |
84 | format_url = url_or_none(resource.get('url')) | |
85 | if not format_url: | |
86 | continue | |
87 | extension = resource.get('extension') | |
88 | type_ = resource.get('type') | |
89 | if extension == 'jpg' or type_ == 'reference_keyframe': | |
90 | thumbnail = format_url | |
91 | continue | |
92 | ext = determine_ext(format_url) | |
93 | if type_ == 'dash' or ext == 'mpd': | |
94 | formats.extend(self._extract_mpd_formats( | |
95 | format_url, video_id, mpd_id='dash', fatal=False)) | |
96 | elif type_ == 'hls' or ext == 'm3u8': | |
97 | formats.extend(self._extract_m3u8_formats( | |
98 | format_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
99 | m3u8_id='hls', fatal=False)) | |
100 | elif extension == 'mp4' or ext == 'mp4': | |
101 | formats.append({ | |
102 | 'url': format_url, | |
103 | 'format_id': type_, | |
104 | 'width': int_or_none(resource.get('width')), | |
105 | 'height': int_or_none(resource.get('height')), | |
106 | }) | |
e1d168e5 | 107 | |
8bdd16b4 | 108 | attrs = {} |
109 | for attribute in video['attributes']: | |
110 | if not isinstance(attribute, dict): | |
111 | continue | |
112 | key = attribute.get('fieldKey') | |
113 | value = attribute.get('fieldValue') | |
114 | if not key or not value: | |
115 | continue | |
116 | attrs[key] = value | |
117 | ||
118 | title = attrs.get('title_stv') or video_id | |
119 | alt_title = attrs.get('title') | |
120 | description = attrs.get('long_description') or attrs.get('short_description') | |
121 | series = attrs.get('label') | |
122 | season = attrs.get('season') | |
123 | episode = attrs.get('chapter') | |
124 | duration = float_or_none(attrs.get('duration'), scale=1000) | |
125 | season_number = int_or_none(self._search_regex( | |
126 | r'Season (\d+)', season or '', 'season number', default=None)) | |
127 | episode_number = int_or_none(self._search_regex( | |
128 | r'Episode (\d+)', episode or '', 'episode number', default=None)) | |
129 | ||
e1d168e5 AS |
130 | return { |
131 | 'id': video_id, | |
132 | 'title': title, | |
8bdd16b4 | 133 | 'alt_title': alt_title, |
e1d168e5 AS |
134 | 'description': description, |
135 | 'thumbnail': thumbnail, | |
8bdd16b4 | 136 | 'duration': duration, |
137 | 'timestamp': unified_timestamp(video.get('lastPublished')), | |
138 | 'series': series, | |
139 | 'season': season, | |
140 | 'season_number': season_number, | |
141 | 'episode': episode, | |
142 | 'episode_number': episode_number, | |
e1d168e5 AS |
143 | 'formats': formats, |
144 | } |