Resolving track overwrite issue; Repairing queue images; Next is formatImages()

This commit is contained in:
James Barnsley
2018-09-08 21:16:18 +12:00
parent b7914e6c66
commit 1114b9031f
8 changed files with 10688 additions and 14008 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -98,7 +98,7 @@
// Release details // Release details
// These are automatically injected to built HTML // These are automatically injected to built HTML
var build = "1536275446"; var build = "1536363007";
var version = "3.25.1"; var version = "3.25.1";
// Construct the script tag // Construct the script tag

View File

@ -527,6 +527,9 @@ export let formatTrack = function(data){
'track_number', 'track_number',
'duration', 'duration',
'followers', 'followers',
'userloved',
'is_explicit',
'is_local',
'lyrics', 'lyrics',
'lyrics_path', 'lyrics_path',
'lyrics_results', 'lyrics_results',
@ -563,28 +566,32 @@ export let formatTrack = function(data){
track.followers = data.followers.total; track.followers = data.followers.total;
} }
if (!track.duration && data.duration_ms){ if (track.duration === undefined && data.duration_ms !== undefined){
track.duration = data.duration_ms; track.duration = data.duration_ms;
} else if (!track.duration && data.length){ } else if (track.duration === undefined && data.length !== undefined){
track.duration = data.length; track.duration = data.length;
} }
if (!track.track_number && data.track_no){ if (track.track_number === undefined && data.track_no !== undefined){
track.track_number = data.track_no; track.track_number = data.track_no;
} }
if (!track.disc_number && data.disc_no){ if (track.disc_number === undefined && data.disc_no !== undefined){
track.disc_number = data.disc_no; track.disc_number = data.disc_no;
} }
if (!track.release_date && data.date){ if (track.release_date === undefined && data.date !== undefined){
track.release_date = data.date; track.release_date = data.date;
} }
if (track.explicit === undefined && data.explicit !== undefined){
track.is_explicit = data.explicit;
}
// Copy images from albums (if applicable) // Copy images from albums (if applicable)
// TOOD: Identify if we stil need this... // TOOD: Identify if we stil need this...
if (data.album && data.album.images){ if (data.album && data.album.images){
if (!track.images || track.images.length > 0){ if (track.images === undefined){
track.images = data.album.images; track.images = data.album.images;
} }
} }

View File

@ -507,7 +507,7 @@ const CoreMiddleware = (function(){
var artists_loaded = []; var artists_loaded = [];
var albums_loaded = []; var albums_loaded = [];
action.tracks.forEach(raw_track => { for (var raw_track of action.tracks){
var track = helpers.formatTrack(raw_track); var track = helpers.formatTrack(raw_track);
if (tracks_index[track.uri] !== undefined){ if (tracks_index[track.uri] !== undefined){
@ -541,7 +541,7 @@ const CoreMiddleware = (function(){
} }
tracks_loaded.push(track); tracks_loaded.push(track);
}); };
if (artists_loaded.length > 0){ if (artists_loaded.length > 0){
store.dispatch(coreActions.artistsLoaded(artists_loaded)); store.dispatch(coreActions.artistsLoaded(artists_loaded));
@ -550,6 +550,8 @@ const CoreMiddleware = (function(){
store.dispatch(coreActions.albumsLoaded(albums_loaded)); store.dispatch(coreActions.albumsLoaded(albums_loaded));
} }
action.tracks = tracks_loaded;
next(action); next(action);
break; break;

View File

@ -26,7 +26,10 @@ var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) =
if (endpoint.startsWith('https://') || endpoint.startsWith('http://')){ if (endpoint.startsWith('https://') || endpoint.startsWith('http://')){
var url = endpoint; var url = endpoint;
} else { } else {
var url = 'https://api.genius.com/'+endpoint+'?access_token='+getState().genius.access_token; var url = 'https://api.genius.com/'+endpoint;
if (getState().genius.access_token){
url += '?access_token='+getState().genius.access_token;
}
} }
// create our ajax request config // create our ajax request config
@ -213,9 +216,9 @@ export function findTrackLyrics(track){
}); });
} }
dispatch(coreActions.trackLoaded({ dispatch(coreActions.trackLoaded({
uri: track.uri, uri: track.uri,
lyrics_results: lyrics_results lyrics_results: lyrics_results
})); }));
// Immediately go and get the first result's lyrics // Immediately go and get the first result's lyrics
var lyrics_result = lyrics_results[0]; var lyrics_result = lyrics_results[0];

View File

