2014-02-21 11:28:30 -05:00
|
|
|
# coding: utf-8
|
2014-02-22 14:17:26 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2014-02-21 11:28:30 -05:00
|
|
|
from .common import InfoExtractor
|
2014-04-09 09:19:27 -04:00
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
int_or_none,
|
2014-07-27 13:51:38 -04:00
|
|
|
parse_duration,
|
2014-04-09 09:19:27 -04:00
|
|
|
)
|
2014-02-21 11:28:30 -05:00
|
|
|
|
|
|
|
|
2014-02-22 14:17:26 -05:00
|
|
|
class BRIE(InfoExtractor):
|
2014-04-09 09:19:27 -04:00
|
|
|
IE_DESC = 'Bayerischer Rundfunk Mediathek'
|
2014-07-21 14:42:20 -04:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?br\.de/(?:[a-z0-9\-_]+/)+(?P<id>[a-z0-9\-_]+)\.html'
|
2014-04-09 09:19:27 -04:00
|
|
|
_BASE_URL = 'http://www.br.de'
|
2014-02-21 11:28:30 -05:00
|
|
|
|
2014-03-13 09:01:20 -04:00
|
|
|
_TESTS = [
|
|
|
|
{
|
2014-06-22 11:33:27 -04:00
|
|
|
'url': 'http://www.br.de/mediathek/video/sendungen/heimatsound/heimatsound-festival-2014-trailer-100.html',
|
|
|
|
'md5': '93556dd2bcb2948d9259f8670c516d59',
|
2014-04-09 09:19:27 -04:00
|
|
|
'info_dict': {
|
2014-06-22 11:33:27 -04:00
|
|
|
'id': '25e279aa-1ffd-40fd-9955-5325bd48a53a',
|
2014-04-09 09:19:27 -04:00
|
|
|
'ext': 'mp4',
|
2014-07-27 13:45:46 -04:00
|
|
|
'title': 'Wenn das Traditions-Theater wackelt',
|
|
|
|
'description': 'Heimatsound-Festival 2014: Wenn das Traditions-Theater wackelt',
|
2014-07-27 13:51:38 -04:00
|
|
|
'duration': 34,
|
2014-09-28 23:40:20 -04:00
|
|
|
'uploader': 'BR',
|
|
|
|
'upload_date': '20140802',
|
2014-03-13 09:01:20 -04:00
|
|
|
}
|
|
|
|
},
|
2014-04-09 09:19:27 -04:00
|
|
|
{
|
|
|
|
'url': 'http://www.br.de/nachrichten/schaeuble-haushaltsentwurf-bundestag-100.html',
|
|
|
|
'md5': '3db0df1a9a9cd9fa0c70e6ea8aa8e820',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'c6aae3de-2cf9-43f2-957f-f17fef9afaab',
|
|
|
|
'ext': 'aac',
|
|
|
|
'title': '"Keine neuen Schulden im nächsten Jahr"',
|
|
|
|
'description': 'Haushaltsentwurf: "Keine neuen Schulden im nächsten Jahr"',
|
2014-07-27 13:51:38 -04:00
|
|
|
'duration': 64,
|
2014-04-09 09:19:27 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'url': 'http://www.br.de/radio/bayern1/service/team/videos/team-video-erdelt100.html',
|
|
|
|
'md5': 'dbab0aef2e047060ea7a21fc1ce1078a',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '6ba73750-d405-45d3-861d-1ce8c524e059',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Umweltbewusster Häuslebauer',
|
|
|
|
'description': 'Uwe Erdelt: Umweltbewusster Häuslebauer',
|
2014-07-27 13:51:38 -04:00
|
|
|
'duration': 116,
|
2014-04-09 09:19:27 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'url': 'http://www.br.de/fernsehen/br-alpha/sendungen/kant-fuer-anfaenger/kritik-der-reinen-vernunft/kant-kritik-01-metaphysik100.html',
|
|
|
|
'md5': '23bca295f1650d698f94fc570977dae3',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'd982c9ce-8648-4753-b358-98abb8aec43d',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Folge 1 - Metaphysik',
|
|
|
|
'description': 'Kant für Anfänger: Folge 1 - Metaphysik',
|
2014-07-27 13:51:38 -04:00
|
|
|
'duration': 893,
|
2014-04-09 09:19:27 -04:00
|
|
|
'uploader': 'Eva Maria Steimle',
|
|
|
|
'upload_date': '20140117',
|
|
|
|
}
|
|
|
|
},
|
2014-03-13 09:01:20 -04:00
|
|
|
]
|
2014-02-21 11:28:30 -05:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2014-09-28 23:40:20 -04:00
|
|
|
display_id = self._match_id(url)
|
2014-02-22 14:17:26 -05:00
|
|
|
page = self._download_webpage(url, display_id)
|
|
|
|
xml_url = self._search_regex(
|
2014-04-09 09:19:27 -04:00
|
|
|
r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page, 'XMLURL')
|
2014-02-21 11:28:30 -05:00
|
|
|
xml = self._download_xml(self._BASE_URL + xml_url, None)
|
|
|
|
|
2014-04-09 09:19:27 -04:00
|
|
|
medias = []
|
|
|
|
|
|
|
|
for xml_media in xml.findall('video') + xml.findall('audio'):
|
|
|
|
media = {
|
|
|
|
'id': xml_media.get('externalId'),
|
|
|
|
'title': xml_media.find('title').text,
|
2014-07-27 13:51:38 -04:00
|
|
|
'duration': parse_duration(xml_media.find('duration').text),
|
2014-04-09 09:19:27 -04:00
|
|
|
'formats': self._extract_formats(xml_media.find('assets')),
|
|
|
|
'thumbnails': self._extract_thumbnails(xml_media.find('teaserImage/variants')),
|
|
|
|
'description': ' '.join(xml_media.find('shareTitle').text.splitlines()),
|
|
|
|
'webpage_url': xml_media.find('permalink').text
|
2014-03-13 09:01:20 -04:00
|
|
|
}
|
2014-04-09 09:19:27 -04:00
|
|
|
if xml_media.find('author').text:
|
|
|
|
media['uploader'] = xml_media.find('author').text
|
|
|
|
if xml_media.find('broadcastDate').text:
|
|
|
|
media['upload_date'] = ''.join(reversed(xml_media.find('broadcastDate').text.split('.')))
|
|
|
|
medias.append(media)
|
2014-02-21 11:28:30 -05:00
|
|
|
|
2014-04-09 09:19:27 -04:00
|
|
|
if len(medias) > 1:
|
2014-02-22 14:17:26 -05:00
|
|
|
self._downloader.report_warning(
|
2014-04-09 09:19:27 -04:00
|
|
|
'found multiple medias; please '
|
2014-02-22 14:17:26 -05:00
|
|
|
'report this with the video URL to http://yt-dl.org/bug')
|
2014-04-09 09:19:27 -04:00
|
|
|
if not medias:
|
|
|
|
raise ExtractorError('No media entries found')
|
|
|
|
return medias[0]
|
2014-02-21 11:28:30 -05:00
|
|
|
|
|
|
|
def _extract_formats(self, assets):
|
2014-04-09 09:19:27 -04:00
|
|
|
|
|
|
|
def text_or_none(asset, tag):
|
|
|
|
elem = asset.find(tag)
|
|
|
|
return None if elem is None else elem.text
|
|
|
|
|
2014-02-22 14:17:26 -05:00
|
|
|
formats = [{
|
2014-04-09 09:19:27 -04:00
|
|
|
'url': text_or_none(asset, 'downloadUrl'),
|
|
|
|
'ext': text_or_none(asset, 'mediaType'),
|
|
|
|
'format_id': asset.get('type'),
|
|
|
|
'width': int_or_none(text_or_none(asset, 'frameWidth')),
|
|
|
|
'height': int_or_none(text_or_none(asset, 'frameHeight')),
|
|
|
|
'tbr': int_or_none(text_or_none(asset, 'bitrateVideo')),
|
|
|
|
'abr': int_or_none(text_or_none(asset, 'bitrateAudio')),
|
|
|
|
'vcodec': text_or_none(asset, 'codecVideo'),
|
|
|
|
'acodec': text_or_none(asset, 'codecAudio'),
|
|
|
|
'container': text_or_none(asset, 'mediaType'),
|
|
|
|
'filesize': int_or_none(text_or_none(asset, 'size')),
|
|
|
|
} for asset in assets.findall('asset')
|
|
|
|
if asset.find('downloadUrl') is not None]
|
2014-02-22 14:17:26 -05:00
|
|
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
return formats
|
2014-02-21 11:28:30 -05:00
|
|
|
|
|
|
|
def _extract_thumbnails(self, variants):
|
2014-02-22 14:17:26 -05:00
|
|
|
thumbnails = [{
|
2014-04-09 09:19:27 -04:00
|
|
|
'url': self._BASE_URL + variant.find('url').text,
|
|
|
|
'width': int_or_none(variant.find('width').text),
|
|
|
|
'height': int_or_none(variant.find('height').text),
|
|
|
|
} for variant in variants.findall('variant')]
|
|
|
|
thumbnails.sort(key=lambda x: x['width'] * x['height'], reverse=True)
|
2014-02-21 11:28:30 -05:00
|
|
|
return thumbnails
|