Fully-functional artists and albums for Google - no such luck for Playlists...
This commit is contained in:
@ -7,7 +7,25 @@ export function set(data){
|
||||
}
|
||||
|
||||
export function getLibraryArtists(){
|
||||
return {
|
||||
type: 'GOOGLE_GET_LIBRARY_ARTISTS'
|
||||
}
|
||||
}
|
||||
|
||||
export function clearLibraryArtists(){
|
||||
return {
|
||||
type: 'GOOGLE_CLEAR_LIBRARY_ARTISTS'
|
||||
}
|
||||
}
|
||||
|
||||
export function getLibraryAlbums(){
|
||||
return {
|
||||
'type': 'GOOGLE_GET_LIBRARY_ARTISTS'
|
||||
'type': 'GOOGLE_GET_LIBRARY_ALBUMS'
|
||||
}
|
||||
}
|
||||
|
||||
export function clearLibraryAlbums(){
|
||||
return {
|
||||
type: 'GOOGLE_CLEAR_LIBRARY_ALBUMS'
|
||||
}
|
||||
}
|
||||
@ -8,11 +8,11 @@ var uiActions = require('../ui/actions');
|
||||
|
||||
const GoogleMiddleware = (function(){
|
||||
|
||||
// A snapcast request is an alias of the Pusher request
|
||||
const request = (store, params = null, response_callback = null, error_callback = null) => {
|
||||
// A Google request is an alias of the Mopidy request
|
||||
const request = (store, method, params = null, response_callback = null, error_callback = null) => {
|
||||
store.dispatch(
|
||||
pusherActions.request(
|
||||
'snapcast_instruct',
|
||||
mopidyActions.request(
|
||||
method,
|
||||
params,
|
||||
response_callback,
|
||||
error_callback
|
||||
@ -25,6 +25,113 @@ const GoogleMiddleware = (function(){
|
||||
var google = store.getState().google;
|
||||
|
||||
switch(action.type){
|
||||
case 'GOOGLE_GET_LIBRARY_ALBUMS':
|
||||
var last_run = store.getState().ui.processes.GOOGLE_LIBRARY_ALBUMS_PROCESSOR
|
||||
|
||||
if (!last_run){
|
||||
request(
|
||||
store,
|
||||
'library.browse',
|
||||
{
|
||||
uri: 'gmusic:album'
|
||||
},
|
||||
response => {
|
||||
if (response.length <= 0){
|
||||
return;
|
||||
}
|
||||
|
||||
var uris = helpers.arrayOf('uri',response);
|
||||
store.dispatch({
|
||||
type: 'GOOGLE_LIBRARY_ALBUMS_LOADED',
|
||||
uris: uris
|
||||
});
|
||||
|
||||
// Start our process to load the full album objects
|
||||
store.dispatch(uiActions.startProcess(
|
||||
'GOOGLE_LIBRARY_ALBUMS_PROCESSOR',
|
||||
'Loading '+uris.length+' Google albums',
|
||||
{
|
||||
uris: uris,
|
||||
total: uris.length,
|
||||
remaining: uris.length
|
||||
}
|
||||
));
|
||||
}
|
||||
);
|
||||
|
||||
} else if (last_run.status == 'cancelled'){
|
||||
store.dispatch(uiActions.resumeProcess('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
} else if (last_run.status == 'finished'){
|
||||
// TODO: do we want to force a refresh?
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'GOOGLE_LIBRARY_ALBUMS_PROCESSOR':
|
||||
if (store.getState().ui.processes['GOOGLE_LIBRARY_ALBUMS_PROCESSOR'] !== undefined){
|
||||
var processor = store.getState().ui.processes['GOOGLE_LIBRARY_ALBUMS_PROCESSOR']
|
||||
|
||||
if (processor.status == 'cancelling'){
|
||||
store.dispatch(uiActions.processCancelled('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var uris = Object.assign([], action.data.uris);
|
||||
var uris_to_load = uris.splice(0,50);
|
||||
|
||||
if (uris_to_load.length > 0){
|
||||
store.dispatch(uiActions.updateProcess(
|
||||
'GOOGLE_LIBRARY_ALBUMS_PROCESSOR',
|
||||
'Loading '+uris.length+' Google albums',
|
||||
{
|
||||
uris: uris,
|
||||
remaining: uris.length
|
||||
}
|
||||
));
|
||||
store.dispatch(mopidyActions.getAlbums(uris_to_load, {name: 'GOOGLE_LIBRARY_ALBUMS_PROCESSOR', data: {uris: uris}}))
|
||||
} else {
|
||||
store.dispatch(uiActions.processFinishing('GOOGLE_LIBRARY_ALBUMS_PROCESSOR'));
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
case 'GOOGLE_GET_LIBRARY_ARTISTS':
|
||||
request(
|
||||
store,
|
||||
'library.browse',
|
||||
{
|
||||
uri: 'gmusic:artist'
|
||||
},
|
||||
response => {
|
||||
if (response.length <= 0){
|
||||
return
|
||||
}
|
||||
|
||||
var uris = [];
|
||||
for (var i = 0; i < response.length; i++){
|
||||
|
||||
// Convert local URI to actual artist URI
|
||||
// See https://github.com/mopidy/mopidy-local-sqlite/issues/39
|
||||
response[i].uri = response[i].uri.replace('local:directory?albumartist=','');
|
||||
uris.push(response[i].uri);
|
||||
}
|
||||
|
||||
store.dispatch(coreActions.artistsLoaded(response));
|
||||
|
||||
store.dispatch({
|
||||
type: 'GOOGLE_LIBRARY_ARTISTS_LOADED',
|
||||
uris: uris
|
||||
});
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not load Google artists',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
|
||||
@ -1,10 +1,34 @@
|
||||
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
export default function reducer(google = {}, action){
|
||||
switch (action.type){
|
||||
|
||||
case 'GOOGLE_SET':
|
||||
return Object.assign({}, google, action.data);
|
||||
|
||||
case 'GOOGLE_LIBRARY_ARTISTS_LOADED':
|
||||
if (google.library_artists){
|
||||
var uris = [...google.library_artists,...action.uris];
|
||||
} else {
|
||||
var uris = action.uris;
|
||||
}
|
||||
return Object.assign({}, google, { library_artists: helpers.removeDuplicates(uris) });
|
||||
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ARTISTS':
|
||||
return Object.assign({}, google, { library_artists: null });
|
||||
|
||||
case 'GOOGLE_LIBRARY_ALBUMS_LOADED':
|
||||
if (google.library_albums){
|
||||
var uris = [...google.library_albums,...action.uris];
|
||||
} else {
|
||||
var uris = action.uris;
|
||||
}
|
||||
return Object.assign({}, google, { library_albums: helpers.removeDuplicates(uris) });
|
||||
|
||||
case 'GOOGLE_CLEAR_LIBRARY_ALBUMS':
|
||||
return Object.assign({}, google, { library_albums: null });
|
||||
|
||||
default:
|
||||
return google
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ export function set(data){
|
||||
}
|
||||
}
|
||||
|
||||
export function request(method, params = null, response_callback = null, error_callback = null){
|
||||
export function request(method, params = {}, response_callback = null, error_callback = null){
|
||||
return {
|
||||
type: 'MOPIDY_REQUEST',
|
||||
method: method,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
import * as helpers from '../../helpers'
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
export default function reducer(mopidy = {}, action){
|
||||
switch (action.type){
|
||||
|
||||
Reference in New Issue
Block a user