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.

134 lines
5.5 KiB

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