mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Fixed: Only one version of an album may be approved for import
This commit is contained in:
parent
a3f5fa0596
commit
8ff141d886
2 changed files with 71 additions and 16 deletions
|
@ -272,6 +272,41 @@ namespace NzbDrone.Core.Test.MediaFiles.TrackImport
|
||||||
result.Single().Approved.Should().BeTrue();
|
result.Single().Approved.Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_reject_more_than_one_version_of_an_album()
|
||||||
|
{
|
||||||
|
GivenAugmentationSuccess();
|
||||||
|
|
||||||
|
GivenAudioFiles(new[]
|
||||||
|
{
|
||||||
|
@"C:\Test\Unsorted\release1\track1.mp3".AsOsAgnostic(),
|
||||||
|
@"C:\Test\Unsorted\release2\track1.mp3".AsOsAgnostic()
|
||||||
|
});
|
||||||
|
|
||||||
|
Mocker.GetMock<IIdentificationService>()
|
||||||
|
.Setup(s => s.Identify(It.IsAny<List<LocalTrack>>(), It.IsAny<IdentificationOverrides>(), It.IsAny<ImportDecisionMakerConfig>()))
|
||||||
|
.Returns((List<LocalTrack> tracks, IdentificationOverrides idOverrides, ImportDecisionMakerConfig config) =>
|
||||||
|
{
|
||||||
|
var ret1 = new LocalAlbumRelease(tracks.Take(1).ToList());
|
||||||
|
ret1.AlbumRelease = _albumRelease;
|
||||||
|
|
||||||
|
var ret2 = new LocalAlbumRelease(tracks.Skip(1).ToList());
|
||||||
|
var albumRelease2 = Builder<AlbumRelease>.CreateNew()
|
||||||
|
.With(x => x.Album = _album)
|
||||||
|
.With(x => x.ForeignReleaseId = "anotherid")
|
||||||
|
.Build();
|
||||||
|
ret2.AlbumRelease = albumRelease2;
|
||||||
|
|
||||||
|
return new List<LocalAlbumRelease> { ret1, ret2 };
|
||||||
|
});
|
||||||
|
|
||||||
|
GivenSpecifications(_pass1);
|
||||||
|
|
||||||
|
var result = Subject.GetImportDecisions(_fileInfos, null, null, _idConfig);
|
||||||
|
result.Count(x => x.Approved).Should().Be(1);
|
||||||
|
result.Count(x => !x.Approved).Should().Be(1);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
||||||
{
|
{
|
||||||
|
|
|
@ -141,8 +141,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
|
||||||
|
|
||||||
public List<ImportDecision<LocalTrack>> GetImportDecisions(List<IFileInfo> musicFiles, IdentificationOverrides idOverrides, ImportDecisionMakerInfo itemInfo, ImportDecisionMakerConfig config)
|
public List<ImportDecision<LocalTrack>> GetImportDecisions(List<IFileInfo> musicFiles, IdentificationOverrides idOverrides, ImportDecisionMakerInfo itemInfo, ImportDecisionMakerConfig config)
|
||||||
{
|
{
|
||||||
idOverrides = idOverrides ?? new IdentificationOverrides();
|
idOverrides ??= new IdentificationOverrides();
|
||||||
itemInfo = itemInfo ?? new ImportDecisionMakerInfo();
|
itemInfo ??= new ImportDecisionMakerInfo();
|
||||||
|
|
||||||
var trackData = GetLocalTracks(musicFiles, itemInfo.DownloadClientItem, itemInfo.ParsedTrackInfo, config.Filter);
|
var trackData = GetLocalTracks(musicFiles, itemInfo.DownloadClientItem, itemInfo.ParsedTrackInfo, config.Filter);
|
||||||
var localTracks = trackData.Item1;
|
var localTracks = trackData.Item1;
|
||||||
|
@ -152,16 +152,35 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
|
||||||
|
|
||||||
var releases = _identificationService.Identify(localTracks, idOverrides, config);
|
var releases = _identificationService.Identify(localTracks, idOverrides, config);
|
||||||
|
|
||||||
foreach (var release in releases)
|
var albums = releases.GroupBy(x => x.AlbumRelease?.Album?.Value.ForeignAlbumId);
|
||||||
|
|
||||||
|
// group releases that are identified as the same album
|
||||||
|
foreach (var album in albums)
|
||||||
|
{
|
||||||
|
var albumDecisions = new List<ImportDecision<LocalAlbumRelease>>();
|
||||||
|
|
||||||
|
foreach (var release in album)
|
||||||
{
|
{
|
||||||
// make sure the appropriate quality profile is set for the release artist
|
// make sure the appropriate quality profile is set for the release artist
|
||||||
// in case it's a new artist
|
// in case it's a new artist
|
||||||
EnsureData(release);
|
EnsureData(release);
|
||||||
release.NewDownload = config.NewDownload;
|
release.NewDownload = config.NewDownload;
|
||||||
|
|
||||||
var releaseDecision = GetDecision(release, itemInfo.DownloadClientItem);
|
albumDecisions.Add(GetDecision(release, itemInfo.DownloadClientItem));
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var localTrack in release.LocalTracks)
|
// if multiple album releases accepted, reject all but one with most tracks
|
||||||
|
var acceptedReleases = albumDecisions
|
||||||
|
.Where(x => x.Approved)
|
||||||
|
.OrderByDescending(x => x.Item.TrackCount);
|
||||||
|
foreach (var decision in acceptedReleases.Skip(1))
|
||||||
|
{
|
||||||
|
decision.Reject(new Rejection("Multiple versions of an album not supported"));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var releaseDecision in albumDecisions)
|
||||||
|
{
|
||||||
|
foreach (var localTrack in releaseDecision.Item.LocalTracks)
|
||||||
{
|
{
|
||||||
if (releaseDecision.Approved)
|
if (releaseDecision.Approved)
|
||||||
{
|
{
|
||||||
|
@ -173,6 +192,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return decisions;
|
return decisions;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue