]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | ExtractorError, | |
4 | int_or_none, | |
5 | parse_duration, | |
6 | xpath_element, | |
7 | xpath_text, | |
8 | ) | |
9 | ||
10 | ||
11 | class BRIE(InfoExtractor): | |
12 | _WORKING = False | |
13 | IE_DESC = 'Bayerischer Rundfunk' | |
14 | _VALID_URL = r'(?P<base_url>https?://(?:www\.)?br(?:-klassik)?\.de)/(?:[a-z0-9\-_]+/)+(?P<id>[a-z0-9\-_]+)\.html' | |
15 | ||
16 | _TESTS = [ | |
17 | { | |
18 | 'url': 'http://www.br.de/mediathek/video/sendungen/abendschau/betriebliche-altersvorsorge-104.html', | |
19 | 'md5': '83a0477cf0b8451027eb566d88b51106', | |
20 | 'info_dict': { | |
21 | 'id': '48f656ef-287e-486f-be86-459122db22cc', | |
22 | 'ext': 'mp4', | |
23 | 'title': 'Die böse Überraschung', | |
24 | 'description': 'md5:ce9ac81b466ce775b8018f6801b48ac9', | |
25 | 'duration': 180, | |
26 | 'uploader': 'Reinhard Weber', | |
27 | 'upload_date': '20150422', | |
28 | }, | |
29 | 'skip': '404 not found', | |
30 | }, | |
31 | { | |
32 | 'url': 'http://www.br.de/nachrichten/oberbayern/inhalt/muenchner-polizeipraesident-schreiber-gestorben-100.html', | |
33 | 'md5': 'af3a3a4aa43ff0ce6a89504c67f427ef', | |
34 | 'info_dict': { | |
35 | 'id': 'a4b83e34-123d-4b81-9f4e-c0d3121a4e05', | |
36 | 'ext': 'flv', | |
37 | 'title': 'Manfred Schreiber ist tot', | |
38 | 'description': 'md5:b454d867f2a9fc524ebe88c3f5092d97', | |
39 | 'duration': 26, | |
40 | }, | |
41 | 'skip': '404 not found', | |
42 | }, | |
43 | { | |
44 | 'url': 'https://www.br-klassik.de/audio/peeping-tom-premierenkritik-dance-festival-muenchen-100.html', | |
45 | 'md5': '8b5b27c0b090f3b35eac4ab3f7a73d3d', | |
46 | 'info_dict': { | |
47 | 'id': '74c603c9-26d3-48bb-b85b-079aeed66e0b', | |
48 | 'ext': 'aac', | |
49 | 'title': 'Kurzweilig und sehr bewegend', | |
50 | 'description': 'md5:0351996e3283d64adeb38ede91fac54e', | |
51 | 'duration': 296, | |
52 | }, | |
53 | 'skip': '404 not found', | |
54 | }, | |
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', | |
62 | 'description': 'md5:d52dae9792d00226348c1dbb13c9bae2', | |
63 | 'duration': 116, | |
64 | } | |
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', | |
73 | 'description': 'md5:bb659990e9e59905c3d41e369db1fbe3', | |
74 | 'duration': 893, | |
75 | 'uploader': 'Eva Maria Steimle', | |
76 | 'upload_date': '20170208', | |
77 | } | |
78 | }, | |
79 | ] | |
80 | ||
81 | def _real_extract(self, url): | |
82 | base_url, display_id = self._match_valid_url(url).groups() | |
83 | page = self._download_webpage(url, display_id) | |
84 | xml_url = self._search_regex( | |
85 | r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page, 'XMLURL') | |
86 | xml = self._download_xml(base_url + xml_url, display_id) | |
87 | ||
88 | medias = [] | |
89 | ||
90 | for xml_media in xml.findall('video') + xml.findall('audio'): | |
91 | media_id = xml_media.get('externalId') | |
92 | media = { | |
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'), | |
103 | } | |
104 | broadcast_date = xpath_text(xml_media, 'broadcastDate') | |
105 | if broadcast_date: | |
106 | media['upload_date'] = ''.join(reversed(broadcast_date.split('.'))) | |
107 | medias.append(media) | |
108 | ||
109 | if len(medias) > 1: | |
110 | self.report_warning( | |
111 | 'found multiple medias; please ' | |
112 | 'report this with the video URL to http://yt-dl.org/bug') | |
113 | if not medias: | |
114 | raise ExtractorError('No media entries found') | |
115 | return medias[0] | |
116 | ||
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') | |
122 | if asset_type.startswith('HDS'): | |
123 | formats.extend(self._extract_f4m_formats( | |
124 | format_url + '?hdcore=3.2.0', media_id, f4m_id='hds', fatal=False)) | |
125 | elif asset_type.startswith('HLS'): | |
126 | formats.extend(self._extract_m3u8_formats( | |
127 | format_url, media_id, 'mp4', 'm3u8_native', m3u8_id='hds', fatal=False)) | |
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, | |
145 | 'format_id': 'http-%s' % asset_type, | |
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'), | |
154 | 'format_id': 'rtmp-%s' % asset_type, | |
155 | }) | |
156 | formats.append(rtmp_format_info) | |
157 | return formats | |
158 | ||
159 | def _extract_thumbnails(self, variants, base_url): | |
160 | thumbnails = [{ | |
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')] | |
165 | thumbnails.sort(key=lambda x: x['width'] * x['height'], reverse=True) | |
166 | return thumbnails |