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.

168 lines
7.3 KiB

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. parse_duration,
  9. xpath_element,
  10. xpath_text,
  11. )
  12. class BRIE(InfoExtractor):
  13. IE_DESC = 'Bayerischer Rundfunk Mediathek'
  14. _VALID_URL = r'(?P<base_url>https?://(?:www\.)?br(?:-klassik)?\.de)/(?:[a-z0-9\-_]+/)+(?P<id>[a-z0-9\-_]+)\.html'
  15. _TESTS = [
  16. {
  17. 'url': 'http://www.br.de/mediathek/video/sendungen/abendschau/betriebliche-altersvorsorge-104.html',
  18. 'md5': '83a0477cf0b8451027eb566d88b51106',
  19. 'info_dict': {
  20. 'id': '48f656ef-287e-486f-be86-459122db22cc',
  21. 'ext': 'mp4',
  22. 'title': 'Die böse Überraschung',
  23. 'description': 'md5:ce9ac81b466ce775b8018f6801b48ac9',
  24. 'duration': 180,
  25. 'uploader': 'Reinhard Weber',
  26. 'upload_date': '20150422',
  27. }
  28. },
  29. {
  30. 'url': 'http://www.br.de/nachrichten/oberbayern/inhalt/muenchner-polizeipraesident-schreiber-gestorben-100.html',
  31. 'md5': 'af3a3a4aa43ff0ce6a89504c67f427ef',
  32. 'info_dict': {
  33. 'id': 'a4b83e34-123d-4b81-9f4e-c0d3121a4e05',
  34. 'ext': 'flv',
  35. 'title': 'Manfred Schreiber ist tot',
  36. 'description': 'md5:b454d867f2a9fc524ebe88c3f5092d97',
  37. 'duration': 26,
  38. }
  39. },
  40. {
  41. 'url': 'https://www.br-klassik.de/audio/peeping-tom-premierenkritik-dance-festival-muenchen-100.html',
  42. 'md5': '8b5b27c0b090f3b35eac4ab3f7a73d3d',
  43. 'info_dict': {
  44. 'id': '74c603c9-26d3-48bb-b85b-079aeed66e0b',
  45. 'ext': 'aac',
  46. 'title': 'Kurzweilig und sehr bewegend',
  47. 'description': 'md5:0351996e3283d64adeb38ede91fac54e',
  48. 'duration': 296,
  49. }
  50. },
  51. {
  52. 'url': 'http://www.br.de/radio/bayern1/service/team/videos/team-video-erdelt100.html',
  53. 'md5': 'dbab0aef2e047060ea7a21fc1ce1078a',
  54. 'info_dict': {
  55. 'id': '6ba73750-d405-45d3-861d-1ce8c524e059',
  56. 'ext': 'mp4',
  57. 'title': 'Umweltbewusster Häuslebauer',
  58. 'description': 'md5:d52dae9792d00226348c1dbb13c9bae2',
  59. 'duration': 116,
  60. }
  61. },
  62. {
  63. 'url': 'http://www.br.de/fernsehen/br-alpha/sendungen/kant-fuer-anfaenger/kritik-der-reinen-vernunft/kant-kritik-01-metaphysik100.html',
  64. 'md5': '23bca295f1650d698f94fc570977dae3',
  65. 'info_dict': {
  66. 'id': 'd982c9ce-8648-4753-b358-98abb8aec43d',
  67. 'ext': 'mp4',
  68. 'title': 'Folge 1 - Metaphysik',
  69. 'description': 'md5:bb659990e9e59905c3d41e369db1fbe3',
  70. 'duration': 893,
  71. 'uploader': 'Eva Maria Steimle',
  72. 'upload_date': '20140117',
  73. }
  74. },
  75. ]
  76. def _real_extract(self, url):
  77. base_url, display_id = re.search(self._VALID_URL, url).groups()
  78. page = self._download_webpage(url, display_id)
  79. xml_url = self._search_regex(
  80. r"return BRavFramework\.register\(BRavFramework\('avPlayer_(?:[a-f0-9-]{36})'\)\.setup\({dataURL:'(/(?:[a-z0-9\-]+/)+[a-z0-9/~_.-]+)'}\)\);", page, 'XMLURL')
  81. xml = self._download_xml(base_url + xml_url, display_id)
  82. medias = []
  83. for xml_media in xml.findall('video') + xml.findall('audio'):
  84. media_id = xml_media.get('externalId')
  85. media = {
  86. 'id': media_id,
  87. 'title': xpath_text(xml_media, 'title', 'title', True),
  88. 'duration': parse_duration(xpath_text(xml_media, 'duration')),
  89. 'formats': self._extract_formats(xpath_element(
  90. xml_media, 'assets'), media_id),
  91. 'thumbnails': self._extract_thumbnails(xpath_element(
  92. xml_media, 'teaserImage/variants'), base_url),
  93. 'description': xpath_text(xml_media, 'desc'),
  94. 'webpage_url': xpath_text(xml_media, 'permalink'),
  95. 'uploader': xpath_text(xml_media, 'author'),
  96. }
  97. broadcast_date = xpath_text(xml_media, 'broadcastDate')
  98. if broadcast_date:
  99. media['upload_date'] = ''.join(reversed(broadcast_date.split('.')))
  100. medias.append(media)
  101. if len(medias) > 1:
  102. self._downloader.report_warning(
  103. 'found multiple medias; please '
  104. 'report this with the video URL to http://yt-dl.org/bug')
  105. if not medias:
  106. raise ExtractorError('No media entries found')
  107. return medias[0]
  108. def _extract_formats(self, assets, media_id):
  109. formats = []
  110. for asset in assets.findall('asset'):
  111. format_url = xpath_text(asset, ['downloadUrl', 'url'])
  112. asset_type = asset.get('type')
  113. if asset_type == 'HDS':
  114. formats.extend(self._extract_f4m_formats(
  115. format_url + '?hdcore=3.2.0', media_id, f4m_id='hds', fatal=False))
  116. elif asset_type == 'HLS':
  117. formats.extend(self._extract_m3u8_formats(
  118. format_url, media_id, 'mp4', 'm3u8_native', m3u8_id='hds', fatal=False))
  119. else:
  120. format_info = {
  121. 'ext': xpath_text(asset, 'mediaType'),
  122. 'width': int_or_none(xpath_text(asset, 'frameWidth')),
  123. 'height': int_or_none(xpath_text(asset, 'frameHeight')),
  124. 'tbr': int_or_none(xpath_text(asset, 'bitrateVideo')),
  125. 'abr': int_or_none(xpath_text(asset, 'bitrateAudio')),
  126. 'vcodec': xpath_text(asset, 'codecVideo'),
  127. 'acodec': xpath_text(asset, 'codecAudio'),
  128. 'container': xpath_text(asset, 'mediaType'),
  129. 'filesize': int_or_none(xpath_text(asset, 'size')),
  130. }
  131. format_url = self._proto_relative_url(format_url)
  132. if format_url:
  133. http_format_info = format_info.copy()
  134. http_format_info.update({
  135. 'url': format_url,
  136. 'format_id': 'http-%s' % asset_type,
  137. })
  138. formats.append(http_format_info)
  139. server_prefix = xpath_text(asset, 'serverPrefix')
  140. if server_prefix:
  141. rtmp_format_info = format_info.copy()
  142. rtmp_format_info.update({
  143. 'url': server_prefix,
  144. 'play_path': xpath_text(asset, 'fileName'),
  145. 'format_id': 'rtmp-%s' % asset_type,
  146. })
  147. formats.append(rtmp_format_info)
  148. self._sort_formats(formats)
  149. return formats
  150. def _extract_thumbnails(self, variants, base_url):
  151. thumbnails = [{
  152. 'url': base_url + xpath_text(variant, 'url'),
  153. 'width': int_or_none(xpath_text(variant, 'width')),
  154. 'height': int_or_none(xpath_text(variant, 'height')),
  155. } for variant in variants.findall('variant') if xpath_text(variant, 'url')]
  156. thumbnails.sort(key=lambda x: x['width'] * x['height'], reverse=True)
  157. return thumbnails