Skip to content

Commit 7e9b9a1

Browse files
fix: lyricsline event not beign sent
Plus, all the payloads now match the lavalyrics payloads, making it compatible with clients.
1 parent fa1a9af commit 7e9b9a1

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/managers/lyricsManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export default class LyricsManager {
135135
if (lyricsSource && !skipTrackSource) {
136136
const lyrics = await lyricsSource.getLyrics(trackInfo, language)
137137
if (lyrics && lyrics.loadType !== 'empty') {
138+
lyrics.data.provider = sourceName
138139
return lyrics
139140
}
140141
}
@@ -148,6 +149,7 @@ export default class LyricsManager {
148149
)
149150
const lyrics = await source.getLyrics(trackInfo, language)
150151
if (lyrics && lyrics.loadType !== 'empty') {
152+
lyrics.data.provider = name
151153
return lyrics
152154
}
153155
}

src/playback/player.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ export class Player {
599599
}
600600

601601
this._lastPosition = position
602+
this._syncLyrics()
602603

603604
this.session.socket.send(
604605
JSON.stringify({
@@ -878,7 +879,7 @@ export class Player {
878879

879880
async _seekUsingSource(position, endTime) {
880881
if (!this.track) return false
881-
882+
882883
logger(
883884
'debug',
884885
'Player',
@@ -892,7 +893,7 @@ export class Player {
892893
...this.track.info,
893894
audioTrackId: this.track.audioTrackId
894895
}
895-
896+
896897
const urlData = await this.nodelink.sources.getTrackUrl(trackInfo)
897898
this.streamInfo = { ...urlData, trackInfo: this.track.info }
898899

@@ -1444,15 +1445,28 @@ export class Player {
14441445

14451446
async _loadLyrics() {
14461447
if (!this.track) return
1447-
1448+
14481449
const lyricsData = await this.nodelink.lyrics.loadLyrics(
14491450
{ info: this.track.info },
14501451
undefined,
14511452
this.skipTrackSource
14521453
)
14531454

14541455
if (lyricsData && lyricsData.loadType === 'lyrics') {
1455-
this.currentLyrics = lyricsData.data
1456+
const payload = {
1457+
sourceName: this.track.info.sourceName,
1458+
provider: lyricsData.data.provider,
1459+
text: lyricsData.data.lines.map((l) => l.text).join('\n'),
1460+
lines: lyricsData.data.lines.map((line) => ({
1461+
timestamp: line.time,
1462+
duration: line.duration,
1463+
line: line.text,
1464+
plugin: {}
1465+
})),
1466+
plugin: {}
1467+
}
1468+
1469+
this.currentLyrics = payload
14561470
this.lyricsLineIndex = -1
14571471
this.emitEvent('LyricsFoundEvent', { lyrics: this.currentLyrics })
14581472
this._recalculateLyricsIndex()
@@ -1471,7 +1485,7 @@ export class Player {
14711485

14721486
if (nextIndex >= lines.length) return
14731487

1474-
if (position >= lines[nextIndex].time) {
1488+
if (position >= lines[nextIndex].timestamp) {
14751489
this._recalculateLyricsIndex()
14761490
}
14771491
}
@@ -1485,7 +1499,7 @@ export class Player {
14851499
let foundIndex = -1
14861500
// Efficiently find the current line
14871501
for (let i = 0; i < lines.length; i++) {
1488-
if (lines[i].time <= position) {
1502+
if (lines[i].timestamp <= position) {
14891503
foundIndex = i
14901504
} else {
14911505
break
@@ -1500,12 +1514,7 @@ export class Player {
15001514
const line = lines[foundIndex]
15011515
this.emitEvent('LyricsLineEvent', {
15021516
lineIndex: foundIndex,
1503-
line: {
1504-
timestamp: line.time,
1505-
duration: line.duration,
1506-
line: line.text,
1507-
plugin: null
1508-
},
1517+
line: line,
15091518
skipped
15101519
})
15111520
}

0 commit comments

Comments
 (0)