Skip to content

Commit

Permalink
In album and genre views, sort albums by album artist AND album name
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Henning committed Jan 11, 2018
1 parent 2080d19 commit 76f7694
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/plugins/music_service/mpd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2998,14 +2998,18 @@ ControllerMpd.prototype.listAlbums = function (ui) {
}
}
}
// Sort albums by album artist, because the order produced by mpd is dependent on the
// filesystem from which the albums were read, i.e. if audio files are stored in the
// folders 'A' and 'B', then all albums in 'A' come before those in 'B'.
// Within 'A' and 'B' albums are typically sorted by album artist. Its partially
// Sort albums by album artist and album name, because the order produced by
// mpd is dependent on the filesystem from which the albums were read, i.e.
// if audio files are stored in the folders 'A' and 'B', then all albums
// in 'A' come before those in 'B'.
// Within a folder albums are typically sorted by album artist. Its partially
// sorted nature makes the albums array a good candidate for Timsort.
// https://en.wikipedia.org/wiki/Timsort
timSort.sort(response.navigation.lists[0].items, function (a, b) {
return a.artist.localeCompare(b.artist);
if (a.artist === b.artist)
return a.title.localeCompare(b.title);
else
return a.artist.localeCompare(b.artist);
});
//Save response in albumList cache for future use
memoryCache.set("cacheAlbumList", response);
Expand Down Expand Up @@ -3640,7 +3644,10 @@ ControllerMpd.prototype.listGenre = function (curUri) {
return a.title.localeCompare(b.title)
});
response.navigation.lists[1].items.sort(function (a,b) {
return a.artist.localeCompare(b.artist)
if (a.artist === b.artist)
return a.title.localeCompare(b.title);
else
return a.artist.localeCompare(b.artist);
});
response.navigation.lists[0].items.sort(function (a,b) {
return a.title.localeCompare(b.title)
Expand Down

0 comments on commit 76f7694

Please sign in to comment.