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

Code before:
                track_details.append(f'「{name}」')
            if lyricist := track.get('lyricist'):
                track_details.append(f'{lyricist}:作詞')
            if composer := track.get('composer'):
                track_details.append(f'{composer}:作曲')
            if arranger := track.get('arranger'):
                track_details.append(f'{arranger}:編曲')
            track_details.append(self._fetch_artists(track.get('byArtist')))
            track_details.append(self._fetch_duration(track.get('duration')))

            if track.get('label') or track.get('code'):
                track_details.append('＜' + join_nonempty('label', 'code', delim=' ', from_dict=track) + '＞')

            if location := track.get('location'):
                track_details.append(f'～{location}～')

            tracks.append(join_nonempty(*track_details, delim='\n'))

        return '\n\n'.join(tracks)

    def _format_description(self, response):
        act = traverse_obj(response, ('misc', 'actList', {self._format_actlist}))
        music = traverse_obj(response, ('misc', 'musicList', {self._format_musiclist}))
        desc = join_nonempty('epg80', 'epg200', delim='\n\n', from_dict=traverse_obj(response, 'detailedDescription'))

        return join_nonempty(desc, act, music, delim='\n\n')

    def _get_thumbnails(self, thumbs, name, preference=-1):
        thumbnails = []
        if thumbs is None or len(thumbs) == 0:
            return []
        for size, thumb in thumbs:
            if size == 'copyright' or not isinstance(thumb, dict):
                continue
            thumbnails.append({**thumb,
                               'preference': preference,
                               'id': join_nonempty(name, size),
                               })
            preference -= 1
        return thumbnails

    def _extract_extended_metadata(self, episode_id, aa_vinfo):
        service, _, area = traverse_obj(aa_vinfo, (2, {str}, {lambda x: (x or '').partition(',')}))
        dateid = aa_vinfo[3]

        detail_url = try_call(
            lambda: self._API_URL_TMPL.format(broadcastEventId=join_nonempty(service, area, dateid, delim='-')))
        if not detail_url:
            return {}

        response = self._download_json(

Review comment (suggestion):
- adjustments based on above suggestions to the `_format_*` methods
- in `join_nonempty`, if `from_dict` is `None`, then it will join the literal strings `epg80` and `epg200`, so we need to typecheck for `{dict}` and fallback with `or {}`
- can inline in the outer `join_nonempty` call
```suggestion
    def _format_description(self, response):
        detailed_description = traverse_obj(response, ('detailedDescription', {dict})) or {}
        return join_nonempty(
            join_nonempty('epg80', 'epg200', delim='\n\n', from_dict=detailed_description),
            traverse_obj(response, ('misc', 'actList', {self._format_act_list})),
            traverse_obj(response, ('misc', 'musicList', {self._format_music_list})),
            delim='\n\n')
```

Code after:
    def _format_description(self, response):
        detailed_description = traverse_obj(response, ('detailedDescription', {dict})) or {}
        return join_nonempty(
            join_nonempty('epg80', 'epg200', delim='\n\n', from_dict=detailed_description),
            traverse_obj(response, ('misc', 'actList', {self._format_act_list})),
            traverse_obj(response, ('misc', 'musicList', {self._format_music_list})),
            delim='\n\n')

    def _get_thumbnails(self, data, keys, name=None, preference=-1):
        thumbnails = []
        for size, thumb in traverse_obj(data, (
            *variadic(keys, (str, bytes, dict, set)), {dict.items},
            lambda _, v: v[0] != 'copyright' and url_or_none(v[1]['url']),
        )):
            thumbnails.append({
                'url': thumb['url'],
                'width': int_or_none(thumb.get('width')),
                'height': int_or_none(thumb.get('height')),
                'preference': preference,
                'id': join_nonempty(name, size),
            })
            preference -= 1
        return thumbnails

    def _extract_extended_metadata(self, episode_id, aa_vinfo):
        service, _, area = traverse_obj(aa_vinfo, (2, {str}, {lambda x: (x or '').partition(',')}))
        date_id = aa_vinfo[3]

        detail_url = try_call(
            lambda: self._API_URL_TMPL.format(broadcastEventId=join_nonempty(service, area, date_id)))
        if not detail_url:
            return {}

        response = self._download_json(
            detail_url, episode_id, 'Downloading extended metadata',
            'Failed to download extended metadata', fatal=False, expected_status=400)
        if not response:
            return {}

        if error := traverse_obj(response, ('error', {dict})):
            self.report_warning(
                'Failed to get extended metadata. API returned '
                f'Error {join_nonempty("statuscode", "message", from_dict=error, delim=": ")}')
            return {}

        station = traverse_obj(response, ('publishedOn', 'broadcastDisplayName', {str}))

        thumbnails = []
        thumbnails.extend(self._get_thumbnails(response, ('about', 'eyecatch')))
        for num, dct in enumerate(traverse_obj(response, ('about', 'eyecatchList', ...))):
            thumbnails.extend(self._get_thumbnails(dct, None, join_nonempty('list', num), -2))