diff --git a/web-src/src/App.vue b/web-src/src/App.vue index c8e4b507ef..c146d604f9 100644 --- a/web-src/src/App.vue +++ b/web-src/src/App.vue @@ -305,13 +305,14 @@ export default { }, update_lyrics() { - let track = this.$store.state.queue.items.filter( - (e) => e.id == this.$store.state.player.item_id - ) - if (track.length >= 1) - webapi.library_track(track[0].track_id).then(({ data }) => { + const track = this.$store.getters.now_playing + if (track && track.track_id) { + webapi.library_track(track.track_id).then(({ data }) => { this.$store.commit(types.UPDATE_LYRICS, data) }) + } else { + this.$store.commit(types.UPDATE_LYRICS) + } }, update_settings() { diff --git a/web-src/src/components/PlayerButtonLyrics.vue b/web-src/src/components/PlayerButtonLyrics.vue index 8147b10bd7..a40c69daae 100644 --- a/web-src/src/components/PlayerButtonLyrics.vue +++ b/web-src/src/components/PlayerButtonLyrics.vue @@ -36,8 +36,7 @@ export default { methods: { toggle_lyrics() { - this.$store.state.lyrics.lyrics_pane = - !this.$store.state.lyrics.lyrics_pane + this.$store.state.lyrics.pane = !this.$store.state.lyrics.pane } } } diff --git a/web-src/src/store/index.js b/web-src/src/store/index.js index ea8be15070..b0cadcdf62 100644 --- a/web-src/src/store/index.js +++ b/web-src/src/store/index.js @@ -34,10 +34,8 @@ export default createStore({ item_progress_ms: 0 }, lyrics: { - found: false, - lyrics_id: -1, - lyrics_pane: false, - lyrics: [] + pane: false, + content: [] }, queue: { version: 0, @@ -76,17 +74,9 @@ export default createStore({ }, getters: { - lyrics: (state) => { - return state.lyrics.lyrics - }, - - lyrics_found: (state) => { - return state.lyrics.found - }, + lyrics: (state) => state.lyrics.content, - lyrics_pane: (state) => { - return state.lyrics.lyrics_pane - }, + lyrics_pane: (state) => state.lyrics.pane, now_playing: (state) => { const item = state.queue.items.find(function (item) { @@ -206,27 +196,28 @@ export default createStore({ [types.UPDATE_QUEUE](state, queue) { state.queue = queue }, - [types.UPDATE_LYRICS](state, lyrics) { + [types.UPDATE_LYRICS](state, track) { // Parse from .LRC or text format to synchronized lyrics function parse(lyrics) { - let lyricsObj = [] - let tempArr = lyrics.split('\n') - const regex = /(\[(\d+):(\d+)(?:\.\d+)?\] ?)?(.*)/ - - tempArr.forEach((item) => { - let matches = regex.exec(item) - if (matches !== null && matches[4].length) { - let 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 + if (lyrics) { + const lyricsObj = [] + 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 + } + return {} } - state.lyrics.lyrics = 'lyrics' in lyrics ? parse(lyrics.lyrics) : '' - if (!state.lyrics.found) - state.lyrics.found = state.lyrics.lyrics.length > 0 + state.lyrics.content = track ? parse(track.lyrics) : '' }, [types.UPDATE_LASTFM](state, lastfm) { state.lastfm = lastfm diff --git a/web-src/src/webapi/index.js b/web-src/src/webapi/index.js index 62610c751f..4a2fda393f 100644 --- a/web-src/src/webapi/index.js +++ b/web-src/src/webapi/index.js @@ -424,9 +424,7 @@ export default { }, library_track(trackId) { - if (trackId) { // Temporary fix - return axios.get(`./api/library/tracks/${trackId}`) - } + return axios.get(`./api/library/tracks/${trackId}`) }, library_track_playlists(trackId) {