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.

139 lines
5.7 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 (
  6. ExtractorError,
  7. int_or_none,
  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/anselm-gruen-114.html',
  16. 'md5': 'c4f83cf0f023ba5875aba0bf46860df2',
  17. 'info_dict': {
  18. 'id': '2c8d81c5-6fb7-4a74-88d4-e768e5856532',
  19. 'ext': 'mp4',
  20. 'title': 'Feiern und Verzichten',
  21. 'description': 'Anselm Grün: Feiern und Verzichten',
  22. 'uploader': 'BR/Birgit Baier',
  23. 'upload_date': '20140301',
  24. }
  25. },
  26. {
  27. 'url': 'http://www.br.de/mediathek/video/sendungen/unter-unserem-himmel/unter-unserem-himmel-alpen-ueber-den-pass-100.html',
  28. 'md5': 'ab451b09d861dbed7d7cc9ab0be19ebe',
  29. 'info_dict': {
  30. 'id': '2c060e69-3a27-4e13-b0f0-668fac17d812',
  31. 'ext': 'mp4',
  32. 'title': 'Über den Pass',
  33. 'description': 'Die Eroberung der Alpen: Über den Pass',
  34. }
  35. },
  36. {
  37. 'url': 'http://www.br.de/nachrichten/schaeuble-haushaltsentwurf-bundestag-100.html',
  38. 'md5': '3db0df1a9a9cd9fa0c70e6ea8aa8e820',
  39. 'info_dict': {
  40. 'id': 'c6aae3de-2cf9-43f2-957f-f17fef9afaab',
  41. 'ext': 'aac',
  42. 'title': '"Keine neuen Schulden im nächsten Jahr"',
  43. 'description': 'Haushaltsentwurf: "Keine neuen Schulden im nächsten Jahr"',
  44. }
  45. },
  46. {
  47. 'url': 'http://www.br.de/radio/bayern1/service/team/videos/team-video-erdelt100.html',
  48. 'md5': 'dbab0aef2e047060ea7a21fc1ce1078a',
  49. 'info_dict': {
  50. 'id': '6ba73750-d405-45d3-861d-1ce8c524e059',
  51. 'ext': 'mp4',
  52. 'title': 'Umweltbewusster Häuslebauer',
  53. 'description': 'Uwe Erdelt: Umweltbewusster Häuslebauer',
  54. }
  55. },
  56. {
  57. 'url': 'http://www.br.de/fernsehen/br-alpha/sendungen/kant-fuer-anfaenger/kritik-der-reinen-vernunft/kant-kritik-01-metaphysik100.html',
  58. 'md5': '23bca295f1650d698f94fc570977dae3',
  59. 'info_dict': {
  60. 'id': 'd982c9ce-8648-4753-b358-98abb8aec43d',
  61. 'ext': 'mp4',
  62. 'title': 'Folge 1 - Metaphysik',
  63. 'description': 'Kant für Anfänger: Folge 1 - Metaphysik',
  64. 'uploader': 'Eva Maria Steimle',
  65. 'upload_date': '20140117',
  66. }
  67. },
  68. ]
  69. def _real_extract(self, url):
  70. mobj = re.match(self._VALID_URL, url)
  71. display_id = mobj.group('id')
  72. page = self._download_webpage(url, display_id)
  73. xml_url = self._search_regex(
  74. r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page, 'XMLURL')
  75. xml = self._download_xml(self._BASE_URL + xml_url, None)
  76. medias = []
  77. for xml_media in xml.findall('video') + xml.findall('audio'):
  78. media = {
  79. 'id': xml_media.get('externalId'),
  80. 'title': xml_media.find('title').text,
  81. 'formats': self._extract_formats(xml_media.find('assets')),
  82. 'thumbnails': self._extract_thumbnails(xml_media.find('teaserImage/variants')),
  83. 'description': ' '.join(xml_media.find('shareTitle').text.splitlines()),
  84. 'webpage_url': xml_media.find('permalink').text
  85. }
  86. if xml_media.find('author').text:
  87. media['uploader'] = xml_media.find('author').text
  88. if xml_media.find('broadcastDate').text:
  89. media['upload_date'] = ''.join(reversed(xml_media.find('broadcastDate').text.split('.')))
  90. medias.append(media)
  91. if len(medias) > 1:
  92. self._downloader.report_warning(
  93. 'found multiple medias; please '
  94. 'report this with the video URL to http://yt-dl.org/bug')
  95. if not medias:
  96. raise ExtractorError('No media entries found')
  97. return medias[0]
  98. def _extract_formats(self, assets):
  99. def text_or_none(asset, tag):
  100. elem = asset.find(tag)
  101. return None if elem is None else elem.text
  102. formats = [{
  103. 'url': text_or_none(asset, 'downloadUrl'),
  104. 'ext': text_or_none(asset, 'mediaType'),
  105. 'format_id': asset.get('type'),
  106. 'width': int_or_none(text_or_none(asset, 'frameWidth')),
  107. 'height': int_or_none(text_or_none(asset, 'frameHeight')),
  108. 'tbr': int_or_none(text_or_none(asset, 'bitrateVideo')),
  109. 'abr': int_or_none(text_or_none(asset, 'bitrateAudio')),
  110. 'vcodec': text_or_none(asset, 'codecVideo'),
  111. 'acodec': text_or_none(asset, 'codecAudio'),
  112. 'container': text_or_none(asset, 'mediaType'),
  113. 'filesize': int_or_none(text_or_none(asset, 'size')),
  114. } for asset in assets.findall('asset')
  115. if asset.find('downloadUrl') is not None]
  116. self._sort_formats(formats)
  117. return formats
  118. def _extract_thumbnails(self, variants):
  119. thumbnails = [{
  120. 'url': self._BASE_URL + variant.find('url').text,
  121. 'width': int_or_none(variant.find('width').text),
  122. 'height': int_or_none(variant.find('height').text),
  123. } for variant in variants.findall('variant')]
  124. thumbnails.sort(key=lambda x: x['width'] * x['height'], reverse=True)
  125. return thumbnails