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.

171 lines
7.4 KiB

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