]>
Commit | Line | Data |
---|---|---|
3eb38acb | 1 | from .common import InfoExtractor |
ef2041eb S |
2 | from ..utils import ( |
3 | ExtractorError, | |
4 | int_or_none, | |
65bc504d | 5 | parse_duration, |
5625bd06 | 6 | xpath_element, |
7 | xpath_text, | |
ef2041eb | 8 | ) |
3eb38acb | 9 | |
3eb38acb | 10 | |
06aabfc4 | 11 | class BRIE(InfoExtractor): |
9751a457 | 12 | _WORKING = False |
07cf18b9 | 13 | IE_DESC = 'Bayerischer Rundfunk' |
5625bd06 | 14 | _VALID_URL = r'(?P<base_url>https?://(?:www\.)?br(?:-klassik)?\.de)/(?:[a-z0-9\-_]+/)+(?P<id>[a-z0-9\-_]+)\.html' |
3eb38acb | 15 | |
c21215b4 DT |
16 | _TESTS = [ |
17 | { | |
d592b42f | 18 | 'url': 'http://www.br.de/mediathek/video/sendungen/abendschau/betriebliche-altersvorsorge-104.html', |
19 | 'md5': '83a0477cf0b8451027eb566d88b51106', | |
ef2041eb | 20 | 'info_dict': { |
d592b42f | 21 | 'id': '48f656ef-287e-486f-be86-459122db22cc', |
ef2041eb | 22 | 'ext': 'mp4', |
d592b42f | 23 | 'title': 'Die böse Überraschung', |
5625bd06 | 24 | 'description': 'md5:ce9ac81b466ce775b8018f6801b48ac9', |
d592b42f | 25 | 'duration': 180, |
26 | 'uploader': 'Reinhard Weber', | |
27 | 'upload_date': '20150422', | |
0278aa44 YCH |
28 | }, |
29 | 'skip': '404 not found', | |
c21215b4 | 30 | }, |
ef2041eb | 31 | { |
d592b42f | 32 | 'url': 'http://www.br.de/nachrichten/oberbayern/inhalt/muenchner-polizeipraesident-schreiber-gestorben-100.html', |
5625bd06 | 33 | 'md5': 'af3a3a4aa43ff0ce6a89504c67f427ef', |
ef2041eb | 34 | 'info_dict': { |
d592b42f | 35 | 'id': 'a4b83e34-123d-4b81-9f4e-c0d3121a4e05', |
5625bd06 | 36 | 'ext': 'flv', |
d592b42f | 37 | 'title': 'Manfred Schreiber ist tot', |
5625bd06 | 38 | 'description': 'md5:b454d867f2a9fc524ebe88c3f5092d97', |
d592b42f | 39 | 'duration': 26, |
0278aa44 YCH |
40 | }, |
41 | 'skip': '404 not found', | |
ef2041eb | 42 | }, |
0892090a | 43 | { |
5625bd06 | 44 | 'url': 'https://www.br-klassik.de/audio/peeping-tom-premierenkritik-dance-festival-muenchen-100.html', |
0892090a | 45 | 'md5': '8b5b27c0b090f3b35eac4ab3f7a73d3d', |
46 | 'info_dict': { | |
47 | 'id': '74c603c9-26d3-48bb-b85b-079aeed66e0b', | |
48 | 'ext': 'aac', | |
49 | 'title': 'Kurzweilig und sehr bewegend', | |
5625bd06 | 50 | 'description': 'md5:0351996e3283d64adeb38ede91fac54e', |
0892090a | 51 | 'duration': 296, |
0278aa44 YCH |
52 | }, |
53 | 'skip': '404 not found', | |
0892090a | 54 | }, |
ef2041eb S |
55 | { |
56 | 'url': 'http://www.br.de/radio/bayern1/service/team/videos/team-video-erdelt100.html', | |
57 | 'md5': 'dbab0aef2e047060ea7a21fc1ce1078a', | |
58 | 'info_dict': { | |
59 | 'id': '6ba73750-d405-45d3-861d-1ce8c524e059', | |
60 | 'ext': 'mp4', | |
61 | 'title': 'Umweltbewusster Häuslebauer', | |
5625bd06 | 62 | 'description': 'md5:d52dae9792d00226348c1dbb13c9bae2', |
65bc504d | 63 | 'duration': 116, |
add96eb9 | 64 | }, |
ef2041eb S |
65 | }, |
66 | { | |
67 | 'url': 'http://www.br.de/fernsehen/br-alpha/sendungen/kant-fuer-anfaenger/kritik-der-reinen-vernunft/kant-kritik-01-metaphysik100.html', | |
68 | 'md5': '23bca295f1650d698f94fc570977dae3', | |
69 | 'info_dict': { | |
70 | 'id': 'd982c9ce-8648-4753-b358-98abb8aec43d', | |
71 | 'ext': 'mp4', | |
72 | 'title': 'Folge 1 - Metaphysik', | |
5625bd06 | 73 | 'description': 'md5:bb659990e9e59905c3d41e369db1fbe3', |
65bc504d | 74 | 'duration': 893, |
ef2041eb | 75 | 'uploader': 'Eva Maria Steimle', |
6f4a8884 | 76 | 'upload_date': '20170208', |
add96eb9 | 77 | }, |
ef2041eb | 78 | }, |
c21215b4 | 79 | ] |
3eb38acb DT |
80 | |
81 | def _real_extract(self, url): | |
5ad28e7f | 82 | base_url, display_id = self._match_valid_url(url).groups() |
06aabfc4 PH |
83 | page = self._download_webpage(url, display_id) |
84 | xml_url = self._search_regex( | |
ef2041eb | 85 | r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page, 'XMLURL') |
5625bd06 | 86 | xml = self._download_xml(base_url + xml_url, display_id) |
3eb38acb | 87 | |
ef2041eb S |
88 | medias = [] |
89 | ||
90 | for xml_media in xml.findall('video') + xml.findall('audio'): | |
5625bd06 | 91 | media_id = xml_media.get('externalId') |
ef2041eb | 92 | media = { |
5625bd06 | 93 | 'id': media_id, |
94 | 'title': xpath_text(xml_media, 'title', 'title', True), | |
95 | 'duration': parse_duration(xpath_text(xml_media, 'duration')), | |
96 | 'formats': self._extract_formats(xpath_element( | |
97 | xml_media, 'assets'), media_id), | |
98 | 'thumbnails': self._extract_thumbnails(xpath_element( | |
99 | xml_media, 'teaserImage/variants'), base_url), | |
100 | 'description': xpath_text(xml_media, 'desc'), | |
101 | 'webpage_url': xpath_text(xml_media, 'permalink'), | |
102 | 'uploader': xpath_text(xml_media, 'author'), | |
c21215b4 | 103 | } |
5625bd06 | 104 | broadcast_date = xpath_text(xml_media, 'broadcastDate') |
105 | if broadcast_date: | |
106 | media['upload_date'] = ''.join(reversed(broadcast_date.split('.'))) | |
ef2041eb | 107 | medias.append(media) |
3eb38acb | 108 | |
ef2041eb | 109 | if len(medias) > 1: |
6a39ee13 | 110 | self.report_warning( |
ef2041eb | 111 | 'found multiple medias; please ' |
06aabfc4 | 112 | 'report this with the video URL to http://yt-dl.org/bug') |
ef2041eb S |
113 | if not medias: |
114 | raise ExtractorError('No media entries found') | |
115 | return medias[0] | |
3eb38acb | 116 | |
5625bd06 | 117 | def _extract_formats(self, assets, media_id): |
118 | formats = [] | |
119 | for asset in assets.findall('asset'): | |
120 | format_url = xpath_text(asset, ['downloadUrl', 'url']) | |
121 | asset_type = asset.get('type') | |
07cf18b9 | 122 | if asset_type.startswith('HDS'): |
7e5edcfd S |
123 | formats.extend(self._extract_f4m_formats( |
124 | format_url + '?hdcore=3.2.0', media_id, f4m_id='hds', fatal=False)) | |
07cf18b9 | 125 | elif asset_type.startswith('HLS'): |
7e5edcfd S |
126 | formats.extend(self._extract_m3u8_formats( |
127 | format_url, media_id, 'mp4', 'm3u8_native', m3u8_id='hds', fatal=False)) | |
5625bd06 | 128 | else: |
129 | format_info = { | |
130 | 'ext': xpath_text(asset, 'mediaType'), | |
131 | 'width': int_or_none(xpath_text(asset, 'frameWidth')), | |
132 | 'height': int_or_none(xpath_text(asset, 'frameHeight')), | |
133 | 'tbr': int_or_none(xpath_text(asset, 'bitrateVideo')), | |
134 | 'abr': int_or_none(xpath_text(asset, 'bitrateAudio')), | |
135 | 'vcodec': xpath_text(asset, 'codecVideo'), | |
136 | 'acodec': xpath_text(asset, 'codecAudio'), | |
137 | 'container': xpath_text(asset, 'mediaType'), | |
138 | 'filesize': int_or_none(xpath_text(asset, 'size')), | |
139 | } | |
140 | format_url = self._proto_relative_url(format_url) | |
141 | if format_url: | |
142 | http_format_info = format_info.copy() | |
143 | http_format_info.update({ | |
144 | 'url': format_url, | |
add96eb9 | 145 | 'format_id': f'http-{asset_type}', |
5625bd06 | 146 | }) |
147 | formats.append(http_format_info) | |
148 | server_prefix = xpath_text(asset, 'serverPrefix') | |
149 | if server_prefix: | |
150 | rtmp_format_info = format_info.copy() | |
151 | rtmp_format_info.update({ | |
152 | 'url': server_prefix, | |
153 | 'play_path': xpath_text(asset, 'fileName'), | |
add96eb9 | 154 | 'format_id': f'rtmp-{asset_type}', |
5625bd06 | 155 | }) |
156 | formats.append(rtmp_format_info) | |
06aabfc4 | 157 | return formats |
3eb38acb | 158 | |
5625bd06 | 159 | def _extract_thumbnails(self, variants, base_url): |
06aabfc4 | 160 | thumbnails = [{ |
5625bd06 | 161 | 'url': base_url + xpath_text(variant, 'url'), |
162 | 'width': int_or_none(xpath_text(variant, 'width')), | |
163 | 'height': int_or_none(xpath_text(variant, 'height')), | |
164 | } for variant in variants.findall('variant') if xpath_text(variant, 'url')] | |
ef2041eb | 165 | thumbnails.sort(key=lambda x: x['width'] * x['height'], reverse=True) |
3eb38acb | 166 | return thumbnails |