Loading images via LastFM when all else fails
This commit is contained in:
@ -254,31 +254,87 @@ export function getArtist(uri, artist, mbid = false){
|
||||
|
||||
export function getAlbum(artist, album, mbid = false){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch({ type: 'LASTFM_ALBUM_LOADED', data: false });
|
||||
|
||||
if (mbid){
|
||||
var params = 'method=album.getInfo&mbid='+mbid
|
||||
var params = 'method=album.getInfo&mbid='+mbid;
|
||||
} else {
|
||||
artist = encodeURIComponent(artist )
|
||||
album = encodeURIComponent(album )
|
||||
var params = 'method=album.getInfo&album='+album+'&artist='+artist
|
||||
artist = encodeURIComponent(artist);
|
||||
album = encodeURIComponent(album);
|
||||
var params = 'method=album.getInfo&album='+album+'&artist='+artist;
|
||||
}
|
||||
sendRequest(dispatch, getState, params)
|
||||
.then(
|
||||
response => {
|
||||
if (response.album){
|
||||
dispatch({
|
||||
type: 'LASTFM_ALBUM_LOADED',
|
||||
data: response.album
|
||||
});
|
||||
dispatch(coreActions.albumsLoaded([response.album]));
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function getImages(context, uri){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
var record = getState().core[context][uri];
|
||||
if (record){
|
||||
switch (context){
|
||||
|
||||
case "tracks":
|
||||
|
||||
if (record.mbid){
|
||||
var params = 'method=album.getInfo&mbid='+record.mbid;
|
||||
} else if (record.artists && record.artists.length > 0 && record.album){
|
||||
var artist = encodeURIComponent(record.artists[0].name);
|
||||
var album = encodeURIComponent(record.album.name);
|
||||
var params = 'method=album.getInfo&album='+album+'&artist='+artist;
|
||||
}
|
||||
|
||||
if (params){
|
||||
sendRequest(dispatch, getState, params)
|
||||
.then(
|
||||
response => {
|
||||
if (response.album){
|
||||
record = Object.assign({}, record, {images: response.album.image});
|
||||
dispatch(coreActions.tracksLoaded([record]));
|
||||
dispatch(coreActions.albumsLoaded([response.album]));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case "albums":
|
||||
|
||||
if (record.mbid){
|
||||
var params = 'method=album.getInfo&mbid='+record.mbid;
|
||||
} else if (record.artists && record.artists.length > 0){
|
||||
var artist = encodeURIComponent(record.artists[0].name);
|
||||
var album = encodeURIComponent(record.name);
|
||||
var params = 'method=album.getInfo&album='+album+'&artist='+artist;
|
||||
}
|
||||
|
||||
if (params){
|
||||
sendRequest(dispatch, getState, params)
|
||||
.then(
|
||||
response => {
|
||||
if (response.album){
|
||||
record = Object.assign({}, record, {images: response.album.image});
|
||||
dispatch(coreActions.albumsLoaded([record]));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -1740,7 +1740,7 @@ const MopidyMiddleware = (function(){
|
||||
var track = helpers.formatTracks(action.data);
|
||||
|
||||
// We've got Spotify running, and it's a spotify track - go straight to the source!
|
||||
if (helpers.uriSource(track.uri) == 'spotify' && store.getState().spotify.enabled){
|
||||
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify'){
|
||||
store.dispatch(spotifyActions.getTrack(track.uri))
|
||||
|
||||
// Some other source, rely on Mopidy backends to do their work
|
||||
@ -1789,16 +1789,20 @@ const MopidyMiddleware = (function(){
|
||||
instruct(socket, store, 'library.getImages', {uris: action.uris})
|
||||
.then(response => {
|
||||
|
||||
var records = []
|
||||
var records = [];
|
||||
for (var uri in response){
|
||||
if (response.hasOwnProperty(uri)){
|
||||
var images = response[uri];
|
||||
images = helpers.digestMopidyImages(store.getState().mopidy, images);
|
||||
|
||||
if (images && images.length > 0){
|
||||
records.push({
|
||||
uri: uri,
|
||||
images: images
|
||||
});
|
||||
|
||||
} else {
|
||||
store.dispatch(lastfmActions.getImages(action.context, uri));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@
|
||||
&.name,
|
||||
&.artists,
|
||||
&.album {
|
||||
width: 25% !important;
|
||||
width: 25%;
|
||||
}
|
||||
&.added {
|
||||
width: 20%;
|
||||
|
||||
Reference in New Issue
Block a user