POC for playlist queueing

This commit is contained in:
James Barnsley
2019-03-18 16:26:16 +13:00
parent f824cca396
commit 5aa932d045
10 changed files with 5492 additions and 5372 deletions

View File

@ -1634,32 +1634,36 @@ export function getLibraryTracksAndPlayProcessor(data){
* Recursively get .next until we have all tracks
**/
export function getPlaylistTracksAndPlay(uri, shuffle){
export function getAllPlaylistTracks(uri, shuffle = false, callback_action = null, play_next = false, at_position = null, offset = 0){
return (dispatch, getState) => {
dispatch(uiActions.startProcess(
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
'SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR',
'Loading playlist tracks',
{
uri: uri,
next: 'playlists/'+ helpers.getFromUri('playlistid',uri) +'/tracks?market='+getState().spotify.country,
shuffle: shuffle
shuffle: shuffle,
play_next: play_next,
at_position: at_position,
offset: offset,
callback_action: callback_action
}
))
}
}
export function getPlaylistTracksAndPlayProcessor(data){
export function getAllPlaylistTracksProcessor(data){
return (dispatch, getState) => {
request(dispatch, getState, data.next)
.then(
response => {
// Check to see if we've been cancelled
if (getState().ui.processes['SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR'] !== undefined){
var processor = getState().ui.processes['SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR']
if (getState().ui.processes['SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR'] !== undefined){
var processor = getState().ui.processes['SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR']
if (processor.status == 'cancelling'){
dispatch(uiActions.processCancelled('SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR'))
dispatch(uiActions.processCancelled('SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR'))
return false
}
}
@ -1679,31 +1683,41 @@ export function getPlaylistTracksAndPlayProcessor(data){
// We got a next link, so we've got more work to be done
if (response.next){
dispatch(uiActions.updateProcess(
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
'SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR',
'Loading '+(response.total-uris.length)+' playlist tracks',
{
next: response.next,
total: response.total,
remaining: response.total - uris.length,
shuffle: data.shuffle
}
))
Object.assign(
{},
data,
{
next: response.next,
total: response.total,
remaining: response.total - uris.length
}
)
));
dispatch(uiActions.runProcess(
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
{
next: response.next,
uris: uris,
shuffle: data.shuffle
}
))
'SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR',
Object.assign(
{},
data,
{
next: response.next,
uris: uris,
}
)
));
} else {
if (data.shuffle){
uris = helpers.shuffle(uris);
}
dispatch(mopidyActions.playURIs(uris, data.uri))
dispatch(uiActions.processFinishing('SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR'))
if (data.callback_action == 'enqueue'){
dispatch(mopidyActions.enqueueURIs(uris, data.uri, data.play_next, data.at_position, data.offset));
} else {
dispatch(mopidyActions.playURIs(uris, data.uri));
}
dispatch(uiActions.processFinishing('SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR'))
}
},
error => {

View File

@ -305,14 +305,14 @@ const SpotifyMiddleware = (function(){
store.dispatch(spotifyActions.getLibraryAlbumsProcessor(action.data))
break
case 'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR':
store.dispatch(spotifyActions.getPlaylistTracksAndPlayProcessor(action.data))
break
case 'SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR':
store.dispatch(spotifyActions.getLibraryTracksAndPlayProcessor(action.data))
break
case 'SPOTIFY_GET_ALL_PLAYLIST_TRACKS_PROCESSOR':
store.dispatch(spotifyActions.getAllPlaylistTracksProcessor(action.data))
break
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
var albums = []
for (var i = 0; i < action.albums.length; i++){