@ -1759,13 +1759,13 @@ const MopidyMiddleware = (function(){
var artists_uris = []; var artists_uris = [];
for (var artist in response[uri][0].artists){ for (var artist in response[uri][0].artists){
artists_loaded.push(helpers.formatArtist(artist)); artists_loaded.push(artist);
artists_uris.push(artist.uri); artists_uris.push(artist.uri);
} }
var tracks_uris = []; var tracks_uris = [];
for (var track in response[uri]){ for (var track in response[uri]){
tracks_loaded.push(helpers.formatTrack(track)); tracks_loaded.push(helpers.track);
tracks_uris.push(track.uri); tracks_uris.push(track.uri);
} }
@ -1811,7 +1811,7 @@ const MopidyMiddleware = (function(){
var artists = []; var artists = [];
for (var artist of response[0].artists){ for (var artist of response[0].artists){
artists.push(helpers.formatArtist(artist)); artists.push(artist);
} }
var album = Object.assign( var album = Object.assign(
@ -1819,7 +1819,7 @@ const MopidyMiddleware = (function(){
{ {
images: [] images: []
}, },
helpers.formatAlbum(response[0].album), response[0].album,
{ {
source: 'local', source: 'local',
artists_uris: helpers.arrayOf('uri', artists), artists_uris: helpers.arrayOf('uri', artists),
@ -2073,8 +2073,8 @@ const MopidyMiddleware = (function(){
case 'MOPIDY_CURRENT_TRACK_LOADED': case 'MOPIDY_CURRENT_TRACK_LOADED':
var track = helpers.formatTrack(action.tl_track); var track = helpers.formatTrack(action.tl_track);
// We don't have the track already in our index // We don't have the track already in our index, or we do but it's a partial record
if (!store.getState().core.tracks[track.uri]){ if (store.getState().core.tracks[track.uri] === undefined || store.getState().core.tracks[track.uri].images === undefined){
// We've got Spotify running, and it's a spotify track - go straight to the source! // We've got Spotify running, and it's a spotify track - go straight to the source!
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify'){ if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify'){

View File

@ -33,7 +33,7 @@ class Track extends React.Component{
} }
componentDidMount(){ componentDidMount(){
this.loadTrack(); this.props.coreActions.loadTrack(this.props.params.uri);
} }
handleContextMenu(e){ handleContextMenu(e){
@ -46,12 +46,12 @@ class Track extends React.Component{
// if our URI has changed, fetch new track // if our URI has changed, fetch new track
if (nextProps.params.uri != this.props.params.uri){ if (nextProps.params.uri != this.props.params.uri){
this.loadTrack(nextProps) this.props.coreActions.loadTrack(nextProps.params.uri);
// if mopidy has just connected AND we're not a Spotify track, go get // if mopidy has just connected AND we're not a Spotify track, go get
} else if (!this.props.mopidy_connected && nextProps.mopidy_connected){ } else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
if (helpers.uriSource(this.props.params.uri) != 'spotify'){ if (helpers.uriSource(this.props.params.uri) != 'spotify'){
this.loadTrack(nextProps); this.props.coreActions.loadTrack(nextProps.params.uri);
} }
} }
@ -101,48 +101,6 @@ class Track extends React.Component{
this.props.uiActions.showContextMenu(data) this.props.uiActions.showContextMenu(data)
} }
/**
* TODO: Identify why images being loaded breaks the thumbnail. Is there a new image array format
* we need to accommodate?
**/
loadTrack(props = this.props){
switch (helpers.uriSource(props.params.uri)){
case 'spotify':
if (props.track){
console.info('Loading track from index');
} else {
this.props.spotifyActions.getTrack(props.params.uri);
this.props.spotifyActions.following(props.params.uri);
}
break;
default:
if (props.mopidy_connected){
if (props.track){
console.info('Loading track from index');
} else {
this.props.mopidyActions.getTrack(props.params.uri );
}
}
break;
}
// We have artist info already
if (props.track && props.track.artists){
// Get the LastFM version of this track (provided we have artist info)
if (props.lastfm_authorized){
this.props.lastfmActions.getTrack(props.track.uri);
}
// Ready for lyrics
if (props.track && !props.track.lyrics_results){
this.props.geniusActions.findTrackLyrics(props.track);
}
}
}
play(){ play(){
this.props.mopidyActions.playURIs([this.props.params.uri], this.props.params.uri) this.props.mopidyActions.playURIs([this.props.params.uri], this.props.params.uri)
} }
@ -226,7 +184,7 @@ class Track extends React.Component{
if (!this.props.track){ if (!this.props.track){
return null return null
} else { } else {
var track = this.props.track var track = this.props.track;
} }
return ( return (
@ -268,7 +226,7 @@ class Track extends React.Component{
<div className="actions"> <div className="actions">
<button className="primary" onClick={e => this.play()}>Play</button> <button className="primary" onClick={e => this.play()}>Play</button>
<LastfmLoveButton uri={this.props.params.uri} artist={this.props.track.artists[0].name} track={this.props.track.name} addText="Love" removeText="Unlove" is_loved={this.props.track.userloved} /> <LastfmLoveButton uri={this.props.params.uri} artist={(this.props.track.artists ? this.props.track.artists[0].name : null)} track={this.props.track.name} addText="Love" removeText="Unlove" is_loved={this.props.track.userloved} />
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} /> <ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
</div> </div>