Fixed: NullReferenceException manually importing an unparseable release

Fixes Sentry LIDARR-GY

(cherry picked from commit 702480852e742c39edacbe40977837381dc884ba)
This commit is contained in:
ta264 2021-08-04 21:58:33 +01:00
parent 334044ae31
commit f7925ff5d6
1 changed files with 11 additions and 1 deletions

View File

@ -384,7 +384,17 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
}
}
if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteAlbum.Albums.Count))
var remoteTrackCount = Math.Max(1,
trackedDownload.RemoteAlbum?.Albums.Sum(x =>
x.AlbumReleases.Value.Where(y => y.Monitored).Sum(z => z.TrackCount)) ?? 1);
var importResults = groupedTrackedDownload.Select(x => x.ImportResult).ToList();
var importedTrackCount = importResults.Where(c => c.Result == ImportResultType.Imported)
.SelectMany(c => c.ImportDecision.Item.Tracks)
.Count();
var allTracksImported = importResults.All(c => c.Result == ImportResultType.Imported) || importedTrackCount >= remoteTrackCount;
if (allTracksImported)
{
trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, importArtist.Id));