ndr.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. )
  8. preferences = {'xl': 4, 'l': 3, 'm': 2, 's': 1, 'xs': 0,}
  9. class NDRBaseIE(InfoExtractor):
  10. def extract_video_info(self, playlist, video_id):
  11. formats = []
  12. streamType = playlist.get('config').get('streamType')
  13. if streamType == 'httpVideo':
  14. for key, f in playlist.items():
  15. if key != 'config':
  16. src = f['src']
  17. if '.f4m' in src:
  18. formats.extend(self._extract_f4m_formats(src, video_id))
  19. elif '.m3u8' in src:
  20. formats.extend(self._extract_m3u8_formats(src, video_id, fatal=False))
  21. else:
  22. quality = f.get('quality')
  23. formats.append({
  24. 'url': src,
  25. 'format_id': quality,
  26. 'preference': preferences.get(quality),
  27. })
  28. elif streamType == 'httpAudio':
  29. for key, f in playlist.items():
  30. if key != 'config':
  31. formats.append({
  32. 'url': f['src'],
  33. 'format_id': 'mp3',
  34. 'vcodec': 'none',
  35. })
  36. else:
  37. raise ExtractorError('No media links available for %s' % video_id)
  38. self._sort_formats(formats)
  39. config = playlist.get('config')
  40. title = config['title']
  41. duration = int_or_none(config.get('duration'))
  42. thumbnails = [{
  43. 'id': thumbnail.get('quality'),
  44. 'url': thumbnail.get('src'),
  45. 'preference': preferences.get(thumbnail.get('quality'))
  46. } for thumbnail in config.get('poster').values()]
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'thumbnails': thumbnails,
  51. 'duration': duration,
  52. 'formats': formats,
  53. }
  54. def _real_extract(self, url):
  55. video_id = self._match_id(url)
  56. json_data = self._download_json('http://www.ndr.de/%s-ppjson.json' % video_id, video_id, fatal=False)
  57. if not json_data:
  58. webpage = self._download_webpage(url, video_id)
  59. embed_url = self._html_search_regex(r'<iframe[^>]+id="pp_\w+"[^>]+src="(/.*)"', webpage, 'embed url', None, False)
  60. if not embed_url:
  61. embed_url = self._html_search_meta('embedURL', webpage, fatal=False)
  62. if embed_url:
  63. if embed_url.startswith('/'):
  64. return self.url_result('http://www.ndr.de%s' % embed_url, 'NDREmbed')
  65. else:
  66. return self.url_result(embed_url, 'NDREmbed')
  67. raise ExtractorError('No media links available for %s' % video_id)
  68. return self.extract_video_info(json_data['playlist'], video_id)
  69. class NDRIE(NDRBaseIE):
  70. IE_NAME = 'ndr'
  71. IE_DESC = 'NDR.de - Mediathek'
  72. _VALID_URL = r'https?://www\.ndr\.de/.+?,(?P<id>\w+)\.html'
  73. _TESTS = [
  74. {
  75. 'url': 'http://www.ndr.de/fernsehen/sendungen/nordmagazin/Kartoffeltage-in-der-Lewitz,nordmagazin25866.html',
  76. 'md5': '5bc5f5b92c82c0f8b26cddca34f8bb2c',
  77. 'note': 'Video file',
  78. 'info_dict': {
  79. 'id': 'nordmagazin25866',
  80. 'ext': 'mp4',
  81. 'title': 'Kartoffeltage in der Lewitz',
  82. 'duration': 166,
  83. },
  84. 'skip': '404 Not found',
  85. },
  86. {
  87. 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
  88. 'md5': 'dadc003c55ae12a5d2f6bd436cd73f59',
  89. 'info_dict': {
  90. 'id': 'hafengeburtstag988',
  91. 'ext': 'mp4',
  92. 'title': 'Party, Pötte und Parade',
  93. 'duration': 3498,
  94. },
  95. },
  96. {
  97. 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html',
  98. 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8',
  99. 'note': 'Audio file',
  100. 'info_dict': {
  101. 'id': 'audio51535',
  102. 'ext': 'mp3',
  103. 'title': 'La Valette entgeht der Hinrichtung',
  104. 'duration': 884,
  105. }
  106. }
  107. ]
  108. class NJoyIE(NDRBaseIE):
  109. IE_NAME = 'N-JOY'
  110. _VALID_URL = r'https?://www\.n-joy\.de/.+?,(?P<id>\w+)\.html'
  111. _TEST = {
  112. 'url': 'http://www.n-joy.de/entertainment/comedy/comedy_contest/Benaissa-beim-NDR-Comedy-Contest,comedycontest2480.html',
  113. 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
  114. 'info_dict': {
  115. 'id': 'comedycontest2480',
  116. 'ext': 'mp4',
  117. 'title': 'Benaissa beim NDR Comedy Contest',
  118. 'duration': 654,
  119. }
  120. }
  121. class NDREmbedBaseIE(NDRBaseIE):
  122. def _real_extract(self, url):
  123. video_id = self._match_id(url)
  124. json_data = self._download_json('http://www.ndr.de/%s-ppjson.json' % video_id, video_id, fatal=False)
  125. if not json_data:
  126. raise ExtractorError('No media links available for %s' % video_id)
  127. return self.extract_video_info(json_data['playlist'], video_id)
  128. class NDREmbedIE(NDREmbedBaseIE):
  129. IE_NAME = 'ndr:embed'
  130. _VALID_URL = r'https?://www\.ndr\.de/(?:[^/]+/)+(?P<id>\w+)'
  131. _TEST = {
  132. 'url': 'http://www.ndr.de/fernsehen/sendungen/ndr_aktuell/ndraktuell28488-player.html',
  133. 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
  134. 'info_dict': {
  135. 'id': 'ndraktuell28488',
  136. 'ext': 'mp4',
  137. 'title': 'Norddeutschland begrüßt Flüchtlinge',
  138. 'duration': 132,
  139. }
  140. }
  141. class NJoyEmbedIE(NDREmbedBaseIE):
  142. IE_NAME = 'N-JOY:embed'
  143. _VALID_URL = r'https?://www\.n-joy\.de/(?:[^/]+/)(?P<id>\w+)'
  144. _TEST = {
  145. 'url': 'http://www.n-joy.de/entertainment/film/portraet374-player_image-832d9b79-fa8a-4026-92e2-e0fd99deb2f9_theme-n-joy.html',
  146. 'md5': 'cb63be60cd6f9dd75218803146d8dc67',
  147. 'info_dict': {
  148. 'id': 'portraet374',
  149. 'ext': 'mp4',
  150. 'title': 'Viviane Andereggen - "Schuld um Schuld"',
  151. 'duration': 129,
  152. }
  153. }