Buildout; Play all library tracks, fixes #250

This commit is contained in:
James Barnsley
2018-02-14 08:22:08 +13:00
parent 4721e2d3b9
commit 7611788ebd
11 changed files with 2239 additions and 1063 deletions

View File

@ -307,14 +307,14 @@ const MopidyMiddleware = (function(){
// make sure we didn't get this playlist from Mopidy-Spotify
// if we did, we'd have a cached version on server so no need to fetch
if (!store.getState().core.playlists[action.uri].is_mopidy){
store.dispatch(spotifyActions.getPlaylistTracksForPlaying(action.uri))
store.dispatch(spotifyActions.getPlaylistTracksAndPlay(action.uri))
break
}
// it's a spotify playlist that we haven't loaded
// we need to fetch via HTTP API to avoid timeout
} else if (helpers.uriSource(action.uri) == 'spotify' && store.getState().spotify.enabled){
store.dispatch(spotifyActions.getPlaylistTracksForPlaying(action.uri))
store.dispatch(spotifyActions.getPlaylistTracksAndPlay(action.uri))
break
// Not in index, and Spotify HTTP not enabled, so just play it as-is

View File

@ -1548,16 +1548,96 @@ export function getPlaylist(uri){
}
}
/**
* Get all library tracks
*
* Recursively get .next until we have all tracks
**/
export function getLibraryTracksAndPlay(uri){
return (dispatch, getState) => {
dispatch(uiActions.startProcess(
'SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR',
'Loading library tracks',
{
uri: uri,
next: 'me/tracks'
}
))
}
}
export function getLibraryTracksAndPlayProcessor(data){
return (dispatch, getState) => {
sendRequest(dispatch, getState, data.next)
.then(
response => {
// Check to see if we've been cancelled
if (getState().ui.processes['SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR'] !== undefined){
var processor = getState().ui.processes['SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR']
if (processor.status == 'cancelling'){
dispatch(uiActions.processCancelled('SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR'))
return false
}
}
// Add on our new batch of loaded tracks
var uris = [];
var new_uris = [];
for (var i = 0; i < response.items.length; i++){
new_uris.push(response.items[i].track.uri)
}
if (data.uris){
uris = [...data.uris, ...new_uris];
} else {
uris = new_uris;
}
// We got a next link, so we've got more work to be done
if (response.next){
dispatch(uiActions.updateProcess(
'SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR',
'Loading '+(response.total-uris.length)+' library tracks',
{
next: response.next,
total: response.total,
remaining: response.total - uris.length
}
))
dispatch(uiActions.runProcess(
'SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR',
{
next: response.next,
uris: uris
}
))
} else {
dispatch(mopidyActions.playURIs(uris, data.uri));
dispatch(uiActions.processFinished('SPOTIFY_GET_LIBRARY_TRACKS_AND_PLAY_PROCESSOR'))
}
},
error => {
dispatch(coreActions.handleException(
'Could not load library tracks',
error
));
}
);
}
}
/**
* Get all tracks for a playlist
*
* Recursively get .next until we have all tracks
**/
export function getPlaylistTracksForPlaying(uri){
export function getPlaylistTracksAndPlay(uri){
return (dispatch, getState) => {
dispatch(uiActions.startProcess(
'SPOTIFY_GET_PLAYLIST_TRACKS_FOR_PLAYING_PROCESSOR',
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
'Loading playlist tracks',
{
uri: uri,
@ -1567,18 +1647,18 @@ export function getPlaylistTracksForPlaying(uri){
}
}
export function getPlaylistTracksForPlayingProcessor(data){
export function getPlaylistTracksAndPlayProcessor(data){
return (dispatch, getState) => {
sendRequest(dispatch, getState, data.next)
.then(
response => {
// Check to see if we've been cancelled
if (getState().ui.processes['SPOTIFY_GET_PLAYLIST_TRACKS_FOR_PLAYING_PROCESSOR'] !== undefined){
var processor = getState().ui.processes['SPOTIFY_GET_PLAYLIST_TRACKS_FOR_PLAYING_PROCESSOR']
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 (processor.status == 'cancelling'){
dispatch(uiActions.processCancelled('SPOTIFY_GET_PLAYLIST_TRACKS_FOR_PLAYING_PROCESSOR'))
dispatch(uiActions.processCancelled('SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR'))
return false
}
}
@ -1598,7 +1678,7 @@ export function getPlaylistTracksForPlayingProcessor(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_FOR_PLAYING_PROCESSOR',
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
'Loading '+(response.total-uris.length)+' playlist tracks',
{
next: response.next,
@ -1607,7 +1687,7 @@ export function getPlaylistTracksForPlayingProcessor(data){
}
))
dispatch(uiActions.runProcess(
'SPOTIFY_GET_PLAYLIST_TRACKS_FOR_PLAYING_PROCESSOR',
'SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR',
{
next: response.next,
uris: uris
@ -1615,7 +1695,7 @@ export function getPlaylistTracksForPlayingProcessor(data){
))
} else {
dispatch(mopidyActions.playURIs(uris, data.uri))
dispatch(uiActions.processFinished('SPOTIFY_GET_PLAYLIST_TRACKS_FOR_PLAYING_PROCESSOR'))
dispatch(uiActions.processFinished('SPOTIFY_GET_PLAYLIST_TRACKS_AND_PLAY_PROCESSOR'))
}
},
error => {

View File

@ -264,8 +264,12 @@ const SpotifyMiddleware = (function(){
store.dispatch(spotifyActions.getLibraryAlbumsProcessor(action.data))
break
case 'SPOTIFY_GET_PLAYLIST_TRACKS_FOR_PLAYING_PROCESSOR':
store.dispatch(spotifyActions.getPlaylistTracksForPlayingProcessor(action.data))
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_LIBRARY_ALBUMS_LOADED':

View File

@ -3,6 +3,7 @@ import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import FontAwesome from 'react-fontawesome'
import TrackList from '../../components/TrackList'
import Header from '../../components/Header'
@ -35,6 +36,10 @@ class LibraryTracks extends React.Component{
);
}
playAll(){
this.props.spotifyActions.getLibraryTracksAndPlay();
}
render(){
if (helpers.isLoading(this.props.load_queue,['spotify_me/tracks'])){
return (
@ -57,9 +62,18 @@ class LibraryTracks extends React.Component{
}
}
var options = (
<span>
<button className="no-hover" onClick={e => this.playAll(e)}>
<FontAwesome name="play" />&nbsp;
Play all
</button>
</span>
);
return (
<div className="view library-tracks-view">
<Header icon="music" title="My tracks" />
<Header icon="music" title="My tracks" options={options} uiActions={this.props.uiActions} />
<section className="content-wrapper">
<TrackList tracks={tracks} />
<LazyLoadListener loading={this.props.library_tracks_more} loadMore={() => this.loadMore()}/>