0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-12-29 01:51:06 +00:00

[NDR] Rewrite NDRIE (#962)

Closes #959 
Authored by: Ashish0804
This commit is contained in:
Ashish Gupta 2021-09-16 23:41:55 +05:30 committed by GitHub
parent b89378a69a
commit 23dd2d9a32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,15 +1,14 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
int_or_none, int_or_none,
merge_dicts, parse_duration,
parse_iso8601,
qualities, qualities,
try_get, try_get,
unified_strdate,
urljoin, urljoin,
) )
@ -28,110 +27,110 @@ class NDRIE(NDRBaseIE):
IE_DESC = 'NDR.de - Norddeutscher Rundfunk' IE_DESC = 'NDR.de - Norddeutscher Rundfunk'
_VALID_URL = r'https?://(?:www\.)?(?:daserste\.)?ndr\.de/(?:[^/]+/)*(?P<display_id>[^/?#]+),(?P<id>[\da-z]+)\.html' _VALID_URL = r'https?://(?:www\.)?(?:daserste\.)?ndr\.de/(?:[^/]+/)*(?P<display_id>[^/?#]+),(?P<id>[\da-z]+)\.html'
_TESTS = [{ _TESTS = [{
# httpVideo, same content id
'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html', 'url': 'http://www.ndr.de/fernsehen/Party-Poette-und-Parade,hafengeburtstag988.html',
'md5': '6515bc255dc5c5f8c85bbc38e035a659',
'info_dict': { 'info_dict': {
'id': 'hafengeburtstag988', 'id': 'hafengeburtstag988',
'display_id': 'Party-Poette-und-Parade',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Party, Pötte und Parade', 'title': 'Party, Pötte und Parade',
'thumbnail': 'https://www.ndr.de/fernsehen/hafengeburtstag990_v-contentxl.jpg',
'description': 'md5:ad14f9d2f91d3040b6930c697e5f6b4c', 'description': 'md5:ad14f9d2f91d3040b6930c697e5f6b4c',
'uploader': 'ndrtv', 'series': None,
'timestamp': 1431108900, 'channel': 'NDR Fernsehen',
'upload_date': '20150510', 'upload_date': '20150508',
'duration': 3498, 'duration': 3498,
}, },
'params': {
'skip_download': True,
},
}, { }, {
# httpVideo, different content id 'url': 'https://www.ndr.de/sport/fussball/Rostocks-Matchwinner-Froede-Ein-Hansa-Debuet-wie-im-Maerchen,hansa10312.html',
'url': 'http://www.ndr.de/sport/fussball/40-Osnabrueck-spielt-sich-in-einen-Rausch,osna270.html', 'only_matching': True
'md5': '1043ff203eab307f0c51702ec49e9a71', }, {
'url': 'https://www.ndr.de/nachrichten/niedersachsen/kommunalwahl_niedersachsen_2021/Grosse-Parteien-zufrieden-mit-Ergebnissen-der-Kommunalwahl,kommunalwahl1296.html',
'info_dict': { 'info_dict': {
'id': 'osna272', 'id': 'kommunalwahl1296',
'display_id': '40-Osnabrueck-spielt-sich-in-einen-Rausch',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Osnabrück - Wehen Wiesbaden: Die Highlights', 'title': 'Die Spitzenrunde: Die Wahl aus Sicht der Landespolitik',
'description': 'md5:32e9b800b3d2d4008103752682d5dc01', 'thumbnail': 'https://www.ndr.de/fernsehen/screenshot1194912_v-contentxl.jpg',
'uploader': 'ndrtv', 'description': 'md5:5c6e2ad744cef499135735a1036d7aa7',
'timestamp': 1442059200, 'series': 'Hallo Niedersachsen',
'upload_date': '20150912', 'channel': 'NDR Fernsehen',
'duration': 510, 'upload_date': '20210913',
}, 'duration': 438,
'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,
},
}, {
# with subtitles
'url': 'https://www.ndr.de/fernsehen/sendungen/extra_3/extra-3-Satiremagazin-mit-Christian-Ehring,sendung1091858.html', 'url': 'https://www.ndr.de/fernsehen/sendungen/extra_3/extra-3-Satiremagazin-mit-Christian-Ehring,sendung1091858.html',
'info_dict': { 'info_dict': {
'id': 'extra18674', 'id': 'sendung1091858',
'display_id': 'extra-3-Satiremagazin-mit-Christian-Ehring',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Extra 3 vom 11.11.2020 mit Christian Ehring', 'title': 'Extra 3 vom 11.11.2020 mit Christian Ehring',
'description': 'md5:42ee53990a715eaaf4dc7f13a3bd56c6', 'thumbnail': 'https://www.ndr.de/fernsehen/screenshot983938_v-contentxl.jpg',
'uploader': 'ndrtv', 'description': 'md5:700f6de264010585012a72f97b0ac0c9',
'upload_date': '20201113', 'series': 'extra 3',
'channel': 'NDR Fernsehen',
'upload_date': '20201111',
'duration': 1749, 'duration': 1749,
'subtitles': { }
'de': [{
'ext': 'ttml',
'url': r're:^https://www\.ndr\.de.+',
}],
},
},
'params': {
'skip_download': True,
},
'expected_warnings': ['Unable to download f4m manifest'],
}, { }, {
'url': 'https://www.ndr.de/Fettes-Brot-Ferris-MC-und-Thees-Uhlmann-live-on-stage,festivalsommer116.html', 'url': 'http://www.ndr.de/info/La-Valette-entgeht-der-Hinrichtung,audio51535.html',
'only_matching': True, 'info_dict': {
'id': 'audio51535',
'ext': 'mp3',
'title': 'La Valette entgeht der Hinrichtung',
'thumbnail': 'https://www.ndr.de/mediathek/mediathekbild140_v-podcast.jpg',
'description': 'md5:22f9541913a40fe50091d5cdd7c9f536',
'upload_date': '20140729',
'duration': 884.0,
},
'expected_warnings': ['unable to extract json url'],
}] }]
def _extract_embed(self, webpage, display_id, id): def _extract_embed(self, webpage, display_id, id):
embed_url = self._html_search_meta( formats = []
'embedURL', webpage, 'embed URL', base_url = 'https://www.ndr.de'
default=None) or self._search_regex( json_url = self._search_regex(r'<iframe[^>]+src=\"([^\"]+)_theme-ndrde[^\.]*\.html\"', webpage,
r'\bembedUrl["\']\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'json url', fatal=False)
'embed URL', fatal=False, group='url') if json_url:
if embed_url is None: data_json = self._download_json(base_url + json_url.replace('ardplayer_image', 'ardjson_image') + '.json',
return self.url_result('ndr:%s' % id, ie=NDREmbedBaseIE.ie_key()) id, fatal=False)
description = self._search_regex( info_json = data_json.get('_info', {})
r'<p[^>]+itemprop="description">([^<]+)</p>', media_json = try_get(data_json, lambda x: x['_mediaArray'][0]['_mediaStreamArray'])
webpage, 'description', default=None) or self._og_search_description(webpage) for media in media_json:
timestamp = parse_iso8601( if media.get('_quality') == 'auto':
self._search_regex( formats.extend(self._extract_m3u8_formats(media['_stream'], id))
r'<span[^>]+itemprop="(?:datePublished|uploadDate)"[^>]+content="([^"]+)"', subtitles = {}
webpage, 'upload date', default=None)) sub_url = data_json.get('_subtitleUrl')
info = self._search_json_ld(webpage, display_id, default={}) if sub_url:
return merge_dicts({ subtitles.setdefault('de', []).append({
'_type': 'url_transparent', 'url': base_url + sub_url,
'url': embed_url, })
'display_id': display_id, self._sort_formats(formats)
'description': description, return {
'timestamp': timestamp, 'id': id,
}, info) 'title': info_json.get('clipTitle'),
'thumbnail': base_url + data_json.get('_previewImage'),
'description': info_json.get('clipDescription'),
'series': info_json.get('seriesTitle') or None,
'channel': info_json.get('channelTitle'),
'upload_date': unified_strdate(info_json.get('clipDate')),
'duration': data_json.get('_duration'),
'formats': formats,
'subtitles': subtitles,
}
else:
json_url = base_url + self._search_regex(r'apiUrl\s?=\s?\'([^\']+)\'', webpage, 'json url').replace(
'_belongsToPodcast-', '')
data_json = self._download_json(json_url, id, fatal=False)
return {
'id': id,
'title': data_json.get('title'),
'thumbnail': base_url + data_json.get('poster'),
'description': data_json.get('summary'),
'upload_date': unified_strdate(data_json.get('publicationDate')),
'duration': parse_duration(data_json.get('duration')),
'formats': [{
'url': try_get(data_json, (lambda x: x['audio'][0]['url'], lambda x: x['files'][0]['url'])),
'vcodec': 'none',
'ext': 'mp3',
}],
}
class NJoyIE(NDRBaseIE): class NJoyIE(NDRBaseIE):