Allow changing monitoring the artist without the albums

pull/4227/head v2.0.0.3707
Bogdan 1 year ago
parent 690b2c72c8
commit 661338f5b1

@ -25,71 +25,79 @@ namespace NzbDrone.Core.Music
public void SetAlbumMonitoredStatus(Artist artist, MonitoringOptions monitoringOptions) public void SetAlbumMonitoredStatus(Artist artist, MonitoringOptions monitoringOptions)
{ {
if (monitoringOptions != null) // Update the artist without changing the albums
if (monitoringOptions == null)
{ {
_logger.Debug("[{0}] Setting album monitored status.", artist.Name); _artistService.UpdateArtist(artist);
return;
}
var albums = _albumService.GetAlbumsByArtist(artist.Id); var monitoredAlbums = monitoringOptions.AlbumsToMonitor;
var albumsWithFiles = _albumService.GetArtistAlbumsWithFiles(artist); if (monitoringOptions.Monitor == MonitorTypes.Unknown && monitoredAlbums is not { Count: not 0 })
{
return;
}
var albumsWithoutFiles = albums.Where(c => !albumsWithFiles.Select(e => e.Id).Contains(c.Id) && c.ReleaseDate <= DateTime.UtcNow).ToList(); _logger.Debug("[{0}] Setting album monitored status.", artist.Name);
var monitoredAlbums = monitoringOptions.AlbumsToMonitor; var albums = _albumService.GetAlbumsByArtist(artist.Id);
// If specific albums are passed use those instead of the monitoring options. // If specific albums are passed use those instead of the monitoring options.
if (monitoredAlbums.Any()) if (monitoredAlbums.Any())
{ {
ToggleAlbumsMonitoredState(albums.Where(s => monitoredAlbums.Contains(s.ForeignAlbumId)), true); ToggleAlbumsMonitoredState(albums.Where(s => monitoredAlbums.Contains(s.ForeignAlbumId)), true);
ToggleAlbumsMonitoredState(albums.Where(s => !monitoredAlbums.Contains(s.ForeignAlbumId)), false); ToggleAlbumsMonitoredState(albums.Where(s => !monitoredAlbums.Contains(s.ForeignAlbumId)), false);
} }
else else
{
var albumsWithFiles = _albumService.GetArtistAlbumsWithFiles(artist);
var albumsWithoutFiles = albums.Where(c => !albumsWithFiles.Select(e => e.Id).Contains(c.Id) && c.ReleaseDate <= DateTime.UtcNow).ToList();
switch (monitoringOptions.Monitor)
{ {
switch (monitoringOptions.Monitor) case MonitorTypes.All:
{ _logger.Debug("Monitoring all albums");
case MonitorTypes.All: ToggleAlbumsMonitoredState(albums, true);
ToggleAlbumsMonitoredState(albums, true); break;
break; case MonitorTypes.Future:
case MonitorTypes.Future: _logger.Debug("Unmonitoring Albums with Files");
_logger.Debug("Unmonitoring Albums with Files"); ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), false);
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), false); _logger.Debug("Unmonitoring Albums without Files");
_logger.Debug("Unmonitoring Albums without Files"); ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), false);
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), false); break;
break; case MonitorTypes.Missing:
case MonitorTypes.None: _logger.Debug("Unmonitoring Albums with Files");
ToggleAlbumsMonitoredState(albums, false); ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), false);
break; _logger.Debug("Monitoring Albums without Files");
case MonitorTypes.Missing: ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), true);
_logger.Debug("Unmonitoring Albums with Files"); break;
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), false); case MonitorTypes.Existing:
_logger.Debug("Monitoring Albums without Files"); _logger.Debug("Monitoring Albums with Files");
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), true); ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), true);
break; _logger.Debug("Unmonitoring Albums without Files");
case MonitorTypes.Existing: ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), false);
_logger.Debug("Monitoring Albums with Files"); break;
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithFiles.Select(c => c.Id).Contains(e.Id)), true); case MonitorTypes.Latest:
_logger.Debug("Unmonitoring Albums without Files"); _logger.Debug("Monitoring latest album");
ToggleAlbumsMonitoredState(albums.Where(e => albumsWithoutFiles.Select(c => c.Id).Contains(e.Id)), false); ToggleAlbumsMonitoredState(albums, false);
break; ToggleAlbumsMonitoredState(albums.OrderByDescending(e => e.ReleaseDate).Take(1), true);
case MonitorTypes.Latest: break;
ToggleAlbumsMonitoredState(albums, false); case MonitorTypes.First:
ToggleAlbumsMonitoredState(albums.OrderByDescending(e => e.ReleaseDate).Take(1), true); _logger.Debug("Monitoring first album");
break; ToggleAlbumsMonitoredState(albums, false);
case MonitorTypes.First: ToggleAlbumsMonitoredState(albums.OrderBy(e => e.ReleaseDate).Take(1), true);
ToggleAlbumsMonitoredState(albums, false); break;
ToggleAlbumsMonitoredState(albums.OrderBy(e => e.ReleaseDate).Take(1), true); case MonitorTypes.None:
break; _logger.Debug("Unmonitoring all albums");
case MonitorTypes.Unknown: ToggleAlbumsMonitoredState(albums, false);
// Ignoring, it's the default value break;
break; default:
default: throw new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException();
}
} }
_albumService.UpdateMany(albums);
} }
_albumService.UpdateMany(albums);
_artistService.UpdateArtist(artist); _artistService.UpdateArtist(artist);
} }

Loading…
Cancel
Save