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