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

Code before:
        },
        'skip': 'Blocked outside Mainland China',
    }]

    def _process_lyrics(self, lyrics_info):
        original = traverse_obj(lyrics_info, ('lrc', 'lyric', {str}))
        translated = traverse_obj(lyrics_info, ('tlyric', 'lyric', {str}))

        if not original or original == '[99:00.00]纯音乐，请欣赏\n':
            return None

        if not translated:
            return {
                'lyrics': [{'data': original, 'ext': 'lrc'}],
            }

        def _collect_lyrics(lrc):
            lyrics_expr = r'\[([0-9]{2}):([0-9]{2})[:\.]([0-9]{2,})\]([^\n]+)'
            matches = re.findall(lyrics_expr, lrc)
            return (
                (f'[{mm}:{ss}.{sss}]', text)
                for mm, ss, sss, text in matches
            )

        original_ts_texts = _collect_lyrics(original)
        translation_ts_dict = dict(_collect_lyrics(translated))

        merged = '\n'.join(
            join_nonempty(f'{timestamp}{text}', translation_ts_dict.get(timestamp, ''), delim=' / ')
            for timestamp, text in original_ts_texts)

        return {
            'lyrics_merged': [{'data': merged, 'ext': 'lrc'}],
            'lyrics': [{'data': original, 'ext': 'lrc'}],
            'lyrics_translated': [{'data': translated, 'ext': 'lrc'}],
        }

    def _real_extract(self, url):
        song_id = self._match_id(url)

        info = self._query_api(
            f'song/detail?id={song_id}&ids=%5B{song_id}%5D', song_id, 'Downloading song info')['songs'][0]

        formats = self._extract_formats(info)

        lyrics = self._process_lyrics(self._query_api(
            f'song/lyric?id={song_id}&lv=-1&tv=-1', song_id, 'Downloading lyrics data'))
        lyric_data = {
            'description': traverse_obj(lyrics, (('lyrics_merged', 'lyrics'), 0, 'data'), get_all=False),
            'subtitles': lyrics,
        } if lyrics else {}

Review comment (suggestion):
```suggestion
        original_ts_texts = collect_lyrics(original)
        translation_ts_dict = dict(collect_lyrics(translated))
```

Code after:
        },
        'skip': 'Blocked outside Mainland China',
    }]

    def _process_lyrics(self, lyrics_info):
        original = traverse_obj(lyrics_info, ('lrc', 'lyric', {str}))
        translated = traverse_obj(lyrics_info, ('tlyric', 'lyric', {str}))

        if not original or original == '[99:00.00]纯音乐，请欣赏\n':
            return None

        if not translated:
            return {
                'lyrics': [{'data': original, 'ext': 'lrc'}],
            }

        def collect_lyrics(lrc):
            lyrics_expr = r'\[([0-9]{2}):([0-9]{2})[:.]([0-9]{2,})\]([^\n]+)'
            matches = re.findall(lyrics_expr, lrc)
            return (
                (f'[{minute}:{sec}.{msec}]', text)
                for minute, sec, msec, text in matches
            )

        original_ts_texts = collect_lyrics(original)
        translation_ts_dict = dict(collect_lyrics(translated))

        merged = '\n'.join(
            join_nonempty(f'{timestamp}{text}', translation_ts_dict.get(timestamp, ''), delim=' / ')
            for timestamp, text in original_ts_texts)

        return {
            'lyrics_merged': [{'data': merged, 'ext': 'lrc'}],
            'lyrics': [{'data': original, 'ext': 'lrc'}],
            'lyrics_translated': [{'data': translated, 'ext': 'lrc'}],
        }

    def _real_extract(self, url):
        song_id = self._match_id(url)

        info = self._query_api(
            f'song/detail?id={song_id}&ids=%5B{song_id}%5D', song_id, 'Downloading song info')['songs'][0]

        formats = self._extract_formats(info)

        lyrics = self._process_lyrics(self._query_api(
            f'song/lyric?id={song_id}&lv=-1&tv=-1', song_id, 'Downloading lyrics data'))
        lyric_data = {
            'description': traverse_obj(lyrics, (('lyrics_merged', 'lyrics'), 0, 'data'), get_all=False),
            'subtitles': lyrics,
        } if lyrics else {}