2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..utils import ExtractorError
10 class BRIE(InfoExtractor):
11 IE_DESC = "Bayerischer Rundfunk Mediathek"
12 _VALID_URL = r"^https?://(?:www\.)?br\.de/mediathek/video/(?:sendungen/)?(?P<id>[a-z0-9\-]+)\.html$"
13 _BASE_URL = "http://www.br.de"
16 "url": "http://www.br.de/mediathek/video/anselm-gruen-114.html",
17 "md5": "c4f83cf0f023ba5875aba0bf46860df2",
19 "id": "2c8d81c5-6fb7-4a74-88d4-e768e5856532",
21 "title": "Feiern und Verzichten",
22 "description": "Anselm GrĂ¼n: Feiern und Verzichten",
23 "uploader": "BR/Birgit Baier",
24 "upload_date": "20140301"
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 display_id = mobj.group('id')
31 page = self._download_webpage(url, display_id)
32 xml_url = self._search_regex(
33 r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/mediathek/video/[a-z0-9/~_.-]+)'}\)\);", page, "XMLURL")
34 xml = self._download_xml(self._BASE_URL + xml_url, None)
37 "id": xml_video.get("externalId"),
38 "title": xml_video.find("title").text,
39 "formats": self._extract_formats(xml_video.find("assets")),
40 "thumbnails": self._extract_thumbnails(xml_video.find("teaserImage/variants")),
41 "description": " ".join(xml_video.find("shareTitle").text.splitlines()),
42 "uploader": xml_video.find("author").text,
43 "upload_date": "".join(reversed(xml_video.find("broadcastDate").text.split("."))),
44 "webpage_url": xml_video.find("permalink").text,
45 } for xml_video in xml.findall("video")]
48 self._downloader.report_warning(
49 'found multiple videos; please '
50 'report this with the video URL to http://yt-dl.org/bug')
52 raise ExtractorError('No video entries found')
55 def _extract_formats(self, assets):
57 "url": asset.find("downloadUrl").text,
58 "ext": asset.find("mediaType").text,
59 "format_id": asset.get("type"),
60 "width": int(asset.find("frameWidth").text),
61 "height": int(asset.find("frameHeight").text),
62 "tbr": int(asset.find("bitrateVideo").text),
63 "abr": int(asset.find("bitrateAudio").text),
64 "vcodec": asset.find("codecVideo").text,
65 "container": asset.find("mediaType").text,
66 "filesize": int(asset.find("size").text),
67 } for asset in assets.findall("asset")
68 if asset.find("downloadUrl") is not None]
70 self._sort_formats(formats)
73 def _extract_thumbnails(self, variants):
75 "url": self._BASE_URL + variant.find("url").text,
76 "width": int(variant.find("width").text),
77 "height": int(variant.find("height").text),
78 } for variant in variants.findall("variant")]
79 thumbnails.sort(key=lambda x: x["width"] * x["height"], reverse=True)