mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-13 16:03:23 -05:00
[web] Fix for unexpected calls to the API #1688
Lyrics feature doesn't mess anymore when the user is playing tracks from Spotify
This commit is contained in:
parent
f19e9fb48b
commit
91c1e5b174
@ -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() {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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: (state) => state.lyrics.content,
|
||||
|
||||
lyrics_found: (state) => {
|
||||
return state.lyrics.found
|
||||
},
|
||||
|
||||
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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user