]>
Commit | Line | Data |
---|---|---|
07cf18b9 | 1 | import json |
5625bd06 | 2 | |
3eb38acb | 3 | from .common import InfoExtractor |
ef2041eb | 4 | from ..utils import ( |
07cf18b9 | 5 | determine_ext, |
ef2041eb S |
6 | ExtractorError, |
7 | int_or_none, | |
65bc504d | 8 | parse_duration, |
07cf18b9 | 9 | parse_iso8601, |
5625bd06 | 10 | xpath_element, |
11 | xpath_text, | |
ef2041eb | 12 | ) |
3eb38acb | 13 | |
3eb38acb | 14 | |
06aabfc4 | 15 | class BRIE(InfoExtractor): |
07cf18b9 | 16 | IE_DESC = 'Bayerischer Rundfunk' |
5625bd06 | 17 | _VALID_URL = r'(?P<base_url>https?://(?:www\.)?br(?:-klassik)?\.de)/(?:[a-z0-9\-_]+/)+(?P<id>[a-z0-9\-_]+)\.html' |
3eb38acb | 18 | |
c21215b4 DT |
19 | _TESTS = [ |
20 | { | |
d592b42f | 21 | 'url': 'http://www.br.de/mediathek/video/sendungen/abendschau/betriebliche-altersvorsorge-104.html', |
22 | 'md5': '83a0477cf0b8451027eb566d88b51106', | |
ef2041eb | 23 | 'info_dict': { |
d592b42f | 24 | 'id': '48f656ef-287e-486f-be86-459122db22cc', |
ef2041eb | 25 | 'ext': 'mp4', |
d592b42f | 26 | 'title': 'Die böse Überraschung', |
5625bd06 | 27 | 'description': 'md5:ce9ac81b466ce775b8018f6801b48ac9', |
d592b42f | 28 | 'duration': 180, |
29 | 'uploader': 'Reinhard Weber', | |
30 | 'upload_date': '20150422', | |
0278aa44 YCH |
31 | }, |
32 | 'skip': '404 not found', | |
c21215b4 | 33 | }, |
ef2041eb | 34 | { |
d592b42f | 35 | 'url': 'http://www.br.de/nachrichten/oberbayern/inhalt/muenchner-polizeipraesident-schreiber-gestorben-100.html', |
5625bd06 | 36 | 'md5': 'af3a3a4aa43ff0ce6a89504c67f427ef', |
ef2041eb | 37 | 'info_dict': { |
d592b42f | 38 | 'id': 'a4b83e34-123d-4b81-9f4e-c0d3121a4e05', |
5625bd06 | 39 | 'ext': 'flv', |
d592b42f | 40 | 'title': 'Manfred Schreiber ist tot', |
5625bd06 | 41 | 'description': 'md5:b454d867f2a9fc524ebe88c3f5092d97', |
d592b42f | 42 | 'duration': 26, |
0278aa44 YCH |
43 | }, |
44 | 'skip': '404 not found', | |
ef2041eb | 45 | }, |
0892090a | 46 | { |
5625bd06 | 47 | 'url': 'https://www.br-klassik.de/audio/peeping-tom-premierenkritik-dance-festival-muenchen-100.html', |
0892090a | 48 | 'md5': '8b5b27c0b090f3b35eac4ab3f7a73d3d', |
49 | 'info_dict': { | |
50 | 'id': '74c603c9-26d3-48bb-b85b-079aeed66e0b', | |
51 | 'ext': 'aac', | |
52 | 'title': 'Kurzweilig und sehr bewegend', | |
5625bd06 | 53 | 'description': 'md5:0351996e3283d64adeb38ede91fac54e', |
0892090a | 54 | 'duration': 296, |
0278aa44 YCH |
55 | }, |
56 | 'skip': '404 not found', | |
0892090a | 57 | }, |
ef2041eb S |
58 | { |
59 | 'url': 'http://www.br.de/radio/bayern1/service/team/videos/team-video-erdelt100.html', | |
60 | 'md5': 'dbab0aef2e047060ea7a21fc1ce1078a', | |
61 | 'info_dict': { | |
62 | 'id': '6ba73750-d405-45d3-861d-1ce8c524e059', | |
63 | 'ext': 'mp4', | |
64 | 'title': 'Umweltbewusster Häuslebauer', | |
5625bd06 | 65 | 'description': 'md5:d52dae9792d00226348c1dbb13c9bae2', |
65bc504d | 66 | 'duration': 116, |
ef2041eb S |
67 | } |
68 | }, | |
69 | { | |
70 | 'url': 'http://www.br.de/fernsehen/br-alpha/sendungen/kant-fuer-anfaenger/kritik-der-reinen-vernunft/kant-kritik-01-metaphysik100.html', | |
71 | 'md5': '23bca295f1650d698f94fc570977dae3', | |
72 | 'info_dict': { | |
73 | 'id': 'd982c9ce-8648-4753-b358-98abb8aec43d', | |
74 | 'ext': 'mp4', | |
75 | 'title': 'Folge 1 - Metaphysik', | |
5625bd06 | 76 | 'description': 'md5:bb659990e9e59905c3d41e369db1fbe3', |
65bc504d | 77 | 'duration': 893, |
ef2041eb | 78 | 'uploader': 'Eva Maria Steimle', |
6f4a8884 | 79 | 'upload_date': '20170208', |
ef2041eb S |
80 | } |
81 | }, | |
c21215b4 | 82 | ] |
3eb38acb DT |
83 | |
84 | def _real_extract(self, url): | |
5ad28e7f | 85 | base_url, display_id = self._match_valid_url(url).groups() |
06aabfc4 PH |
86 | page = self._download_webpage(url, display_id) |
87 | xml_url = self._search_regex( | |
ef2041eb | 88 | r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page, 'XMLURL') |
5625bd06 | 89 | xml = self._download_xml(base_url + xml_url, display_id) |
3eb38acb | 90 | |
ef2041eb S |
91 | medias = [] |
92 | ||
93 | for xml_media in xml.findall('video') + xml.findall('audio'): | |
5625bd06 | 94 | media_id = xml_media.get('externalId') |
ef2041eb | 95 | media = { |
5625bd06 | 96 | 'id': media_id, |
97 | 'title': xpath_text(xml_media, 'title', 'title', True), | |
98 | 'duration': parse_duration(xpath_text(xml_media, 'duration')), | |
99 | 'formats': self._extract_formats(xpath_element( | |
100 | xml_media, 'assets'), media_id), | |
101 | 'thumbnails': self._extract_thumbnails(xpath_element( | |
102 | xml_media, 'teaserImage/variants'), base_url), | |
103 | 'description': xpath_text(xml_media, 'desc'), | |
104 | 'webpage_url': xpath_text(xml_media, 'permalink'), | |
105 | 'uploader': xpath_text(xml_media, 'author'), | |
c21215b4 | 106 | } |
5625bd06 | 107 | broadcast_date = xpath_text(xml_media, 'broadcastDate') |
108 | if broadcast_date: | |
109 | media['upload_date'] = ''.join(reversed(broadcast_date.split('.'))) | |
ef2041eb | 110 | medias.append(media) |
3eb38acb | 111 | |
ef2041eb | 112 | if len(medias) > 1: |
6a39ee13 | 113 | self.report_warning( |
ef2041eb | 114 | 'found multiple medias; please ' |
06aabfc4 | 115 | 'report this with the video URL to http://yt-dl.org/bug') |
ef2041eb S |
116 | if not medias: |
117 | raise ExtractorError('No media entries found') | |
118 | return medias[0] | |
3eb38acb | 119 | |
5625bd06 | 120 | def _extract_formats(self, assets, media_id): |
121 | formats = [] | |
122 | for asset in assets.findall('asset'): | |
123 | format_url = xpath_text(asset, ['downloadUrl', 'url']) | |
124 | asset_type = asset.get('type') | |
07cf18b9 | 125 | if asset_type.startswith('HDS'): |
7e5edcfd S |
126 | formats.extend(self._extract_f4m_formats( |
127 | format_url + '?hdcore=3.2.0', media_id, f4m_id='hds', fatal=False)) | |
07cf18b9 | 128 | elif asset_type.startswith('HLS'): |
7e5edcfd S |
129 | formats.extend(self._extract_m3u8_formats( |
130 | format_url, media_id, 'mp4', 'm3u8_native', m3u8_id='hds', fatal=False)) | |
5625bd06 | 131 | else: |
132 | format_info = { | |
133 | 'ext': xpath_text(asset, 'mediaType'), | |
134 | 'width': int_or_none(xpath_text(asset, 'frameWidth')), | |
135 | 'height': int_or_none(xpath_text(asset, 'frameHeight')), | |
136 | 'tbr': int_or_none(xpath_text(asset, 'bitrateVideo')), | |
137 | 'abr': int_or_none(xpath_text(asset, 'bitrateAudio')), | |
138 | 'vcodec': xpath_text(asset, 'codecVideo'), | |
139 | 'acodec': xpath_text(asset, 'codecAudio'), | |
140 | 'container': xpath_text(asset, 'mediaType'), | |
141 | 'filesize': int_or_none(xpath_text(asset, 'size')), | |
142 | } | |
143 | format_url = self._proto_relative_url(format_url) | |
144 | if format_url: | |
145 | http_format_info = format_info.copy() | |
146 | http_format_info.update({ | |
147 | 'url': format_url, | |
148 | 'format_id': 'http-%s' % asset_type, | |
149 | }) | |
150 | formats.append(http_format_info) | |
151 | server_prefix = xpath_text(asset, 'serverPrefix') | |
152 | if server_prefix: | |
153 | rtmp_format_info = format_info.copy() | |
154 | rtmp_format_info.update({ | |
155 | 'url': server_prefix, | |
156 | 'play_path': xpath_text(asset, 'fileName'), | |
157 | 'format_id': 'rtmp-%s' % asset_type, | |
158 | }) | |
159 | formats.append(rtmp_format_info) | |
06aabfc4 | 160 | return formats |
3eb38acb | 161 | |
5625bd06 | 162 | def _extract_thumbnails(self, variants, base_url): |
06aabfc4 | 163 | thumbnails = [{ |
5625bd06 | 164 | 'url': base_url + xpath_text(variant, 'url'), |
165 | 'width': int_or_none(xpath_text(variant, 'width')), | |
166 | 'height': int_or_none(xpath_text(variant, 'height')), | |
167 | } for variant in variants.findall('variant') if xpath_text(variant, 'url')] | |
ef2041eb | 168 | thumbnails.sort(key=lambda x: x['width'] * x['height'], reverse=True) |
3eb38acb | 169 | return thumbnails |
07cf18b9 RA |
170 | |
171 | ||
172 | class BRMediathekIE(InfoExtractor): | |
173 | IE_DESC = 'Bayerischer Rundfunk Mediathek' | |
f189faf1 | 174 | _VALID_URL = r'https?://(?:www\.)?br\.de/mediathek//?video/(?:[^/?&#]+?-)?(?P<id>av:[0-9a-f]{24})' |
07cf18b9 RA |
175 | |
176 | _TESTS = [{ | |
177 | 'url': 'https://www.br.de/mediathek/video/gesundheit-die-sendung-vom-28112017-av:5a1e6a6e8fce6d001871cc8e', | |
178 | 'md5': 'fdc3d485835966d1622587d08ba632ec', | |
179 | 'info_dict': { | |
180 | 'id': 'av:5a1e6a6e8fce6d001871cc8e', | |
181 | 'ext': 'mp4', | |
182 | 'title': 'Die Sendung vom 28.11.2017', | |
183 | 'description': 'md5:6000cdca5912ab2277e5b7339f201ccc', | |
184 | 'timestamp': 1511942766, | |
185 | 'upload_date': '20171129', | |
186 | } | |
f189faf1 | 187 | }, { |
188 | 'url': 'https://www.br.de/mediathek//video/av:61b0db581aed360007558c12', | |
189 | 'only_matching': True, | |
07cf18b9 RA |
190 | }] |
191 | ||
192 | def _real_extract(self, url): | |
193 | clip_id = self._match_id(url) | |
194 | ||
195 | clip = self._download_json( | |
196 | 'https://proxy-base.master.mango.express/graphql', | |
197 | clip_id, data=json.dumps({ | |
198 | "query": """{ | |
199 | viewer { | |
200 | clip(id: "%s") { | |
201 | title | |
202 | description | |
203 | duration | |
204 | createdAt | |
205 | ageRestriction | |
206 | videoFiles { | |
207 | edges { | |
208 | node { | |
209 | publicLocation | |
210 | fileSize | |
211 | videoProfile { | |
212 | width | |
213 | height | |
214 | bitrate | |
215 | encoding | |
216 | } | |
217 | } | |
218 | } | |
219 | } | |
220 | captionFiles { | |
221 | edges { | |
222 | node { | |
223 | publicLocation | |
224 | } | |
225 | } | |
226 | } | |
227 | teaserImages { | |
228 | edges { | |
229 | node { | |
230 | imageFiles { | |
231 | edges { | |
232 | node { | |
233 | publicLocation | |
234 | width | |
235 | height | |
236 | } | |
237 | } | |
238 | } | |
239 | } | |
240 | } | |
241 | } | |
242 | } | |
243 | } | |
244 | }""" % clip_id}).encode(), headers={ | |
245 | 'Content-Type': 'application/json', | |
246 | })['data']['viewer']['clip'] | |
247 | title = clip['title'] | |
248 | ||
249 | formats = [] | |
250 | for edge in clip.get('videoFiles', {}).get('edges', []): | |
251 | node = edge.get('node', {}) | |
252 | n_url = node.get('publicLocation') | |
253 | if not n_url: | |
254 | continue | |
255 | ext = determine_ext(n_url) | |
256 | if ext == 'm3u8': | |
257 | formats.extend(self._extract_m3u8_formats( | |
258 | n_url, clip_id, 'mp4', 'm3u8_native', | |
259 | m3u8_id='hls', fatal=False)) | |
260 | else: | |
261 | video_profile = node.get('videoProfile', {}) | |
262 | tbr = int_or_none(video_profile.get('bitrate')) | |
263 | format_id = 'http' | |
264 | if tbr: | |
265 | format_id += '-%d' % tbr | |
266 | formats.append({ | |
267 | 'format_id': format_id, | |
268 | 'url': n_url, | |
269 | 'width': int_or_none(video_profile.get('width')), | |
270 | 'height': int_or_none(video_profile.get('height')), | |
271 | 'tbr': tbr, | |
272 | 'filesize': int_or_none(node.get('fileSize')), | |
273 | }) | |
07cf18b9 RA |
274 | |
275 | subtitles = {} | |
276 | for edge in clip.get('captionFiles', {}).get('edges', []): | |
277 | node = edge.get('node', {}) | |
278 | n_url = node.get('publicLocation') | |
279 | if not n_url: | |
280 | continue | |
281 | subtitles.setdefault('de', []).append({ | |
282 | 'url': n_url, | |
283 | }) | |
284 | ||
285 | thumbnails = [] | |
286 | for edge in clip.get('teaserImages', {}).get('edges', []): | |
287 | for image_edge in edge.get('node', {}).get('imageFiles', {}).get('edges', []): | |
288 | node = image_edge.get('node', {}) | |
289 | n_url = node.get('publicLocation') | |
290 | if not n_url: | |
291 | continue | |
292 | thumbnails.append({ | |
293 | 'url': n_url, | |
294 | 'width': int_or_none(node.get('width')), | |
295 | 'height': int_or_none(node.get('height')), | |
296 | }) | |
297 | ||
298 | return { | |
299 | 'id': clip_id, | |
300 | 'title': title, | |
301 | 'description': clip.get('description'), | |
302 | 'duration': int_or_none(clip.get('duration')), | |
303 | 'timestamp': parse_iso8601(clip.get('createdAt')), | |
304 | 'age_limit': int_or_none(clip.get('ageRestriction')), | |
305 | 'formats': formats, | |
306 | 'subtitles': subtitles, | |
307 | 'thumbnails': thumbnails, | |
308 | } |