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.

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