+preference = qualities(['xs', 's', 'm','l', 'xl'])
+
+
+class NDRBaseIE(InfoExtractor):
+
+ def extract_video_info(self, playlist, video_id):
+ formats = []
+ streamType = playlist.get('config').get('streamType')
+ if streamType == 'httpVideo':
+ for key, f in playlist.items():
+ if key != 'config':
+ src = f['src']
+ if '.f4m' in src:
+ formats.extend(self._extract_f4m_formats(src, video_id))
+ elif '.m3u8' in src:
+ formats.extend(self._extract_m3u8_formats(src, video_id, fatal=False))
+ else:
+ quality = f.get('quality')
+ formats.append({
+ 'url': src,
+ 'format_id': quality,
+ 'preference': preference(quality),
+ })
+ elif streamType == 'httpAudio':
+ for key, f in playlist.items():
+ if key != 'config':
+ formats.append({
+ 'url': f['src'],
+ 'format_id': 'mp3',
+ 'vcodec': 'none',
+ })
+ else:
+ raise ExtractorError('No media links available for %s' % video_id)
+
+ self._sort_formats(formats)
+
+ config = playlist.get('config')
+
+ title = config['title']
+ duration = int_or_none(config.get('duration'))
+ thumbnails = [{
+ 'id': thumbnail.get('quality'),
+ 'url': thumbnail.get('src'),
+ 'preference': preference(thumbnail.get('quality'))
+ } for thumbnail in config.get('poster').values()]
+
+ return {
+ 'id': video_id,
+ 'title': title,
+ 'thumbnails': thumbnails,
+ 'duration': duration,
+ 'formats': formats,
+ }
+
+ def _real_extract(self, url):
+ video_id = self._match_id(url)
+
+ json_data = self._download_json('http://www.ndr.de/%s-ppjson.json' % video_id, video_id, fatal=False)
+
+ if not json_data:
+ webpage = self._download_webpage(url, video_id)
+ embed_url = self._html_search_regex(r'<iframe[^>]+id="pp_\w+"[^>]+src="(/.*)"', webpage, 'embed url', None, False)
+ if not embed_url:
+ embed_url = self._html_search_meta('embedURL', webpage, fatal=False)
+ if embed_url:
+ if embed_url.startswith('/'):
+ return self.url_result('http://www.ndr.de%s' % embed_url, 'NDREmbed')
+ else:
+ return self.url_result(embed_url, 'NDREmbed')
+ raise ExtractorError('No media links available for %s' % video_id)
+
+ return self.extract_video_info(json_data['playlist'], video_id)
+
+
+class NDRIE(NDRBaseIE):