diff --git a/src/components/upnext.vue b/src/components/upnext.vue index 7bf408ea..651d260d 100644 --- a/src/components/upnext.vue +++ b/src/components/upnext.vue @@ -26,6 +26,7 @@ timeline.type === 'video'); + // Clients seem to respond with strings instead of numbers so need to parse return { ...videoTimeline, time: parseInt(videoTimeline.time, 10), duration: parseInt(videoTimeline.duration, 10), receivedAt: Date.now(), + playQueueItemID: parseInt(videoTimeline.playQueueItemID, 10), commandID: parseInt(data.MediaContainer[0].commandID, 10), }; }, @@ -141,26 +138,24 @@ export default { }, timeline) => { if (!getters.GET_PLEX_CLIENT_TIMELINE || getters.GET_PLEX_CLIENT_TIMELINE.machineIdentifier !== timeline.machineIdentifier - || getters.GET_PLEX_CLIENT_TIMELINE.ratingKey !== timeline.ratingKey) { + || !getters.GET_ACTIVE_PLAY_QUEUE_SELECTED_ITEM + || getters.GET_ACTIVE_PLAY_QUEUE_SELECTED_ITEM.playQueueItemID !== timeline.playQueueItemID) { if (timeline.state === 'stopped') { commit('SET_ACTIVE_MEDIA_METADATA', null); commit('SET_ACTIVE_SERVER_ID', null); + // Leaving play queue around for possible upnext } else { - // If client has changed what it's playing - // TODO: see what client sends when its stopped and set metadata and stuff to null instead if so - const metadata = await dispatch('plexservers/FETCH_PLEX_METADATA', { - machineIdentifier: timeline.machineIdentifier, - ratingKey: timeline.ratingKey, - }, { root: true }); + commit('SET_ACTIVE_PLAY_QUEUE_MACHINE_IDENTIFIER', timeline.machineIdentifier); + commit('SET_ACTIVE_PLAY_QUEUE', await dispatch('plexservers/FETCH_PLAY_QUEUE', { + machineIdentifier: getters.GET_ACTIVE_PLAY_QUEUE_MACHINE_IDENTIFIER, + playQueueID: timeline.playQueueID, + }, { root: true })); - commit('SET_ACTIVE_MEDIA_METADATA', metadata); + await dispatch('UPDATE_STATE_FROM_ACTIVE_PLAY_QUEUE_SELECTED_ITEM'); - commit('SET_ACTIVE_SERVER_ID', timeline.machineIdentifier); - commit('plexservers/SET_LAST_SERVER_ID', timeline.machineIdentifier, { root: true }); - - const serverName = rootGetters['plexservers/GET_PLEX_SERVER'](timeline.machineIdentifier).name; - dispatch('DISPLAY_NOTIFICATION', - `Now Playing: ${contentTitleUtils.getCombinedTitle(metadata)} from ${serverName}`, + const serverName = rootGetters['plexservers/GET_PLEX_SERVER'](getters.GET_ACTIVE_SERVER_ID).name; + await dispatch('DISPLAY_NOTIFICATION', + `Now Playing: ${contentTitleUtils.getCombinedTitle(getters.GET_ACTIVE_MEDIA_METADATA)} from ${serverName}`, { root: true }); } } @@ -229,18 +224,12 @@ export default { && getters.GET_ACTIVE_MEDIA_METADATA.type === 'episode' ) { if (!rootGetters.GET_UP_NEXT_TRIGGERED) { - const item = await dispatch('plexservers/FETCH_POST_PLAY', { - machineIdentifier: getters.GET_ACTIVE_SERVER_ID, - ratingKey: getters.GET_ACTIVE_MEDIA_METADATA.ratingKey, - }, { root: true }); - - if (item.grandparentRatingKey - === getters.GET_ACTIVE_MEDIA_METADATA.grandparentRatingKey) { - const metadata = await dispatch('plexservers/FETCH_PLEX_METADATA', { - machineIdentifier: getters.GET_ACTIVE_SERVER_ID, - ratingKey: item.ratingKey, - }, { root: true }); - commit('SET_UP_NEXT_POST_PLAY_DATA', metadata, { root: true }); + if (getters.ACTIVE_PLAY_QUEUE_NEXT_ITEM_EXISTS) { + commit('SET_UP_NEXT_POST_PLAY_DATA', + await dispatch('FETCH_METADATA_OF_PLAY_QUEUE_ITEM', + getters.GET_ACTIVE_PLAY_QUEUE + .Metadata[getters.GET_ACTIVE_PLAY_QUEUE.playQueueSelectedItemOffset + 1]), + { root: true }); } commit('SET_UP_NEXT_TRIGGERED', true, { root: true }); @@ -327,7 +316,6 @@ export default { }, PRESS_PLAY: async ({ getters, dispatch }) => { - console.log('Press play'); switch (getters.GET_CHOSEN_CLIENT_ID) { case 'PTPLAYER9PLUS10': { return dispatch('slplayer/PRESS_PLAY', null, { root: true }); @@ -346,7 +334,6 @@ export default { }, PRESS_PAUSE: ({ getters, dispatch }) => { - console.log('Press play'); switch (getters.GET_CHOSEN_CLIENT_ID) { case 'PTPLAYER9PLUS10': { return dispatch('slplayer/PRESS_PAUSE', null, { root: true }); @@ -364,7 +351,6 @@ export default { }, PRESS_STOP: async ({ getters, dispatch }) => { - console.log('Press stop'); switch (getters.GET_CHOSEN_CLIENT_ID) { case 'PTPLAYER9PLUS10': { return dispatch('slplayer/PRESS_STOP', null, { root: true }); @@ -453,4 +439,51 @@ export default { playQueueID: getters.GET_ACTIVE_PLAY_QUEUE.playQueueID, }, { root: true })); }, + + UPDATE_STATE_FROM_ACTIVE_PLAY_QUEUE_SELECTED_ITEM: async ({ getters, dispatch, commit }) => { + const metadata = await dispatch('FETCH_METADATA_OF_PLAY_QUEUE_ITEM', getters.GET_ACTIVE_PLAY_QUEUE_SELECTED_ITEM); + if (!getters.GET_ACTIVE_MEDIA_METADATA + || (metadata.ratingKey !== getters.GET_ACTIVE_MEDIA_METADATA.ratingKey + && getters.GET_ACTIVE_SERVER_ID !== metadata.machineIdentifier)) { + commit('SET_ACTIVE_SERVER_ID', metadata.machineIdentifier); + commit('plexservers/SET_LAST_SERVER_ID', metadata.machineIdentifier, { root: true }); + commit('SET_ACTIVE_MEDIA_METADATA', metadata); + } + }, + + FETCH_METADATA_OF_PLAY_QUEUE_ITEM: ({ getters, dispatch }, playQueueItem) => { + if (playQueueItem.source) { + // If source is defined on selected item, then it is on a different server and we need to do more stuff. + // Source looks likes: "server://{MACHINE_IDENTIFIER}/com.plexapp.plugins.library" + const regex = /^server:\/\/(\w+)\//; + const machineIdentifier = playQueueItem.source.match(regex)[1]; + + return dispatch('plexservers/FETCH_PLEX_METADATA', { + machineIdentifier, + ratingKey: playQueueItem.ratingKey, + }, { root: true }); + } + + return { + machineIdentifier: getters.GET_ACTIVE_PLAY_QUEUE_MACHINE_IDENTIFIER, + ...playQueueItem, + }; + }, + + PLAY_NEXT: ({ getters, dispatch }) => { + switch (getters.GET_CHOSEN_CLIENT_ID) { + case 'PTPLAYER9PLUS10': { + return dispatch('slplayer/PLAY_NEXT'); + } + + default: { + return dispatch('SEND_CLIENT_REQUEST', { + path: '/player/playback/skipNext', + params: { + wait: 0, + }, + }); + } + } + }, }; diff --git a/src/store/modules/plexservers/actions.js b/src/store/modules/plexservers/actions.js index f3b28340..98477cca 100644 --- a/src/store/modules/plexservers/actions.js +++ b/src/store/modules/plexservers/actions.js @@ -211,16 +211,6 @@ export default { })); }, - FETCH_POST_PLAY: async ({ getters }, { machineIdentifier, ratingKey }) => { - const { data } = await getters.GET_PLEX_SERVER_AXIOS(machineIdentifier) - .get(`/hubs/metadata/${ratingKey}/postplay`); - - return { - ...data.MediaContainer.Hub[0].Metadata[0], - machineIdentifier, - }; - }, - CREATE_PLAY_QUEUE: async ({ getters }, { machineIdentifier, ratingKey }) => { const { data } = await getters.GET_PLEX_SERVER_AXIOS(machineIdentifier).post('/playQueues', null, { params: { diff --git a/src/store/modules/slplayer/actions.js b/src/store/modules/slplayer/actions.js index b8a90fa7..7c2878c1 100644 --- a/src/store/modules/slplayer/actions.js +++ b/src/store/modules/slplayer/actions.js @@ -303,6 +303,7 @@ export default { commit('plexclients/SET_ACTIVE_MEDIA_METADATA', null, { root: true }); commit('plexclients/SET_ACTIVE_SERVER_ID', null, { root: true }); + // Leaving play queue around for possible upnext await getters.GET_PLAYER_UI.destroy(); commit('SET_OFFSET_MS', 0); commit('SET_PLAYER', null); @@ -348,33 +349,7 @@ export default { }, PLAY_ACTIVE_PLAY_QUEUE_SELECTED_ITEM: async ({ dispatch, commit, rootGetters }) => { - if (rootGetters['plexclients/GET_ACTIVE_PLAY_QUEUE_SELECTED_ITEM'].source) { - // TODO: Fix this when switching back and remember the last machine id ugh alskdfjd - // If source is defined on selected item, then it is on a different server and we need to do more stuff. - // Source looks likes: "server://{MACHINE_IDENTIFIER}/com.plexapp.plugins.library" - const regex = /^server:\/\/(\w+)\//; - const machineIdentifier = rootGetters['plexclients/GET_ACTIVE_PLAY_QUEUE_SELECTED_ITEM'].source.match(regex)[1]; - commit('plexclients/SET_ACTIVE_SERVER_ID', machineIdentifier, { root: true }); - commit('plexservers/SET_LAST_SERVER_ID', machineIdentifier, { root: true }); - - const metadata = await dispatch('plexservers/FETCH_PLEX_METADATA', { - machineIdentifier, - ratingKey: rootGetters['plexclients/GET_ACTIVE_PLAY_QUEUE_SELECTED_ITEM'].ratingKey, - }, { root: true }); - - commit('plexclients/SET_ACTIVE_MEDIA_METADATA', metadata, { root: true }); - } else { - if (rootGetters['plexclients/GET_ACTIVE_SERVER_ID'] !== rootGetters['plexclients/GET_ACTIVE_PLAY_QUEUE_MACHINE_IDENTIFIER']) { - console.log('nomatch'); - commit('plexclients/SET_ACTIVE_SERVER_ID', rootGetters['plexclients/GET_ACTIVE_PLAY_QUEUE_MACHINE_IDENTIFIER'], { root: true }); - commit('plexservers/SET_LAST_SERVER_ID', rootGetters['plexclients/GET_ACTIVE_PLAY_QUEUE_MACHINE_IDENTIFIER'], { root: true }); - } - - commit('plexclients/SET_ACTIVE_MEDIA_METADATA', { - machineIdentifier: rootGetters['plexclients/GET_ACTIVE_SERVER_ID'], - ...rootGetters['plexclients/GET_ACTIVE_PLAY_QUEUE_SELECTED_ITEM'], - }, { root: true }); - } + await dispatch('plexclients/UPDATE_STATE_FROM_ACTIVE_PLAY_QUEUE_SELECTED_ITEM', null, { root: true }); // Assume same server machineIdentifier, but this may not always be okay to do. (TODO: figure it out) @@ -384,7 +359,6 @@ export default { await dispatch('CHANGE_PLAYER_SRC'); - // UPDATE play queue GET REQUEST await dispatch('plexclients/UPDATE_ACTIVE_PLAY_QUEUE', null, { root: true }); }, };