From 0dc7d954cb1492834cb07706624b497de4420e23 Mon Sep 17 00:00:00 2001 From: Bart Broere Date: Fri, 1 Mar 2024 15:05:30 +0100 Subject: [PATCH] Comply with coding conventions a bit more --- youtube_dl/extractor/npo.py | 44 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/youtube_dl/extractor/npo.py b/youtube_dl/extractor/npo.py index 52e7096c1..502d276ff 100644 --- a/youtube_dl/extractor/npo.py +++ b/youtube_dl/extractor/npo.py @@ -65,30 +65,29 @@ class NPOIE(InfoExtractor): url = url[:-9] elif url.endswith('/afspelen/'): url = url[:-10] - if url.endswith('/'): - url = url[:-1] + url = url.rstrip('/') slug = url.split('/')[-1] page = self._download_webpage(url, slug, 'Finding productId using slug: %s' % slug) # TODO find out what proper HTML parsing utilities are available in youtube-dl next_data = page.split('')[0] next_data = json.loads(next_data) - product_id, description, thumbnail, title = None, None, None, None + product_id, title, description, thumbnail = None, None, None, None for query in next_data['props']['pageProps']['dehydratedState']['queries']: if isinstance(query['state']['data'], list): for entry in query['state']['data']: - print(entry) - try: - if entry['slug'] == slug: - product_id = entry['productId'] - title = entry['title'] - synopsis = entry['synopsis'] - description = synopsis.get('long', synopsis.get('short', synopsis.get('brief', ''))) - thumbnail = entry['images'][0]['url'] - break - except KeyError: - continue - except IndexError: - continue + if entry['slug'] == slug: + product_id = entry.get('productId') + title = entry.get('title') + synopsis = entry.get('synopsis', {}) + description = ( + synopsis.get('long') + or synopsis.get('short') + or synopsis.get('brief') + ) + thumbnails = entry.get('images') + for thumbnail_entry in thumbnails: + if 'url' in thumbnail_entry: + thumbnail = thumbnail_entry.get('url') if not product_id: raise ExtractorError('No productId found for slug: %s' % slug) @@ -97,19 +96,18 @@ class NPOIE(InfoExtractor): stream_link = self._download_json( 'https://prod.npoplayer.nl/stream-link', video_id=slug, data=json.dumps({ - "profileName": "dash", - "drmType": "widevine", - "referrerUrl": url, + 'profileName': 'dash', + 'drmType': 'widevine', + 'referrerUrl': url, }).encode('utf8'), headers={ - "Authorization": token, - "Content-Type": "application/json", + 'Authorization': token, + 'Content-Type': 'application/json', } ) - stream_url = stream_link['stream']['streamURL'] - # TODO other formats than dash / mpd + stream_url = stream_link.get('stream', {}).get('streamURL') mpd = self._extract_mpd_formats(stream_url, slug, mpd_id='dash', fatal=False) return {