You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.3 KiB

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