mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 15:45:56 -05:00
[web] Move parsing of lyrics to the lyrics pane
This commit is contained in:
parent
35a730793f
commit
a9092e54c0
@ -311,7 +311,7 @@ export default {
|
|||||||
const track = this.$store.getters.now_playing
|
const track = this.$store.getters.now_playing
|
||||||
if (track && track.track_id) {
|
if (track && track.track_id) {
|
||||||
webapi.library_track(track.track_id).then(({ data }) => {
|
webapi.library_track(track.track_id).then(({ data }) => {
|
||||||
this.$store.commit(types.UPDATE_LYRICS, data)
|
this.$store.commit(types.UPDATE_LYRICS, data.lyrics)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.$store.commit(types.UPDATE_LYRICS)
|
this.$store.commit(types.UPDATE_LYRICS)
|
||||||
|
@ -74,24 +74,27 @@ export default {
|
|||||||
return this.lastIndex
|
return this.lastIndex
|
||||||
if (this.lastIndex < la.length - 2 && la[this.lastIndex + 2][1] > curTime)
|
if (this.lastIndex < la.length - 2 && la[this.lastIndex + 2][1] > curTime)
|
||||||
return this.lastIndex + 1
|
return this.lastIndex + 1
|
||||||
// Not found in the next 2 items, so start dichotomous search for the best time
|
// Not found in the next 2 items, so start searching for the best time
|
||||||
let start = 0,
|
return la.findLastIndex((verse) => verse[1] <= curTime)
|
||||||
end = la.length - 1,
|
|
||||||
index
|
|
||||||
while (start <= end) {
|
|
||||||
index = (start + end) >> 1
|
|
||||||
if (
|
|
||||||
la[index][1] <= curTime &&
|
|
||||||
(la[index + 1]?.[1] > curTime || !la[index + 1])
|
|
||||||
) {
|
|
||||||
return index
|
|
||||||
}
|
|
||||||
la[index][1] < curTime ? (start = index + 1) : (end = index - 1)
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
},
|
},
|
||||||
lyrics() {
|
lyrics() {
|
||||||
return this.$store.getters.lyrics
|
const lyrics = this.$store.getters.lyrics
|
||||||
|
const lyricsObj = []
|
||||||
|
if (lyrics) {
|
||||||
|
const regex = /(\[(\d+):(\d+)(?:\.\d+)?\] ?)?(.*)/
|
||||||
|
lyrics.split('\n').forEach((item) => {
|
||||||
|
const matches = regex.exec(item)
|
||||||
|
if (matches && matches[4]) {
|
||||||
|
const obj = [matches[4]]
|
||||||
|
if (matches[2] && matches[3])
|
||||||
|
obj.push(
|
||||||
|
matches[2] * 60 + matches[3] * 1
|
||||||
|
)
|
||||||
|
lyricsObj.push(obj)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return lyricsObj
|
||||||
},
|
},
|
||||||
player() {
|
player() {
|
||||||
return this.$store.state.player
|
return this.$store.state.player
|
||||||
|
@ -191,27 +191,8 @@ export default createStore({
|
|||||||
[types.UPDATE_QUEUE](state, queue) {
|
[types.UPDATE_QUEUE](state, queue) {
|
||||||
state.queue = queue
|
state.queue = queue
|
||||||
},
|
},
|
||||||
[types.UPDATE_LYRICS](state, track) {
|
[types.UPDATE_LYRICS](state, lyrics) {
|
||||||
// Parse from .LRC or text format to synchronized lyrics
|
state.lyrics.content = lyrics
|
||||||
function parse(lyrics) {
|
|
||||||
const lyricsObj = []
|
|
||||||
if (lyrics) {
|
|
||||||
const regex = /(\[(\d+):(\d+)(?:\.\d+)?\] ?)?(.*)/
|
|
||||||
lyrics.split('\n').forEach((item) => {
|
|
||||||
const matches = regex.exec(item)
|
|
||||||
if (matches !== null && matches[4].length) {
|
|
||||||
const obj = [matches[4]]
|
|
||||||
if (matches[2] != null && matches[3] != null)
|
|
||||||
obj.push(
|
|
||||||
parseInt(matches[2], 10) * 60 + parseInt(matches[3], 10)
|
|
||||||
)
|
|
||||||
lyricsObj.push(obj)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return lyricsObj
|
|
||||||
}
|
|
||||||
state.lyrics.content = track ? parse(track.lyrics) : ''
|
|
||||||
},
|
},
|
||||||
[types.UPDATE_LASTFM](state, lastfm) {
|
[types.UPDATE_LASTFM](state, lastfm) {
|
||||||
state.lastfm = lastfm
|
state.lastfm = lastfm
|
||||||
|
Loading…
Reference in New Issue
Block a user