]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/br.py
Annotate changelog with bug closed.
[youtubedl] / youtube_dl / extractor / br.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 int_or_none,
8 parse_duration,
9 )
10
11
12 class BRIE(InfoExtractor):
13 IE_DESC = 'Bayerischer Rundfunk Mediathek'
14 _VALID_URL = r'https?://(?:www\.)?br\.de/(?:[a-z0-9\-_]+/)+(?P<id>[a-z0-9\-_]+)\.html'
15 _BASE_URL = 'http://www.br.de'
16
17 _TESTS = [
18 {
19 'url': 'http://www.br.de/mediathek/video/sendungen/abendschau/betriebliche-altersvorsorge-104.html',
20 'md5': '83a0477cf0b8451027eb566d88b51106',
21 'info_dict': {
22 'id': '48f656ef-287e-486f-be86-459122db22cc',
23 'ext': 'mp4',
24 'title': 'Die böse Überraschung',
25 'description': 'Betriebliche Altersvorsorge: Die böse Überraschung',
26 'duration': 180,
27 'uploader': 'Reinhard Weber',
28 'upload_date': '20150422',
29 }
30 },
31 {
32 'url': 'http://www.br.de/nachrichten/oberbayern/inhalt/muenchner-polizeipraesident-schreiber-gestorben-100.html',
33 'md5': 'a44396d73ab6a68a69a568fae10705bb',
34 'info_dict': {
35 'id': 'a4b83e34-123d-4b81-9f4e-c0d3121a4e05',
36 'ext': 'mp4',
37 'title': 'Manfred Schreiber ist tot',
38 'description': 'Abendschau kompakt: Manfred Schreiber ist tot',
39 'duration': 26,
40 }
41 },
42 {
43 'url': 'http://www.br.de/radio/br-klassik/sendungen/allegro/premiere-urauffuehrung-the-land-2015-dance-festival-muenchen-100.html',
44 'md5': '8b5b27c0b090f3b35eac4ab3f7a73d3d',
45 'info_dict': {
46 'id': '74c603c9-26d3-48bb-b85b-079aeed66e0b',
47 'ext': 'aac',
48 'title': 'Kurzweilig und sehr bewegend',
49 'description': '"The Land" von Peeping Tom: Kurzweilig und sehr bewegend',
50 'duration': 296,
51 }
52 },
53 {
54 'url': 'http://www.br.de/radio/bayern1/service/team/videos/team-video-erdelt100.html',
55 'md5': 'dbab0aef2e047060ea7a21fc1ce1078a',
56 'info_dict': {
57 'id': '6ba73750-d405-45d3-861d-1ce8c524e059',
58 'ext': 'mp4',
59 'title': 'Umweltbewusster Häuslebauer',
60 'description': 'Uwe Erdelt: Umweltbewusster Häuslebauer',
61 'duration': 116,
62 }
63 },
64 {
65 'url': 'http://www.br.de/fernsehen/br-alpha/sendungen/kant-fuer-anfaenger/kritik-der-reinen-vernunft/kant-kritik-01-metaphysik100.html',
66 'md5': '23bca295f1650d698f94fc570977dae3',
67 'info_dict': {
68 'id': 'd982c9ce-8648-4753-b358-98abb8aec43d',
69 'ext': 'mp4',
70 'title': 'Folge 1 - Metaphysik',
71 'description': 'Kant für Anfänger: Folge 1 - Metaphysik',
72 'duration': 893,
73 'uploader': 'Eva Maria Steimle',
74 'upload_date': '20140117',
75 }
76 },
77 ]
78
79 def _real_extract(self, url):
80 display_id = self._match_id(url)
81 page = self._download_webpage(url, display_id)
82 xml_url = self._search_regex(
83 r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page, 'XMLURL')
84 xml = self._download_xml(self._BASE_URL + xml_url, None)
85
86 medias = []
87
88 for xml_media in xml.findall('video') + xml.findall('audio'):
89 media = {
90 'id': xml_media.get('externalId'),
91 'title': xml_media.find('title').text,
92 'duration': parse_duration(xml_media.find('duration').text),
93 'formats': self._extract_formats(xml_media.find('assets')),
94 'thumbnails': self._extract_thumbnails(xml_media.find('teaserImage/variants')),
95 'description': ' '.join(xml_media.find('shareTitle').text.splitlines()),
96 'webpage_url': xml_media.find('permalink').text
97 }
98 if xml_media.find('author').text:
99 media['uploader'] = xml_media.find('author').text
100 if xml_media.find('broadcastDate').text:
101 media['upload_date'] = ''.join(reversed(xml_media.find('broadcastDate').text.split('.')))
102 medias.append(media)
103
104 if len(medias) > 1:
105 self._downloader.report_warning(
106 'found multiple medias; please '
107 'report this with the video URL to http://yt-dl.org/bug')
108 if not medias:
109 raise ExtractorError('No media entries found')
110 return medias[0]
111
112 def _extract_formats(self, assets):
113
114 def text_or_none(asset, tag):
115 elem = asset.find(tag)
116 return None if elem is None else elem.text
117
118 formats = [{
119 'url': text_or_none(asset, 'downloadUrl'),
120 'ext': text_or_none(asset, 'mediaType'),
121 'format_id': asset.get('type'),
122 'width': int_or_none(text_or_none(asset, 'frameWidth')),
123 'height': int_or_none(text_or_none(asset, 'frameHeight')),
124 'tbr': int_or_none(text_or_none(asset, 'bitrateVideo')),
125 'abr': int_or_none(text_or_none(asset, 'bitrateAudio')),
126 'vcodec': text_or_none(asset, 'codecVideo'),
127 'acodec': text_or_none(asset, 'codecAudio'),
128 'container': text_or_none(asset, 'mediaType'),
129 'filesize': int_or_none(text_or_none(asset, 'size')),
130 } for asset in assets.findall('asset')
131 if asset.find('downloadUrl') is not None]
132
133 self._sort_formats(formats)
134 return formats
135
136 def _extract_thumbnails(self, variants):
137 thumbnails = [{
138 'url': self._BASE_URL + variant.find('url').text,
139 'width': int_or_none(variant.find('width').text),
140 'height': int_or_none(variant.find('height').text),
141 } for variant in variants.findall('variant')]
142 thumbnails.sort(key=lambda x: x['width'] * x['height'], reverse=True)
143 return thumbnails