Google as new provider (using Mopidy core), starting #266

This commit is contained in:
James Barnsley
2018-10-16 21:21:36 +13:00
parent 5c9937077e
commit 0f4272d0df
11 changed files with 10787 additions and 13862 deletions

12
src/js/bootstrap.js vendored
View File

@ -10,6 +10,7 @@ import mopidy from './services/mopidy/reducer';
import lastfm from './services/lastfm/reducer';
import spotify from './services/spotify/reducer';
import snapcast from './services/snapcast/reducer';
import google from './services/google/reducer';
import genius from './services/genius/reducer';
import thunk from 'redux-thunk';
@ -20,6 +21,7 @@ import mopidyMiddleware from './services/mopidy/middleware';
import lastfmMiddleware from './services/lastfm/middleware';
import geniusMiddleware from './services/genius/middleware';
import spotifyMiddleware from './services/spotify/middleware';
import googleMiddleware from './services/google/middleware';
import snapcastMiddleware from './services/snapcast/middleware';
import localstorageMiddleware from './services/localstorage/middleware';
@ -59,8 +61,8 @@ var initialState = {
progress: 0,
play_state: null,
uri_schemes: [],
library_albums_uris: 'local:directory?type=album',
library_artists_uris: 'local:directory?type=artist'
library_albums_uri: 'local:directory?type=album',
library_artists_uri: 'local:directory?type=artist'
},
pusher: {
connected: false,
@ -84,6 +86,9 @@ var initialState = {
autocomplete_results: {},
authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_spotify.php'
},
google: {
enabled: false
},
snapcast: {
streams: {},
groups: {},
@ -101,6 +106,7 @@ initialState.pusher = Object.assign({}, initialState.pusher, helpers.getStorage(
initialState.spotify = Object.assign({}, initialState.spotify, helpers.getStorage('spotify'));
initialState.lastfm = Object.assign({}, initialState.lastfm, helpers.getStorage('lastfm'));
initialState.genius = Object.assign({}, initialState.genius, helpers.getStorage('genius'));
initialState.google = Object.assign({}, initialState.google, helpers.getStorage('google'));
initialState.snapcast = Object.assign({}, initialState.snapcast, helpers.getStorage('snapcast'));
console.log('Bootstrapping', initialState);
@ -113,6 +119,7 @@ var reducers = combineReducers({
lastfm,
genius,
spotify,
google,
snapcast
});
@ -129,6 +136,7 @@ export default createStore(
spotifyMiddleware,
lastfmMiddleware,
geniusMiddleware,
googleMiddleware,
snapcastMiddleware
)
);

View File

@ -0,0 +1,13 @@
export function set(data){
return {
type: 'GOOGLE_SET',
data: data
}
}
export function getLibraryArtists(){
return {
'type': 'GOOGLE_GET_LIBRARY_ARTISTS'
}
}

View File

@ -0,0 +1,38 @@
import ReactGA from 'react-ga'
var helpers = require('../../helpers');
var coreActions = require('../core/actions');
var mopidyActions = require('../mopidy/actions');
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) => {
store.dispatch(
pusherActions.request(
'snapcast_instruct',
params,
response_callback,
error_callback
)
);
return;
}
return store => next => action => {
var google = store.getState().google;
switch(action.type){
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);
}
}
})();
export default GoogleMiddleware

View File

@ -0,0 +1,14 @@
export default function reducer(google = {}, action){
switch (action.type){
case 'GOOGLE_SET':
return Object.assign({}, google, action.data);
default:
return google
}
}

View File

