Searching artists/playlists/etc
This commit is contained in:
@ -50,7 +50,7 @@ export default class SearchSettingsModal extends React.Component{
|
||||
return (
|
||||
<div>
|
||||
<h4 className="no-bottom-padding">Advanced search settings</h4>
|
||||
<h3 className="grey-text bottom-padding">Customise the providers used when searching</h3>
|
||||
<h3 className="grey-text bottom-padding">Customise the providers used when searching. Only Spotify and local backends support searching by artist, album or playlist.</h3>
|
||||
|
||||
<form onSubmit={e => this.handleSubmit(e)}>
|
||||
<div className="field checkbox white">
|
||||
|
||||
@ -226,6 +226,13 @@ export function getSearchResults(query, uris = null, fields = ['any']){
|
||||
}
|
||||
}
|
||||
|
||||
export function getArtistSearchResults(query){
|
||||
return {
|
||||
type: 'MOPIDY_GET_ARTIST_SEARCH_RESULTS',
|
||||
query: query
|
||||
}
|
||||
}
|
||||
|
||||
export function getQueueHistory(){
|
||||
return {
|
||||
type: 'MOPIDY_INSTRUCT',
|
||||
|
||||
@ -306,15 +306,26 @@ const MopidyMiddleware = (function(){
|
||||
})
|
||||
break;
|
||||
|
||||
|
||||
/**
|
||||
* =============================================================== SEARCHING ============
|
||||
* ======================================================================================
|
||||
**/
|
||||
|
||||
|
||||
case 'MOPIDY_GET_SEARCH_RESULTS':
|
||||
var queryObject = {};
|
||||
for( var i = 0; i < action.fields.length; i++ ){
|
||||
queryObject[action.fields[i]] = [action.query];
|
||||
}
|
||||
|
||||
console.log({query: queryObject, uris: action.uris})
|
||||
|
||||
instruct( socket, store, 'library.search', {query: queryObject, uris: action.uris})
|
||||
.then( response => {
|
||||
|
||||
console.log(response)
|
||||
|
||||
// collate all our different sources into one array
|
||||
var tracks = []
|
||||
for( var i = 0; i < response.length; i++ ){
|
||||
@ -325,6 +336,38 @@ const MopidyMiddleware = (function(){
|
||||
})
|
||||
break;
|
||||
|
||||
case 'MOPIDY_GET_ARTIST_SEARCH_RESULTS':
|
||||
instruct( socket, store, 'library.search', {query: {artist: [action.query]}, uris: ['local:','file:','m3u:']})
|
||||
.then( response => {
|
||||
|
||||
// collate all our different sources into one array
|
||||
var artists_uris = []
|
||||
for (var i = 0; i < response.length; i++){
|
||||
if (response[i].tracks){
|
||||
for (var j = 0; j < response[i].tracks.length; j++){
|
||||
if (response[i].tracks[j].artists){
|
||||
for (var k = 0; k < response[i].tracks[j].artists.length; k++){
|
||||
var artist = response[i].tracks[j].artists[k]
|
||||
if (artist.uri){
|
||||
artists_uris.push(artist.uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
artists_uris = helpers.removeDuplicates(artists_uris)
|
||||
|
||||
// load each artist
|
||||
for (var i = 0; i < artists_uris.length; i++){
|
||||
store.dispatch(mopidyActions.getArtist(artists_uris[i]))
|
||||
}
|
||||
|
||||
// and plug in their URIs
|
||||
store.dispatch({ type: 'SEARCH_RESULTS_LOADED', artists_uris: artists_uris })
|
||||
})
|
||||
break;
|
||||
|
||||
|
||||
/**
|
||||
* =============================================================== PLAYLIST(S) ==========
|
||||
@ -715,10 +758,11 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
if (albums){
|
||||
store.dispatch({
|
||||
console.log(albums)
|
||||
/*store.dispatch({
|
||||
type: 'ALBUMS_LOADED',
|
||||
albums: albums
|
||||
})
|
||||
})*/
|
||||
}
|
||||
|
||||
var artist = Object.assign(
|
||||
@ -734,7 +778,7 @@ const MopidyMiddleware = (function(){
|
||||
type: 'ARTIST_LOADED',
|
||||
key: artist.uri,
|
||||
artist: artist
|
||||
});
|
||||
})
|
||||
|
||||
// load artwork from LastFM
|
||||
if( !artist.images || artist.images.length <= 0 ){
|
||||
|
||||
@ -129,7 +129,39 @@ const UIMiddleware = (function(){
|
||||
} else {
|
||||
var uri_schemes = state.mopidy.uri_schemes
|
||||
}
|
||||
store.dispatch(mopidyActions.getSearchResults(action.query, uri_schemes))
|
||||
|
||||
uri_schemes.sort()
|
||||
|
||||
// put local backends first as they'll always be fastest
|
||||
var local_backends = ['local:','m3u:','file:']
|
||||
for (var i = 0; i < local_backends.length; i++){
|
||||
var index = uri_schemes.indexOf(local_backends[i])
|
||||
if (index > -1){
|
||||
uri_schemes.splice(index,1)
|
||||
uri_schemes.unshift(local_backends[i])
|
||||
}
|
||||
}
|
||||
|
||||
switch (action.search_type){
|
||||
case 'playlists':
|
||||
store.dispatch(mopidyActions.getPlaylistSearchResults(action.query))
|
||||
break
|
||||
|
||||
case 'artists':
|
||||
store.dispatch(mopidyActions.getArtistSearchResults(action.query))
|
||||
break
|
||||
|
||||
case 'albums':
|
||||
store.dispatch(mopidyActions.getAlbumSearchResults(action.query))
|
||||
break
|
||||
|
||||
default:
|
||||
// wrap each uri scheme in it's own search request
|
||||
// this means slow backends won't hold up the whole request
|
||||
for (var i = 0; i < uri_schemes.length; i++){
|
||||
store.dispatch(mopidyActions.getSearchResults(action.query, [uri_schemes[i]], ['any']))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next(action)
|
||||
|
||||
@ -683,11 +683,11 @@ export default function reducer(ui = {}, action){
|
||||
return Object.assign({}, ui, {
|
||||
search_results: {
|
||||
artists_more: artists_more,
|
||||
artists_uris: artists_uris,
|
||||
artists_uris: helpers.removeDuplicates(artists_uris),
|
||||
albums_more: albums_more,
|
||||
albums_uris: albums_uris,
|
||||
albums_uris: helpers.removeDuplicates(albums_uris),
|
||||
playlists_more: playlists_more,
|
||||
playlists_uris: playlists_uris,
|
||||
playlists_uris: helpers.removeDuplicates(playlists_uris),
|
||||
tracks: tracks,
|
||||
tracks_more: tracks_more
|
||||
}
|
||||
|
||||
@ -265,9 +265,9 @@ class Artist extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
artist: (state.ui.artists && typeof(state.ui.artists[ownProps.params.uri]) !== 'undefined' ? state.ui.artists[ownProps.params.uri] : false ),
|
||||
artists: state.ui.artists,
|
||||
library_artists: state.ui.library_artists,
|
||||
albums: state.ui.albums,
|
||||
artists: (state.ui.artists ? state.ui.artists : []),
|
||||
library_artists: (state.ui.library_artists ? state.ui.library_artists : []),
|
||||
albums: (state.ui.albums ? state.ui.albums : []),
|
||||
spotify_authorized: state.spotify.authorized,
|
||||
mopidy_connected: state.mopidy.connected
|
||||
}
|
||||
|
||||
@ -221,13 +221,13 @@ const mapStateToProps = (state, ownProps) => {
|
||||
search_settings: (state.ui.search_settings ? state.ui.search_settings : null),
|
||||
tracks: (state.ui.search_results ? state.ui.search_results.tracks : []),
|
||||
tracks_more: (state.ui.search_results && state.ui.search_results.tracks_more ? state.ui.search_results.tracks_more : null),
|
||||
artists: state.ui.artists,
|
||||
artists: (state.ui.artists ? state.ui.artists : []),
|
||||
artists_uris: (state.ui.search_results ? state.ui.search_results.artists_uris : []),
|
||||
artists_more: (state.ui.search_results ? state.ui.search_results.artists_more : null),
|
||||
albums: state.ui.albums,
|
||||
albums: (state.ui.albums ? state.ui.albums : []),
|
||||
albums_uris: (state.ui.search_results ? state.ui.search_results.albums_uris : []),
|
||||
albums_more: (state.ui.search_results ? state.ui.search_results.albums_more : null),
|
||||
playlists: state.ui.playlists,
|
||||
playlists: (state.ui.playlists ? state.ui.playlists : []),
|
||||
playlists_uris: (state.ui.search_results ? state.ui.search_results.playlists_uris : []),
|
||||
playlists_more: (state.ui.search_results ? state.ui.search_results.playlists_more : null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user