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.

99 lines
4.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 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/)?(?:[a-z0-9\-/]+/)?(?P<id>[a-z0-9\-]+)\.html$"
  9. _BASE_URL = "http://www.br.de"
  10. _TESTS = [
  11. {
  12. "url": "http://www.br.de/mediathek/video/anselm-gruen-114.html",
  13. "md5": "c4f83cf0f023ba5875aba0bf46860df2",
  14. "info_dict": {
  15. "id": "2c8d81c5-6fb7-4a74-88d4-e768e5856532",
  16. "ext": "mp4",
  17. "title": "Feiern und Verzichten",
  18. "description": "Anselm Grün: Feiern und Verzichten",
  19. "uploader": "BR/Birgit Baier",
  20. "upload_date": "20140301"
  21. }
  22. },
  23. {
  24. "url": "http://www.br.de/mediathek/video/sendungen/unter-unserem-himmel/unter-unserem-himmel-alpen-ueber-den-pass-100.html",
  25. "md5": "ab451b09d861dbed7d7cc9ab0be19ebe",
  26. "info_dict": {
  27. "id": "2c060e69-3a27-4e13-b0f0-668fac17d812",
  28. "ext": "mp4",
  29. "title": "Über den Pass",
  30. "description": "Die Eroberung der Alpen: Über den Pass",
  31. "uploader": None,
  32. "upload_date": None
  33. }
  34. }
  35. ]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. display_id = mobj.group('id')
  39. page = self._download_webpage(url, display_id)
  40. xml_url = self._search_regex(
  41. r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/mediathek/video/[a-z0-9/~_.-]+)'}\)\);", page, "XMLURL")
  42. xml = self._download_xml(self._BASE_URL + xml_url, None)
  43. videos = []
  44. for xml_video in xml.findall("video"):
  45. video = {
  46. "id": xml_video.get("externalId"),
  47. "title": xml_video.find("title").text,
  48. "formats": self._extract_formats(xml_video.find("assets")),
  49. "thumbnails": self._extract_thumbnails(xml_video.find("teaserImage/variants")),
  50. "description": " ".join(xml_video.find("shareTitle").text.splitlines()),
  51. "webpage_url": xml_video.find("permalink").text
  52. }
  53. if xml_video.find("author").text:
  54. video["uploader"] = xml_video.find("author").text
  55. if xml_video.find("broadcastDate").text:
  56. video["upload_date"] = "".join(reversed(xml_video.find("broadcastDate").text.split(".")))
  57. videos.append(video)
  58. if len(videos) > 1:
  59. self._downloader.report_warning(
  60. 'found multiple videos; please '
  61. 'report this with the video URL to http://yt-dl.org/bug')
  62. if not videos:
  63. raise ExtractorError('No video entries found')
  64. return videos[0]
  65. def _extract_formats(self, assets):
  66. formats = [{
  67. "url": asset.find("downloadUrl").text,
  68. "ext": asset.find("mediaType").text,
  69. "format_id": asset.get("type"),
  70. "width": int(asset.find("frameWidth").text),
  71. "height": int(asset.find("frameHeight").text),
  72. "tbr": int(asset.find("bitrateVideo").text),
  73. "abr": int(asset.find("bitrateAudio").text),
  74. "vcodec": asset.find("codecVideo").text,
  75. "container": asset.find("mediaType").text,
  76. "filesize": int(asset.find("size").text),
  77. } for asset in assets.findall("asset")
  78. if asset.find("downloadUrl") is not None]
  79. self._sort_formats(formats)
  80. return formats
  81. def _extract_thumbnails(self, variants):
  82. thumbnails = [{
  83. "url": self._BASE_URL + variant.find("url").text,
  84. "width": int(variant.find("width").text),
  85. "height": int(variant.find("height").text),
  86. } for variant in variants.findall("variant")]
  87. thumbnails.sort(key=lambda x: x["width"] * x["height"], reverse=True)
  88. return thumbnails