Skip to content

Commit

Permalink
fix(spotify): fix broken spotify lyrics (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloWorld017 authored Dec 2, 2024
1 parent 215a912 commit 8296a72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
17 changes: 11 additions & 6 deletions extensions/alspotron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
});
Expand All @@ -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 = {};
Expand Down
23 changes: 7 additions & 16 deletions src/provider/source/tuna-obs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down

0 comments on commit 8296a72

Please sign in to comment.