From 8296a72cbcb5e91455ce7a726d5b50ff27d3228e Mon Sep 17 00:00:00 2001 From: Khinenw Date: Mon, 2 Dec 2024 18:03:41 +0900 Subject: [PATCH] fix(spotify): fix broken spotify lyrics (#1309) --- extensions/alspotron.js | 17 +++++++++++------ src/provider/source/tuna-obs.ts | 23 +++++++---------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/extensions/alspotron.js b/extensions/alspotron.js index f86cc429..d5934937 100644 --- a/extensions/alspotron.js +++ b/extensions/alspotron.js @@ -6,8 +6,12 @@ const LyricResolvers = { v2(uri) { return Spicetify.CosmosAsync - .get(`wg://lyrics/v1/track/${uri.id}`) - .then(payload => payload.lines) + .get(`https://spclient.wg.spotify.com/color-lyrics/v2/track/${uri.id}?format=json&vocalRemoval=false&market=from_token`) + .then(payload => + payload.lyrics.syncType === 'LINE_SYNCED' + ? payload.lyrics.lines + : Promise.reject('No synced lyrics') + ) .catch(() => { return []; }); @@ -21,10 +25,11 @@ const getLyric = async () => { const uri = Spicetify.URI.from(Spicetify.Player.data.item.uri); const lines = await LyricResolvers.current(uri); - return lines.reduce((lyric, line) => { - lyric[line.time] = line.words.map(v => v.string).filter(v => v); - return lyric; - }, {}); + return lines + .reduce((lyric, line) => { + lyric[line.startTimeMs] = [line.words]; + return lyric; + }, {}); }; let previousInfo = {}; diff --git a/src/provider/source/tuna-obs.ts b/src/provider/source/tuna-obs.ts index 3c9b9ebd..123a95ba 100644 --- a/src/provider/source/tuna-obs.ts +++ b/src/provider/source/tuna-obs.ts @@ -163,30 +163,21 @@ export class TunaObsProvider extends BaseSourceProvider { provider: 'tuna-obs', }; - if (data.data.status === 'playing') { - result.data = { - type: 'playing', - id: `${data.data.title}:${data.data.cover_url}`, - title: data.data.title ?? '', - artists: data.data.artists ?? [], - progress: data.data.progress ?? 0, - duration: data.data.duration ?? 0, - coverUrl: data.data.cover_url ?? '', - playerLyrics: data.data.lyrics, - metadata: data, - }; - } + if (data.data.status === 'playing' || data.data.status === 'paused') { + const id = `${data.data.title}:${data.data.cover_url}`; + const lastLyric = this.lastUpdateData?.data.type !== 'idle' && this.lastUpdateData?.data.id === id + ? this.lastUpdateData.data.playerLyrics + : undefined; - if (data.data.status === 'paused') { result.data = { - type: 'paused', + type: data.data.status, id: `${data.data.title}:${data.data.cover_url}`, title: data.data.title ?? '', artists: data.data.artists ?? [], progress: data.data.progress ?? 0, duration: data.data.duration ?? 0, coverUrl: data.data.cover_url ?? '', - playerLyrics: data.data.lyrics, + playerLyrics: data.data.lyrics ?? lastLyric, metadata: data, }; }