formatLyric static method
格式化歌词
Implementation
static List<Lyric> formatLyric(String lyricStr) {
if (lyricStr.trim().length == 0) {
return [];
}
lyricStr = lyricStr.replaceAll("\r", "");
RegExp reg = RegExp(r"""\[(.*?):(.*?)\](.*?)\n""");
late Iterable<Match> matches;
try {
matches = reg.allMatches(lyricStr);
} catch (e) {
print(e.toString());
}
List<Lyric> lyrics = [];
List<Match> list = matches.toList();
for (int i = 0; i < list.length; i++) {
var temp = list[i];
var title = temp[1];
if (!tags.contains(title) && list[i][3] != "") {
lyrics.add(
Lyric(
lyric: list[i][3],
startTime: lyricTimeToDuration(
"${temp[1]}:${temp[2]}",
),
),
);
}
}
//移除所有空歌词
lyrics.removeWhere((lyric) => lyric.lyric!.trim().isEmpty);
for (int i = 0; i < lyrics.length - 1; i++) {
lyrics[i].endTime = lyrics[i + 1].startTime;
}
lyrics.last.endTime = Duration(hours: 200);
return lyrics;
}