Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/npo.py (Python)

Code before:
        if urllib.parse.urlparse(url).netloc in ['www.ntr.nl', 'ntr.nl']:
            player = self._download_json(
                'https://www.ntr.nl/ajax/player/embed/%s' % video_id, video_id,
                'Downloading player JSON', query={
                    'parameters[elementId]': 'npo' + str(random.randint(0, 999)),
                    'parameters[sterReferralUrl]': url,
                    'parameters[autoplay]': 0,
                })
        else:
            self._request_webpage(
                'https://www.npostart.nl/api/token', video_id,
                'Downloading token', headers={
                    'Referer': url,
                    'X-Requested-With': 'XMLHttpRequest',
                })
            player = self._download_json(
                'https://www.npostart.nl/player/%s' % video_id, video_id,
                'Downloading player JSON', data=urlencode_postdata({
                    'autoplay': 0,
                    'share': 1,
                    'pageUrl': url,
                    'hasAdConsent': 0,
                }), headers={
                    'x-xsrf-token': try_call(lambda: urllib.parse.unquote(
                        self._get_cookies('https://www.npostart.nl')['XSRF-TOKEN'].value))
                })

        player_token = player['token']

        drm = False
        format_urls = set()
        formats = []
        for profile in ('hls', 'dash-widevine', 'dash-playready', 'smooth'):
            streams = self._download_json(
                'https://start-player.npo.nl/video/%s/streams' % video_id,
                video_id, 'Downloading %s profile JSON' % profile, fatal=False,
                query={
                    'profile': profile,
                    'quality': 'npoplus',
                    'tokenId': player_token,
                    'streamType': 'broadcast',
                })
            if not streams:
                continue
            stream = streams.get('stream')
            if not isinstance(stream, dict):
                continue
            stream_url = url_or_none(stream.get('src'))
            if not stream_url or stream_url in format_urls:
                continue
            format_urls.add(stream_url)

Review comment (suggestion):
```suggestion
            player = self._download_json(
                f'https://www.ntr.nl/ajax/player/embed/{video_id}', video_id,
                'Downloading player JSON', query={
                    'parameters[elementId]': f'npo{random.randint(0, 999)}',
                    'parameters[sterReferralUrl]': url,
                    'parameters[autoplay]': 0,
                })
        else:
            self._request_webpage(
                'https://www.npostart.nl/api/token', video_id,
                'Downloading token', headers={
                    'Referer': url,
                    'X-Requested-With': 'XMLHttpRequest',
                })
            player = self._download_json(
                f'https://www.npostart.nl/player/{video_id}', video_id,
                'Downloading player JSON', data=urlencode_postdata({
                    'autoplay': 0,
                    'share': 1,
                    'pageUrl': url,
                    'hasAdConsent': 0,
                }), headers={
                    'x-xsrf-token': try_call(lambda: urllib.parse.unquote(
                        self._get_cookies('https://www.npostart.nl')['XSRF-TOKEN'].value))
                })
```

Code after:
        if urllib.parse.urlparse(url).netloc in ['www.ntr.nl', 'ntr.nl']:
            player = self._download_json(
                f'https://www.ntr.nl/ajax/player/embed/{video_id}', video_id,
                'Downloading player JSON', query={
                    'parameters[elementId]': f'npo{random.randint(0, 999)}',
                    'parameters[sterReferralUrl]': url,
                    'parameters[autoplay]': 0,
                })
        else:
            self._request_webpage(
                'https://www.npostart.nl/api/token', video_id,
                'Downloading token', headers={
                    'Referer': url,
                    'X-Requested-With': 'XMLHttpRequest',
                })
            player = self._download_json(
                f'https://www.npostart.nl/player/{video_id}', video_id,
                'Downloading player JSON', data=urlencode_postdata({
                    'autoplay': 0,
                    'share': 1,
                    'pageUrl': url,
                    'hasAdConsent': 0,
                }), headers={
                    'x-xsrf-token': try_call(lambda: urllib.parse.unquote(
                        self._get_cookies('https://www.npostart.nl')['XSRF-TOKEN'].value))
                })

        player_token = player['token']

        drm = False
        format_urls = set()
        formats = []
        for profile in ('hls', 'dash-widevine', 'dash-playready', 'smooth'):
            streams = self._download_json(
                'https://start-player.npo.nl/video/%s/streams' % video_id,
                video_id, 'Downloading %s profile JSON' % profile, fatal=False,
                query={
                    'profile': profile,
                    'quality': 'npoplus',
                    'tokenId': player_token,
                    'streamType': 'broadcast',
                })
            if not streams:
                continue
            stream = streams.get('stream')
            if not isinstance(stream, dict):
                continue
            stream_url = url_or_none(stream.get('src'))
            if not stream_url or stream_url in format_urls:
                continue
            format_urls.add(stream_url)