Skip to content

Commit 22cf2b0

Browse files
domplingdomplingrxri
authored
fix(lyrics-plus/netease): check correctly for songs (#3018)
Co-authored-by: dompling <374779789@qq.com> Co-authored-by: ririxi <dev@ririxi.dev>
1 parent e50f6e2 commit 22cf2b0

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

CustomApps/lyrics-plus/ProviderNetease.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const ProviderNetease = (() => {
1919
// normalized expected album name
2020
const neAlbumName = Utils.normalize(info.album);
2121
const expectedAlbumName = Utils.containsHanCharacter(neAlbumName) ? await Utils.toSimplifiedChinese(neAlbumName) : neAlbumName;
22-
const itemId = items.findIndex(val => Utils.normalize(val.album.name) === expectedAlbumName || Math.abs(info.duration - val.duration) < 1000);
22+
let itemId = items.findIndex(val => Utils.normalize(val.album.name) === expectedAlbumName);
23+
if (itemId === -1) itemId = items.findIndex(val => Math.abs(info.duration - val.duration) < 3000);
24+
if (itemId === -1) itemId = items.findIndex(val => val.name === cleanTitle);
2325
if (itemId === -1) throw "Cannot find track";
2426

2527
return await Spicetify.CosmosAsync.get(lyricURL + items[itemId].id, null, requestHeader);

CustomApps/lyrics-plus/Utils.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,32 +134,58 @@ const Utils = {
134134
},
135135
processTranslatedLyrics(result, lyricsToTranslate, { state, stateName }) {
136136
const translatedLines = result.split("\n");
137-
138137
state[stateName] = [];
139-
140-
for (let i = 0; i < lyricsToTranslate.length; i++)
141-
state[stateName].push({
138+
for (let i = 0; i < lyricsToTranslate.length; i++) {
139+
const lyric = {
142140
startTime: lyricsToTranslate[i].startTime || 0,
143141
text: this.rubyTextToReact(translatedLines[i])
144-
});
142+
};
143+
state[stateName].push(lyric);
144+
}
145+
},
146+
processTranslatedOriginalLyrics(lyrics, synced) {
147+
const data = [];
148+
const dataSouce = {};
149+
150+
for (const item of lyrics) {
151+
dataSouce[item.startTime] = { translate: item.text };
152+
}
153+
154+
for (const time in synced) {
155+
dataSouce[item.startTime] = {
156+
...dataSouce[item.startTime],
157+
text: item.text
158+
};
159+
}
160+
161+
for (const time in dataSouce) {
162+
const item = dataSouce[time];
163+
const lyric = {
164+
startTime: time || 0,
165+
text: this.rubyTextToOriginalReact(item.translate || item.text, item.text || item.translate)
166+
};
167+
data.push(lyric);
168+
}
169+
170+
return data;
171+
},
172+
rubyTextToOriginalReact(translated, syncedText) {
173+
const react = Spicetify.React;
174+
return react.createElement("p1", null, [react.createElement("ruby", {}, syncedText, react.createElement("rt", null, translated))]);
145175
},
146176
rubyTextToReact(s) {
147177
const react = Spicetify.React;
148-
149178
const rubyElems = s.split("<ruby>");
150179
const reactChildren = [];
151180

152181
reactChildren.push(rubyElems[0]);
153-
154182
for (let i = 1; i < rubyElems.length; i++) {
155183
const kanji = rubyElems[i].split("<rp>")[0];
156184
const furigana = rubyElems[i].split("<rt>")[1].split("</rt>")[0];
157-
158185
reactChildren.push(react.createElement("ruby", null, kanji, react.createElement("rt", null, furigana)));
159186

160187
reactChildren.push(rubyElems[i].split("</ruby>")[1]);
161188
}
162-
163189
return react.createElement("p1", null, reactChildren);
164190
},
165191
formatTime(timestamp) {

0 commit comments

Comments
 (0)