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

Code before:
            episode_name = None
        else:  # title, no series
            episode_name = None

        info = {
            'id': video_id,
            'title': title,
            'series': series,
            'episode': episode_name,
            **traverse_obj(episode, {
                'description': ('description', {str}),
                'release_timestamp': ('first_broadcasted_at', {unified_timestamp}),
                'categories': ('categories', ..., 'name', {str}),
                'tags': ('tags', ..., 'name', {str}),
                'thumbnails': ('images', lambda _, v: v['url'], {
                    'url': ('url', {urljoin(url)}),
                    'width': ('width', {int_or_none}),
                    'height': ('height', {int_or_none}),
                }),
                'webpage_url': ('url', {urljoin(url)}),
            }),
            'extractor_key': NhkVodIE.ie_key(),
            'extractor': NhkVodIE.ie_key(),
        }

        # FOOLISH ASSUMPTION: an episode can't be video and audio at the same time
        stream_info = traverse_obj(episode, (('video', 'audio'), {dict}, any)) or {}
        if not stream_info.get('url'):
            self.raise_no_formats('Stream not found; it has most likely expired', expected=True)
        else:
            stream_url = stream_info['url']
            if is_video:
                formats, subtitles = self._extract_m3u8_formats_and_subtitles(stream_url, video_id)
                info.update({
                    'formats': formats,
                    'subtitles': subtitles,
                    **traverse_obj(stream_info, ({
                        'duration': ('duration', {int_or_none}),
                        'timestamp': ('published_at', {unified_timestamp}),
                    })),
                })
            else:
                # From https://www3.nhk.or.jp/nhkworld/common/player/radio/inline/rod.html
                audio_path = remove_end(stream_url, '.m4a')
                info['formats'] = self._extract_m3u8_formats(
                    f'{urljoin("https://vod-stream.nhk.jp", audio_path)}/index.m3u8',
                    episode_id, 'm4a', entry_protocol='m3u8_native',
                    m3u8_id='hls', fatal=False)
                for f in info['formats']:
                    f['language'] = lang


Review comment (suggestion):
```suggestion
        # XXX: We are assuming that 'video' and 'audio' are mutually exclusive
```

Code after:
            episode_name = None
        else:  # title, no series
            episode_name = None

        info = {
            'id': video_id,
            'title': title,
            'series': series,
            'episode': episode_name,
            **traverse_obj(episode, {
                'description': ('description', {str}),
                'release_timestamp': ('first_broadcasted_at', {unified_timestamp}),
                'categories': ('categories', ..., 'name', {str}),
                'tags': ('tags', ..., 'name', {str}),
                'thumbnails': ('images', lambda _, v: v['url'], {
                    'url': ('url', {urljoin(url)}),
                    'width': ('width', {int_or_none}),
                    'height': ('height', {int_or_none}),
                }),
                'webpage_url': ('url', {urljoin(url)}),
            }),
            'extractor_key': NhkVodIE.ie_key(),
            'extractor': NhkVodIE.IE_NAME,
        }

        # XXX: We are assuming that 'video' and 'audio' are mutually exclusive
        stream_info = traverse_obj(episode, (('video', 'audio'), {dict}, any)) or {}
        if not stream_info.get('url'):
            self.raise_no_formats('Stream not found; it has most likely expired', expected=True)
        else:
            stream_url = stream_info['url']
            if is_video:
                formats, subtitles = self._extract_m3u8_formats_and_subtitles(stream_url, video_id)
                info.update({
                    'formats': formats,
                    'subtitles': subtitles,
                    **traverse_obj(stream_info, ({
                        'duration': ('duration', {int_or_none}),
                        'timestamp': ('published_at', {unified_timestamp}),
                    })),
                })
            else:
                # From https://www3.nhk.or.jp/nhkworld/common/player/radio/inline/rod.html
                audio_path = remove_end(stream_url, '.m4a')
                info['formats'] = self._extract_m3u8_formats(
                    f'{urljoin("https://vod-stream.nhk.jp", audio_path)}/index.m3u8',
                    episode_id, 'm4a', entry_protocol='m3u8_native',
                    m3u8_id='hls', fatal=False)
                for f in info['formats']:
                    f['language'] = lang