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.

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