From 2ffe3bc14b5e65c902fe5ddd610143c791edaa52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sun, 13 Sep 2015 04:15:49 +0600 Subject: [PATCH] [ndr] Rework and cover with tests --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/ndr.py | 469 ++++++++++++++++++++++--------- 2 files changed, 334 insertions(+), 136 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 44ab7ce3c..fadba905d 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -367,6 +367,7 @@ from .nbc import ( from .ndr import ( NDRIE, NJoyIE, + NDREmbedBaseIE, NDREmbedIE, NJoyEmbedIE, ) diff --git a/youtube_dl/extractor/ndr.py b/youtube_dl/extractor/ndr.py index 87f3edbbe..e3cc6fde8 100644 --- a/youtube_dl/extractor/ndr.py +++ b/youtube_dl/extractor/ndr.py @@ -1,183 +1,380 @@ -# encoding: utf-8 +# coding: utf-8 from __future__ import unicode_literals +import re + from .common import InfoExtractor from ..utils import ( - ExtractorError, + determine_ext, int_or_none, + parse_iso8601, qualities, ) -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']+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) + display_id = self._match_id(url) + webpage = self._download_webpage(url, display_id) + return self._extract_embed(webpage, display_id) class NDRIE(NDRBaseIE): IE_NAME = 'ndr' - IE_DESC = 'NDR.de - Mediathek' - _VALID_URL = r'https?://www\.ndr\.de/.+?,(?P\w+)\.html' + IE_DESC = 'NDR.de - Norddeutscher Rundfunk' + _VALID_URL = r'https?://www\.ndr\.de/(?:[^/]+/)+(?P[^/?#]+),[\da-z]+\.html' + _TESTS = [{ + # httpVideo, same content id + 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html', + 'md5': '6515bc255dc5c5f8c85bbc38e035a659', + 'info_dict': { + 'id': 'hafengeburtstag988', + 'display_id': 'Party-Poette-und-Parade', + 'ext': 'mp4', + 'title': 'Party, Pötte und Parade', + 'description': 'md5:ad14f9d2f91d3040b6930c697e5f6b4c', + 'uploader': 'ndrtv', + 'timestamp': 1431108900, + 'upload_date': '20150510', + 'duration': 3498, + }, + 'params': { + 'skip_download': True, + }, + }, { + # httpVideo, different content id + 'url': 'http://www.ndr.de/sport/fussball/40-Osnabrueck-spielt-sich-in-einen-Rausch,osna270.html', + 'md5': '1043ff203eab307f0c51702ec49e9a71', + 'info_dict': { + 'id': 'osna272', + 'display_id': '40-Osnabrueck-spielt-sich-in-einen-Rausch', + 'ext': 'mp4', + 'title': 'Osnabrück - Wehen Wiesbaden: Die Highlights', + 'description': 'md5:32e9b800b3d2d4008103752682d5dc01', + 'uploader': 'ndrtv', + 'timestamp': 1442059200, + 'upload_date': '20150912', + 'duration': 510, + }, + 'params': { + 'skip_download': True, + }, + }, { + # httpAudio, same content id + 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html', + 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8', + 'info_dict': { + 'id': 'audio51535', + 'display_id': 'La-Valette-entgeht-der-Hinrichtung', + 'ext': 'mp3', + 'title': 'La Valette entgeht der Hinrichtung', + 'description': 'md5:22f9541913a40fe50091d5cdd7c9f536', + 'uploader': 'ndrinfo', + 'timestamp': 1290626100, + 'upload_date': '20140729', + 'duration': 884, + }, + 'params': { + 'skip_download': True, + }, + }] - _TESTS = [ - { - 'url': 'http://www.ndr.de/fernsehen/sendungen/nordmagazin/Kartoffeltage-in-der-Lewitz,nordmagazin25866.html', - 'md5': '5bc5f5b92c82c0f8b26cddca34f8bb2c', - 'note': 'Video file', - 'info_dict': { - 'id': 'nordmagazin25866', - 'ext': 'mp4', - 'title': 'Kartoffeltage in der Lewitz', - 'duration': 166, - }, - 'skip': '404 Not found', - }, - { - 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html', - 'md5': 'dadc003c55ae12a5d2f6bd436cd73f59', - 'info_dict': { - 'id': 'hafengeburtstag988', - 'ext': 'mp4', - 'title': 'Party, Pötte und Parade', - 'duration': 3498, - }, - }, - { - 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html', - 'md5': 'bb3cd38e24fbcc866d13b50ca59307b8', - 'note': 'Audio file', - 'info_dict': { - 'id': 'audio51535', - 'ext': 'mp3', - 'title': 'La Valette entgeht der Hinrichtung', - 'duration': 884, - } + def _extract_embed(self, webpage, display_id): + embed_url = self._html_search_meta( + 'embedURL', webpage, 'embed URL', fatal=True) + description = self._search_regex( + r']+itemprop="description">([^<]+)

', + webpage, 'description', fatal=False) + timestamp = parse_iso8601( + self._search_regex( + r'