@ -357,9 +357,10 @@ export function getTrack(uri){
}
}
export function getLibraryArtists(){
export function getLibraryArtists(uri = null){
return {
type: 'MOPIDY_GET_LIBRARY_ARTISTS'
type: 'MOPIDY_GET_LIBRARY_ARTISTS',
uri: uri
}
}
@ -399,9 +400,10 @@ export function getAlbums(uris, processor = null){
}
}
export function getLibraryAlbums(){
export function getLibraryAlbums(uri = null){
return {
type: 'MOPIDY_GET_LIBRARY_ALBUMS'
type: 'MOPIDY_GET_LIBRARY_ALBUMS',
uri: uri
}
}

View File

@ -1,16 +1,17 @@
import ReactGA from 'react-ga'
import Mopidy from 'mopidy'
import ReactGA from 'react-ga';
import Mopidy from 'mopidy';
import md5 from 'md5';
import { hashHistory } from 'react-router'
import * as helpers from '../../helpers'
import { hashHistory } from 'react-router';
import * as helpers from '../../helpers';
var mopidyActions = require('./actions.js')
var coreActions = require('../core/actions.js')
var uiActions = require('../ui/actions.js')
var spotifyActions = require('../spotify/actions.js')
var pusherActions = require('../pusher/actions.js')
var lastfmActions = require('../lastfm/actions.js')
var mopidyActions = require('./actions.js');
var coreActions = require('../core/actions.js');
var uiActions = require('../ui/actions.js');
var spotifyActions = require('../spotify/actions.js');
var pusherActions = require('../pusher/actions.js');
var googleActions = require('../google/actions.js');
var lastfmActions = require('../lastfm/actions.js');
const MopidyMiddleware = (function(){
@ -530,21 +531,8 @@ const MopidyMiddleware = (function(){
}
// Enable Iris providers when the backend is available
if (uri_schemes.includes('spotify:')){
store.dispatch({
type: 'SPOTIFY_SET',
data: {
enabled: true
}
});
} else {
store.dispatch({
type: 'SPOTIFY_SET',
data: {
enabled: false
}
});
}
store.dispatch(spotifyActions.set({enabled: uri_schemes.includes('spotify:')}));
store.dispatch(googleActions.set({enabled: uri_schemes.includes('gmusic:')}));
// If we haven't customised our search schemes, add all to search
if (store.getState().ui.uri_schemes_search_enabled === undefined){
@ -1715,22 +1703,7 @@ const MopidyMiddleware = (function(){
var last_run = store.getState().ui.processes.MOPIDY_LIBRARY_ALBUMS_PROCESSOR
if (!last_run){
var uris = store.getState().mopidy.library_albums_uris.split(',');
var promises = [];
// Construct an array of promises
for (var uri of uris){
promises.push(
request(socket, store, 'library.browse', { uri: uri })
);
}
// Now run the requests
Promise.all(promises).then(responses => {
console.log(responses);
});
request(socket, store, 'library.browse', { uri: store.getState().mopidy.library_albums_uris })
request(socket, store, 'library.browse', { uri: store.getState().mopidy.library_albums_uri })
.then(response => {
if (response.length <= 0) return

View File

@ -28,8 +28,8 @@ class Settings extends React.Component {
this.state = {
mopidy_host: this.props.mopidy.host,
mopidy_port: this.props.mopidy.port,
mopidy_library_artists_uris: this.props.mopidy.library_artists_uris,
mopidy_library_albums_uris: this.props.mopidy.library_albums_uris,
mopidy_library_artists_uri: this.props.mopidy.library_artists_uri,
mopidy_library_albums_uri: this.props.mopidy.library_albums_uri,
pusher_username: this.props.pusher.username,
input_in_focus: null
}
@ -393,12 +393,12 @@ class Settings extends React.Component {
<div className="input">
<input
type="text"
value={this.state.mopidy_library_artists_uris}
value={this.state.mopidy_library_artists_uri}
onChange={e => this.setState({mopidy_library_artists_uri: e.target.value})}
onBlur={e => this.handleBlur('mopidy', 'library_artists_uri', e.target.value)}
/>
<div className="description">
URIs used for collecting library artists (comma-separated list)
URI used for collecting library artists
</div>
</div>
</div>
@ -408,12 +408,12 @@ class Settings extends React.Component {
<div className="input">
<input
type="text"
value={this.state.mopidy_library_albums_uris}
onChange={e => this.setState({mopidy_library_albums_uris: e.target.value})}
onBlur={e => this.handleBlur('mopidy', 'library_albums_uris', e.target.value)}
value={this.state.mopidy_library_albums_uri}
onChange={e => this.setState({mopidy_library_albums_uri: e.target.value})}
onBlur={e => this.handleBlur('mopidy', 'library_albums_uri', e.target.value)}
/>
<div className="description">
URIs used for collecting library albums (comma-separated list)
URI used for collecting library albums
</div>
</div>
</div>

View File

@ -1,21 +1,22 @@
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Link } from 'react-router';
import Header from '../../components/Header'
import ArtistGrid from '../../components/ArtistGrid'
import List from '../../components/List'
import DropdownField from '../../components/Fields/DropdownField'
import FilterField from '../../components/Fields/FilterField'
import LazyLoadListener from '../../components/LazyLoadListener'
import Icon from '../../components/Icon'
import Header from '../../components/Header';
import ArtistGrid from '../../components/ArtistGrid';
import List from '../../components/List';
import DropdownField from '../../components/Fields/DropdownField';
import FilterField from '../../components/Fields/FilterField';
import LazyLoadListener from '../../components/LazyLoadListener';
import Icon from '../../components/Icon';
import * as helpers from '../../helpers'
import * as uiActions from '../../services/ui/actions'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
import * as helpers from '../../helpers';
import * as uiActions from '../../services/ui/actions';
import * as mopidyActions from '../../services/mopidy/actions';
import * as spotifyActions from '../../services/spotify/actions';
import * as googleActions from '../../services/google/actions';
class LibraryArtists extends React.Component{
@ -36,6 +37,10 @@ class LibraryArtists extends React.Component{
this.props.mopidyActions.getLibraryArtists();
}
if (!this.props.gmusic_library_artists && this.props.mopidy_connected && (this.props.source == 'all' || this.props.source == 'google')){
this.props.googleActions.getLibraryArtists();
}
if (this.props.spotify_enabled && this.props.spotify_library_artists_status != 'finished' && (this.props.source == 'all' || this.props.source == 'spotify')){
this.props.spotifyActions.getLibraryArtists();
}
@ -55,6 +60,14 @@ class LibraryArtists extends React.Component{
}
}
if (newProps.google_enabled && (newProps.source == 'all' || newProps.source == 'google')){
// Filter changed, but we haven't got this provider's library yet
if (newProps.google_library_artists_status != 'finished' && newProps.google_library_artists_status != 'started'){
this.props.googleActions.getLibraryArtists();
}
}
if (newProps.spotify_enabled && (newProps.source == 'all' || newProps.source == 'spotify')){
// Filter changed, but we haven't got this provider's library yet
@ -201,6 +214,13 @@ class LibraryArtists extends React.Component{
});
}
if (this.props.google_enabled){
source_options.push({
value: 'google',
label: 'Google'
});
}
var view_options = [
{
label: 'Thumbnails',
@ -284,9 +304,12 @@ const mapStateToProps = (state, ownProps) => {
mopidy_uri_schemes: state.mopidy.uri_schemes,
mopidy_library_artists: state.mopidy.library_artists,
mopidy_library_artists_status: (state.ui.processes.MOPIDY_LIBRARY_ARTISTS_PROCESSOR !== undefined ? state.ui.processes.MOPIDY_LIBRARY_ARTISTS_PROCESSOR.status : null),
spotify_enabled: (state.mopidy.uri_schemes && state.mopidy.uri_schemes.includes('spotify:')),
spotify_enabled: state.spotify.enabled,
spotify_library_artists: state.spotify.library_artists,
spotify_library_artists_status: (state.ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR !== undefined ? state.ui.processes.SPOTIFY_GET_LIBRARY_ARTISTS_PROCESSOR.status : null),
google_enabled: state.google.enabled,
google_library_artists: state.google.library_artists,
google_library_artists_status: (state.ui.processes.GOOGLE_GET_LIBRARY_ARTISTS_PROCESSOR !== undefined ? state.ui.processes.GOOGLE_GET_LIBRARY_ARTISTS_PROCESSOR.status : null),
artists: state.core.artists,
source: (state.ui.library_artists_source ? state.ui.library_artists_source : 'all'),
sort: (state.ui.library_artists_sort ? state.ui.library_artists_sort : null),
@ -299,7 +322,8 @@ const mapDispatchToProps = (dispatch) => {
return {
uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
spotifyActions: bindActionCreators(spotifyActions, dispatch),
googleActions: bindActionCreators(googleActions, dispatch)
}
}