Skip to content

Commit

Permalink
Improved handling of orphaned tracks (#1460)
Browse files Browse the repository at this point in the history
* Ensures dummy-albums in the Genres view are represented using the same icon as in the Artists view.

* Ensures that clicking on a dummy-album will list the orphaned tracks (tracks without an album) for which they were created.

Fixes:		volumio/Volumio2/#1458
Maybe Fixes:   volumio/Volumio2/#1441

* Removes dummy-albums (for tracks without an album) from the Genres and Artists views.

Collates dummy-albums in the Albums views, i.e. where Volumio might previously have created hundreds or thousands of dummy-albums for orphaned tracks (one dummy-album per artist) now only one is created (shared by all artists).

Fixes: 		volumio/Volumio2/#1453
  • Loading branch information
andreas-henning authored and volumio committed Jan 29, 2018
1 parent 9c3f3c2 commit 5d40d4b
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions app/plugins/music_service/mpd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,7 @@ ControllerMpd.prototype.searchFor = function (lines, startFrom, beginning) {

i++;
}
return '';
};

ControllerMpd.prototype.updateQueue = function () {
Expand Down Expand Up @@ -2978,26 +2979,32 @@ ControllerMpd.prototype.listAlbums = function (ui) {
if (!artistName) {
artistName = self.searchFor (lines, i + 1, 'Artist:');
}
//********Check if album and artist combination is already found and exists in 'albumsfound' array (Allows for duplicate album names)
if (albumsfound.indexOf(albumName + artistName) <0 ) { // Album/Artist is not in 'albumsfound' array
albumsfound.push(albumName + artistName);
var codedArtistName = encodeURIComponent(artistName);
var codedAlbumName = encodeURIComponent(albumName);
// This causes all orphaned tracks (tracks without an album) in the Albums view to be
// grouped into a single dummy-album, rather than creating one such dummy-album per artist.
var albumId = albumName + artistName;
if (!albumName) {
albumId = '';
albumName = '';
artistName = '*';
}
// Check if album and artist combination is already found and exists in 'albumsfound' array (Allows for duplicate album names)
if (albumsfound.indexOf(albumId) <0 ) { // Album/Artist is not in 'albumsfound' array
albumsfound.push(albumId);
var album = {
service:'mpd',
type: 'folder',
title: albumName,
artist: artistName,
album:'',
uri: 'albums://' + encodeURIComponent(artistName) + '/'+ encodeURIComponent(albumName),
//Get correct album art from path- only download if not existent
// Get correct album art from path- only download if not existent
albumart: self.getAlbumArt({artist: artistName, album: albumName}, self.getParentFolder('/mnt/' + path),'dot-circle-o')
};
response.navigation.lists[0].items.push(album);
}
}
}
//Save response in albumList cache for future use
// Save response in albumList cache for future use
memoryCache.set("cacheAlbumList", response);
if(ui) {
defer.resolve(response);
Expand Down Expand Up @@ -3039,7 +3046,11 @@ ControllerMpd.prototype.listAlbumSongs = function (uri,index,previous) {
else if (splitted[0] == 'albums:') { //album
var artist = decodeURIComponent(splitted[2]);
var albumName = decodeURIComponent(splitted[3]);
var findstring = "find album \"" + albumName + "\"" + " albumartist \"" + artist + "\" ";

var isOrphanAlbum = (uri === "albums://*/");
var artistSubQuery = isOrphanAlbum ? "" : " albumartist \"" + artist + "\" ";

var findstring = "find album \"" + albumName + "\"" + artistSubQuery;
}
else { //artist
var artist = decodeURIComponent(splitted[2]);
Expand Down Expand Up @@ -3127,12 +3138,7 @@ ControllerMpd.prototype.listAlbumSongs = function (uri,index,previous) {
duration: time,
trackType: path.split('.').pop()
});


}



}
if (duration != undefined && duration > 0) {
var durationminutes = Math.floor(duration/60);
Expand All @@ -3142,14 +3148,15 @@ ControllerMpd.prototype.listAlbumSongs = function (uri,index,previous) {
}
duration = durationminutes + ':' + durationseconds;
}
var isOrphanAlbum = (uri === "albums://*/");
duration =
response.navigation.info = {
uri: uri,
service: 'mpd',
artist: artist,
artist: isOrphanAlbum ? '*' : artist,
album: album,
albumart: albumart,
year: year,
year: isOrphanAlbum ? '' : year,
type: 'album',
duration: duration
};
Expand Down Expand Up @@ -3386,7 +3393,10 @@ ControllerMpd.prototype.parseListAlbum= function(err,msg,defer,response,uriBegin
uri: 'music-library/'+path
});

if(albums.indexOf(album)===-1) {
// The first expression in the following "if" statement prevents dummy-albums from being
// created for orphaned tracks (tracks without an album). Such dummy-albums aren't required,
// as orphaned tracks remain accessible from the tracks-list.
if(album !== '' && albums.indexOf(album)===-1) {
albums.push(album);
albumarts.push();

Expand Down Expand Up @@ -3567,7 +3577,7 @@ ControllerMpd.prototype.listGenre = function (curUri) {
var track = self.searchFor(lines, i + 1, 'Track:');
var title = track + " - " + title1;
}
var albumart = self.getAlbumArt({artist: albumartist, album: album}, self.getParentFolder(path),'fa-tags');;
var albumart = self.getAlbumArt({artist: albumartist, album: album}, self.getParentFolder(path),'dot-circle-o');;

if (title) {
title = title;
Expand Down

0 comments on commit 5d40d4b

Please sign in to comment.