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

Code before:
        else:
            stream_url = stream_info.get('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',
                        '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

            info.update({
                'extractor_key': NhkVodIE.ie_key(),
                'extractor': NhkVodIE.ie_key(),
            })

        return info


class NhkVodIE(NhkBaseIE):
    _VALID_URL = [
        rf'{NhkBaseIE._BASE_URL_REGEX}shows/(?:(?P<type>video)/)?(?P<id>\d{{4}}[\da-z]\d+)/?(?:$|[?#])',
        rf'{NhkBaseIE._BASE_URL_REGEX}(?:ondemand|shows)/(?P<type>audio)/(?P<id>[^/?#]+?-\d{{8}}-[\da-z]+)',
        rf'{NhkBaseIE._BASE_URL_REGEX}ondemand/(?P<type>video)/(?P<id>\d{{4}}[\da-z]\d+)',  # deprecated
    ]
    # Content available only for a limited period of time. Visit
    # https://www3.nhk.or.jp/nhkworld/en/ondemand/ for working samples.
    _TESTS = [{
        'url': 'https://www3.nhk.or.jp/nhkworld/en/shows/2049165/',
        'info_dict': {
            'id': '2049165-en',
            'ext': 'mp4',
            'title': 'Japan Railway Journal - Choshi Electric Railway: Fighting to Get Back on Track',
            'description': 'md5:ab57df2fca7f04245148c2e787bb203d',
            'thumbnail': r're:https://.+/.+\.jpg',
            'episode': 'Choshi Electric Railway: Fighting to Get Back on Track',
            'series': 'Japan Railway Journal',
            'duration': 1680,
            'categories': ['Biz & Tech'],
            'tags': ['Akita', 'Chiba', 'Trains', 'All (Japan Navigator)'],

Review comment (refactor):
is this method used directly by a playlist extractor?

if not, then this is unnecessary

if so, then unindent this block so the fields are still added when `--ignore-no-formats` is passed (or even better, remove this block and add these fields when the info dict is first constructed)

Code after:
                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

        return info


class NhkVodIE(NhkBaseIE):
    _VALID_URL = [
        rf'{NhkBaseIE._BASE_URL_REGEX}shows/(?:(?P<type>video)/)?(?P<id>\d{{4}}[\da-z]\d+)/?(?:$|[?#])',
        rf'{NhkBaseIE._BASE_URL_REGEX}(?:ondemand|shows)/(?P<type>audio)/(?P<id>[^/?#]+?-\d{{8}}-[\da-z]+)',
        rf'{NhkBaseIE._BASE_URL_REGEX}ondemand/(?P<type>video)/(?P<id>\d{{4}}[\da-z]\d+)',  # deprecated
    ]
    # Content available only for a limited period of time. Visit
    # https://www3.nhk.or.jp/nhkworld/en/ondemand/ for working samples.
    _TESTS = [{
        'url': 'https://www3.nhk.or.jp/nhkworld/en/shows/2049165/',
        'info_dict': {
            'id': '2049165-en',
            'ext': 'mp4',
            'title': 'Japan Railway Journal - Choshi Electric Railway: Fighting to Get Back on Track',
            'description': 'md5:ab57df2fca7f04245148c2e787bb203d',
            'thumbnail': r're:https://.+/.+\.jpg',
            'episode': 'Choshi Electric Railway: Fighting to Get Back on Track',
            'series': 'Japan Railway Journal',
            'duration': 1680,
            'categories': ['Biz & Tech'],
            'tags': ['Akita', 'Chiba', 'Trains', 'Transcript', 'All (Japan Navigator)'],
            'timestamp': 1759055880,
            'upload_date': '20250928',
            'release_timestamp': 1758810600,
            'release_date': '20250925',
        },
    }, {
        # video clip
        'url': 'https://www3.nhk.or.jp/nhkworld/en/ondemand/video/9999011/',
        'md5': '153c3016dfd252ba09726588149cf0e7',
        'info_dict': {
            'id': '9999011-en',
            'ext': 'mp4',
            'title': 'Dining with the Chef - Chef Saito\'s Family recipe: MENCHI-KATSU',
            'description': 'md5:5aee4a9f9d81c26281862382103b0ea5',
            'thumbnail': r're:https://.+/.+\.jpg',
            'series': 'Dining with the Chef',
            'episode': 'Chef Saito\'s Family recipe: MENCHI-KATSU',
            'duration': 148,
            'categories': ['Food'],
            'tags': ['Washoku'],