Show albumartist from genre view if albumartist selected in settings

Hi,
I would show the albums sort by AlbumArtist not by Artist in Genre-View if Albumartist selected instead in settings.
I have change the index.js as sample to do this. I don’t know if it perfect, therfore I publish here my code changes, I think many peoples with big librarys search over genre and albumartist.

Changes are in function ControllerMpd.prototype.listGenres of index.js in /volumio/app/plugins/music_service/mpd
The used version of VOLUMIO is 2.861 for Raspberry
Maybe this idea will find its way into a future version :wink:

For a test replace only this function.

/**
 *
 * list genre
 */
ControllerMpd.prototype.listGenre = function (curUri) {
  var self = this;
  var defer = libQ.defer();
  var splitted = curUri.split('/');
  var genreName = decodeURIComponent(splitted[2]);
  var genreArtist = decodeURIComponent(splitted[3]);
  var safeGenreName = genreName.replace(/"/g, '\\"');
  var safeGenreArtist = genreArtist.replace(/"/g, '\\"');
  var response = {
    'navigation': {
      'lists': [
        {
          'title': genreName + ' ' + self.commandRouter.getI18nString('COMMON.ARTISTS') ,
          'icon': 'fa icon',
          'availableListViews': [
            'list',
            'grid'
          ],
          'items': []
        },
        {
          'title': genreName + ' ' + self.commandRouter.getI18nString('COMMON.ALBUMS'),
          'icon': 'fa icon',
          'availableListViews': [
            'list',
            'grid'
          ],
          'items': []
        }
      ],
      'prev': {
        'uri': 'genres://'
      }
    }
  };

  self.mpdReady
    .then(function () {
      var cmd = libMpd.cmd;
      if (genreArtist != 'undefined') {
        var findString = 'find genre "' + safeGenreName + '" albumartist "' + safeGenreArtist + '" ';
      } else {
        var findString = 'find genre "' + safeGenreName + '"';
      }
      self.clientMpd.sendCommand(cmd(findString, []), function (err, msg) {
        var albums = [];
        var albumsArt = [];
        var artists = [];
        var artistArt = [];
        var list = [];

        if (msg) {
          var path;
          var name;
          var lines = msg.split('\n');
          for (var i = 0; i < lines.length; i++) {
            var line = lines[i];
            if (line.indexOf('file:') === 0) {
              var path = line.slice(6);
              var name = path.split('/').pop();
              var artist = self.searchFor(lines, i + 1, 'Artist:');
              var albumartist = self.searchFor(lines, i + 1, 'AlbumArtist:');
              var album = self.searchFor(lines, i + 1, 'Album:');
              // Include track number if tracknumber variable is set to 'true'
              if (!tracknumbers) {
                var title = self.searchFor(lines, i + 1, 'Title:');
              } else {
                var title1 = self.searchFor(lines, i + 1, 'Title:');
                var track = self.searchFor(lines, i + 1, 'Track:');
                if (track && title1) {
                  var title = track + ' - ' + title1;
                } else {
                  var title = title1;
                }
              }
              var albumart = self.getAlbumArt({artist: albumartist, album: album}, self.getParentFolder(path), 'dot-circle-o');

              if (title) {
                title = title;
              } else {
                title = name;
              }
			  
			  // fix AlbumArtist for genre ----------------
			  if (artistsort) {	// for AlbumArtist

				if (artists.indexOf(albumartist) === -1) {
					artists.push(albumartist);
					artistArt.push();
					var codedArtists = encodeURIComponent(albumartist);

					if (albumartist !== '') {
					response.navigation.lists[0].items.push({
						service: 'mpd',
						type: 'folder',
						title: albumartist,
						albumart: self.getAlbumArt({artist: codedArtists}, undefined, 'users'),
						uri: 'genres://"' + encodeURIComponent(genreName) + '"/' + encodeURIComponent(albumartist)});
					}
				}
			  } else { // for Artist

				if (artists.indexOf(artist) === -1) {
					artists.push(artist);
					artistArt.push();

					if (artist !== '') {
					response.navigation.lists[0].items.push({
						service: 'mpd',
						type: 'folder',
						title: artist,
						albumart: self.getAlbumArt({artist: artist}, undefined, 'users'),
						uri: 'genres://"' + encodeURIComponent(genreName) + '"/' + encodeURIComponent(artist)});
					}
				}
			  }
			  // fix AlbumArtist for genre end ------------
			  
              if (albums.indexOf(album) === -1) {
                albums.push(album);
                albumsArt.push(albumart);

                if (album !== '') {
                  response.navigation.lists[1].items.push({
                    service: 'mpd',
                    type: 'folder',
                    title: album,
                    artist: albumartist,
                    albumart: albumart,
                    uri: 'genres://"' + genreName + '"/' + encodeURIComponent(albumartist) + '/' + encodeURIComponent(album)});
                }

              }
            }
          }

          defer.resolve(response);
        } else {
          self.logger.error('List Genre error: ' + err);
          defer.reject(new Error());
        }
      });
    });
  return defer.promise;
};


Best regards
2aCD