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.

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