Skip to content

Commit 2a66076

Browse files
committed
fix(synced-lyric): optimize logic
1 parent f48e46d commit 2a66076

File tree

1 file changed

+4
-15
lines changed
  • src/plugins/synced-lyrics/renderer/lyrics

1 file changed

+4
-15
lines changed

src/plugins/synced-lyrics/renderer/lyrics/fetch.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,12 @@ export const getLyricsList = async (
132132
const artists = artist.split(/[&,]/g).map((i) => i.trim());
133133
const itemArtists = artistName.split(/[&,]/g).map((i) => i.trim());
134134

135-
const permutations = [];
136-
for (const artistA of artists) {
137-
for (const artistB of itemArtists) {
138-
permutations.push([artistA.toLowerCase(), artistB.toLowerCase()]);
139-
}
140-
}
141-
142-
for (const artistA of itemArtists) {
143-
for (const artistB of artists) {
144-
permutations.push([artistA.toLowerCase(), artistB.toLowerCase()]);
145-
}
146-
}
135+
const permutations = artists.flatMap((artistA) =>
136+
itemArtists.map((artistB) => [artistA.toLowerCase(), artistB.toLowerCase()])
137+
);
147138

148139
const ratio = Math.max(...permutations.map(([x, y]) => jaroWinkler(x, y)));
149-
150-
if (ratio <= 0.9) continue;
151-
filteredResults.push(item);
140+
if (ratio > 0.9) filteredResults.push(item);
152141
}
153142

154143
const duration = songData.songDuration;

0 commit comments

Comments
 (0)