Fixed: "Specific Book" setting for lidarr list import

Fixes #2435

(cherry picked from commit 466876da624843f62c849dfb28ac9515b6fe3a2c)
pull/2877/head
Thomas White 2 years ago committed by ta264
parent d85d2bb371
commit d96775a4a3

@ -73,6 +73,18 @@ namespace NzbDrone.Core.Test.ImportListTests
_importListReports.First().AlbumMusicBrainzId = "09474d62-17dd-3a4f-98fb-04c65f38a479"; _importListReports.First().AlbumMusicBrainzId = "09474d62-17dd-3a4f-98fb-04c65f38a479";
} }
private void WithSecondBook()
{
var importListItem2 = new ImportListItemInfo
{
Artist = "Linkin Park",
ArtistMusicBrainzId = "f59c5520-5f46-4d2c-b2c4-822eabf53419",
Album = "Meteora 2",
AlbumMusicBrainzId = "madeup"
};
_importListReports.Add(importListItem2);
}
private void WithExistingArtist() private void WithExistingArtist()
{ {
Mocker.GetMock<IArtistService>() Mocker.GetMock<IArtistService>()
@ -275,5 +287,28 @@ namespace NzbDrone.Core.Test.ImportListTests
Mocker.GetMock<IAddAlbumService>() Mocker.GetMock<IAddAlbumService>()
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0), false, It.IsAny<bool>())); .Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 0), false, It.IsAny<bool>()));
} }
[TestCase(ImportListMonitorType.None, 0, false)]
[TestCase(ImportListMonitorType.SpecificAlbum, 2, true)]
[TestCase(ImportListMonitorType.EntireArtist, 0, true)]
public void should_add_two_albums(ImportListMonitorType monitor, int expectedAlbumsMonitored, bool expectedArtistMonitored)
{
WithAlbum();
WithAlbumId();
WithSecondBook();
WithArtistId();
WithMonitorType(monitor);
Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddAlbumService>()
.Verify(v => v.AddAlbums(It.Is<List<Album>>(t => t.Count == 2), false, true));
Mocker.GetMock<IAddArtistService>()
.Verify(v => v.AddArtists(It.Is<List<Artist>>(t => t.Count == 1 &&
t.First().AddOptions.AlbumsToMonitor.Count == expectedAlbumsMonitored &&
t.First().Monitored == expectedArtistMonitored),
false,
true));
}
} }
} }

@ -104,7 +104,7 @@ namespace NzbDrone.Core.ImportLists
MapAlbumReport(report); MapAlbumReport(report);
} }
ProcessAlbumReport(importList, report, listExclusions, albumsToAdd); ProcessAlbumReport(importList, report, listExclusions, albumsToAdd, artistsToAdd);
} }
else if (report.Artist.IsNotNullOrWhiteSpace() || report.ArtistMusicBrainzId.IsNotNullOrWhiteSpace()) else if (report.Artist.IsNotNullOrWhiteSpace() || report.ArtistMusicBrainzId.IsNotNullOrWhiteSpace())
{ {
@ -147,11 +147,11 @@ namespace NzbDrone.Core.ImportLists
report.AlbumMusicBrainzId = mappedAlbum.ForeignAlbumId; report.AlbumMusicBrainzId = mappedAlbum.ForeignAlbumId;
report.Album = mappedAlbum.Title; report.Album = mappedAlbum.Title;
report.Artist = mappedAlbum.ArtistMetadata?.Value?.Name; report.Artist ??= mappedAlbum.ArtistMetadata?.Value?.Name;
report.ArtistMusicBrainzId = mappedAlbum.ArtistMetadata?.Value?.ForeignArtistId; report.ArtistMusicBrainzId ??= mappedAlbum.ArtistMetadata?.Value?.ForeignArtistId;
} }
private void ProcessAlbumReport(ImportListDefinition importList, ImportListItemInfo report, List<ImportListExclusion> listExclusions, List<Album> albumsToAdd) private void ProcessAlbumReport(ImportListDefinition importList, ImportListItemInfo report, List<ImportListExclusion> listExclusions, List<Album> albumsToAdd, List<Artist> artistsToAdd)
{ {
if (report.AlbumMusicBrainzId == null) if (report.AlbumMusicBrainzId == null)
{ {
@ -169,13 +169,13 @@ namespace NzbDrone.Core.ImportLists
if (excludedAlbum != null) if (excludedAlbum != null)
{ {
_logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.AlbumMusicBrainzId, report.Album); _logger.Debug("{0} [{1}] Rejected due to list exclusion", report.AlbumMusicBrainzId, report.Album);
return; return;
} }
if (excludedArtist != null) if (excludedArtist != null)
{ {
_logger.Debug("{0} [{1}] Rejected due to list exlcusion for parent artist", report.AlbumMusicBrainzId, report.Album); _logger.Debug("{0} [{1}] Rejected due to list exclusion for parent artist", report.AlbumMusicBrainzId, report.Album);
return; return;
} }
@ -211,25 +211,32 @@ namespace NzbDrone.Core.ImportLists
{ {
var monitored = importList.ShouldMonitor != ImportListMonitorType.None; var monitored = importList.ShouldMonitor != ImportListMonitorType.None;
var toAddArtist = new Artist
{
Monitored = monitored,
RootFolderPath = importList.RootFolderPath,
QualityProfileId = importList.ProfileId,
MetadataProfileId = importList.MetadataProfileId,
Tags = importList.Tags,
AddOptions = new AddArtistOptions
{
SearchForMissingAlbums = monitored,
Monitored = monitored,
Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
}
};
if (report.ArtistMusicBrainzId != null && report.Artist != null)
{
toAddArtist = ProcessArtistReport(importList, report, listExclusions, artistsToAdd);
}
var toAdd = new Album var toAdd = new Album
{ {
ForeignAlbumId = report.AlbumMusicBrainzId, ForeignAlbumId = report.AlbumMusicBrainzId,
Monitored = monitored, Monitored = monitored,
AnyReleaseOk = true, AnyReleaseOk = true,
Artist = new Artist Artist = toAddArtist,
{
Monitored = monitored,
RootFolderPath = importList.RootFolderPath,
QualityProfileId = importList.ProfileId,
MetadataProfileId = importList.MetadataProfileId,
Tags = importList.Tags,
AddOptions = new AddArtistOptions
{
SearchForMissingAlbums = monitored,
Monitored = monitored,
Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
}
},
AddOptions = new AddAlbumOptions AddOptions = new AddAlbumOptions
{ {
SearchForNewAlbum = monitored SearchForNewAlbum = monitored
@ -238,7 +245,7 @@ namespace NzbDrone.Core.ImportLists
if (importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum) if (importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum)
{ {
toAdd.Artist.Value.AddOptions.AlbumsToMonitor.Add(toAdd.ForeignAlbumId); toAddArtist.AddOptions.AlbumsToMonitor.Add(toAdd.ForeignAlbumId);
} }
albumsToAdd.Add(toAdd); albumsToAdd.Add(toAdd);
@ -253,11 +260,11 @@ namespace NzbDrone.Core.ImportLists
report.Artist = mappedArtist?.Metadata.Value?.Name; report.Artist = mappedArtist?.Metadata.Value?.Name;
} }
private void ProcessArtistReport(ImportListDefinition importList, ImportListItemInfo report, List<ImportListExclusion> listExclusions, List<Artist> artistsToAdd) private Artist ProcessArtistReport(ImportListDefinition importList, ImportListItemInfo report, List<ImportListExclusion> listExclusions, List<Artist> artistsToAdd)
{ {
if (report.ArtistMusicBrainzId == null) if (report.ArtistMusicBrainzId == null)
{ {
return; return null;
} }
// Check to see if artist in DB // Check to see if artist in DB
@ -266,15 +273,18 @@ namespace NzbDrone.Core.ImportLists
// Check to see if artist excluded // Check to see if artist excluded
var excludedArtist = listExclusions.Where(s => s.ForeignId == report.ArtistMusicBrainzId).SingleOrDefault(); var excludedArtist = listExclusions.Where(s => s.ForeignId == report.ArtistMusicBrainzId).SingleOrDefault();
// Check to see if artist in import
var existingImportArtist = artistsToAdd.Find(i => i.ForeignArtistId == report.ArtistMusicBrainzId);
if (excludedArtist != null) if (excludedArtist != null)
{ {
_logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.ArtistMusicBrainzId, report.Artist); _logger.Debug("{0} [{1}] Rejected due to list exclusion", report.ArtistMusicBrainzId, report.Artist);
return; return null;
} }
if (existingArtist != null) if (existingArtist != null)
{ {
_logger.Debug("{0} [{1}] Rejected, Author Exists in DB. Ensuring Author monitored", report.ArtistMusicBrainzId, report.Artist); _logger.Debug("{0} [{1}] Rejected, artist exists in DB. Ensuring artist monitored", report.ArtistMusicBrainzId, report.Artist);
if (!existingArtist.Monitored) if (!existingArtist.Monitored)
{ {
@ -282,35 +292,42 @@ namespace NzbDrone.Core.ImportLists
_artistService.UpdateArtist(existingArtist); _artistService.UpdateArtist(existingArtist);
} }
return; return existingArtist;
} }
// Append Artist if not already in DB or already on add list if (existingImportArtist != null)
if (artistsToAdd.All(s => s.Metadata.Value.ForeignArtistId != report.ArtistMusicBrainzId))
{ {
var monitored = importList.ShouldMonitor != ImportListMonitorType.None; _logger.Debug("{0} [{1}] Rejected, artist exists in Import.", report.ArtistMusicBrainzId, report.Artist);
return existingImportArtist;
}
var monitored = importList.ShouldMonitor != ImportListMonitorType.None;
artistsToAdd.Add(new Artist var toAdd = new Artist
{
Metadata = new ArtistMetadata
{ {
Metadata = new ArtistMetadata ForeignArtistId = report.ArtistMusicBrainzId,
{ Name = report.Artist
ForeignArtistId = report.ArtistMusicBrainzId, },
Name = report.Artist Monitored = monitored,
}, MonitorNewItems = importList.MonitorNewItems,
RootFolderPath = importList.RootFolderPath,
QualityProfileId = importList.ProfileId,
MetadataProfileId = importList.MetadataProfileId,
Tags = importList.Tags,
AddOptions = new AddArtistOptions
{
SearchForMissingAlbums = monitored,
Monitored = monitored, Monitored = monitored,
MonitorNewItems = importList.MonitorNewItems, Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
RootFolderPath = importList.RootFolderPath, }
QualityProfileId = importList.ProfileId, };
MetadataProfileId = importList.MetadataProfileId,
Tags = importList.Tags, artistsToAdd.Add(toAdd);
AddOptions = new AddArtistOptions
{ return toAdd;
SearchForMissingAlbums = monitored,
Monitored = monitored,
Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
}
});
}
} }
public void Execute(ImportListSyncCommand message) public void Execute(ImportListSyncCommand message)

@ -4,6 +4,7 @@ namespace NzbDrone.Core.ImportLists.Lidarr
{ {
public class LidarrArtist public class LidarrArtist
{ {
public int Id { get; set; }
public string ArtistName { get; set; } public string ArtistName { get; set; }
public string ForeignArtistId { get; set; } public string ForeignArtistId { get; set; }
public string Overview { get; set; } public string Overview { get; set; }
@ -13,6 +14,17 @@ namespace NzbDrone.Core.ImportLists.Lidarr
public HashSet<int> Tags { get; set; } public HashSet<int> Tags { get; set; }
} }
public class LidarrAlbum
{
public int ArtistId { get; set; }
public string Title { get; set; }
public string ForeignAlbumId { get; set; }
public string Overview { get; set; }
public List<MediaCover.MediaCover> Images { get; set; }
public bool Monitored { get; set; }
public LidarrArtist Artist { get; set; }
}
public class LidarrProfile public class LidarrProfile
{ {
public string Name { get; set; } public string Name { get; set; }

@ -30,21 +30,28 @@ namespace NzbDrone.Core.ImportLists.Lidarr
public override IList<ImportListItemInfo> Fetch() public override IList<ImportListItemInfo> Fetch()
{ {
var artists = new List<ImportListItemInfo>(); var artistsAndAlbums = new List<ImportListItemInfo>();
try try
{ {
var remoteAlbums = _lidarrV1Proxy.GetAlbums(Settings);
var remoteArtists = _lidarrV1Proxy.GetArtists(Settings); var remoteArtists = _lidarrV1Proxy.GetArtists(Settings);
foreach (var remoteArtist in remoteArtists) var artistDict = remoteArtists.ToDictionary(x => x.Id);
foreach (var remoteAlbum in remoteAlbums)
{ {
var remoteArtist = artistDict[remoteAlbum.ArtistId];
if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(remoteArtist.QualityProfileId)) && if ((!Settings.ProfileIds.Any() || Settings.ProfileIds.Contains(remoteArtist.QualityProfileId)) &&
(!Settings.TagIds.Any() || Settings.TagIds.Any(x => remoteArtist.Tags.Any(y => y == x)))) (!Settings.TagIds.Any() || Settings.TagIds.Any(x => remoteArtist.Tags.Any(y => y == x))) &&
remoteAlbum.Monitored && remoteArtist.Monitored)
{ {
artists.Add(new ImportListItemInfo artistsAndAlbums.Add(new ImportListItemInfo
{ {
ArtistMusicBrainzId = remoteArtist.ForeignArtistId, ArtistMusicBrainzId = remoteArtist.ForeignArtistId,
Artist = remoteArtist.ArtistName Artist = remoteArtist.ArtistName,
AlbumMusicBrainzId = remoteAlbum.ForeignAlbumId,
Album = remoteAlbum.Title
}); });
} }
} }
@ -56,7 +63,7 @@ namespace NzbDrone.Core.ImportLists.Lidarr
_importListStatusService.RecordFailure(Definition.Id); _importListStatusService.RecordFailure(Definition.Id);
} }
return CleanupListItems(artists); return CleanupListItems(artistsAndAlbums);
} }
public override object RequestAction(string action, IDictionary<string, string> query) public override object RequestAction(string action, IDictionary<string, string> query)

@ -12,6 +12,7 @@ namespace NzbDrone.Core.ImportLists.Lidarr
public interface ILidarrV1Proxy public interface ILidarrV1Proxy
{ {
List<LidarrArtist> GetArtists(LidarrSettings settings); List<LidarrArtist> GetArtists(LidarrSettings settings);
List<LidarrAlbum> GetAlbums(LidarrSettings settings);
List<LidarrProfile> GetProfiles(LidarrSettings settings); List<LidarrProfile> GetProfiles(LidarrSettings settings);
List<LidarrTag> GetTags(LidarrSettings settings); List<LidarrTag> GetTags(LidarrSettings settings);
ValidationFailure Test(LidarrSettings settings); ValidationFailure Test(LidarrSettings settings);
@ -33,6 +34,11 @@ namespace NzbDrone.Core.ImportLists.Lidarr
return Execute<LidarrArtist>("/api/v1/artist", settings); return Execute<LidarrArtist>("/api/v1/artist", settings);
} }
public List<LidarrAlbum> GetAlbums(LidarrSettings settings)
{
return Execute<LidarrAlbum>("/api/v1/album", settings);
}
public List<LidarrProfile> GetProfiles(LidarrSettings settings) public List<LidarrProfile> GetProfiles(LidarrSettings settings)
{ {
return Execute<LidarrProfile>("/api/v1/qualityprofile", settings); return Execute<LidarrProfile>("/api/v1/qualityprofile", settings);

@ -41,9 +41,9 @@ namespace NzbDrone.Core.Music
if (monitoredAlbums.Any()) if (monitoredAlbums.Any())
{ {
ToggleAlbumsMonitoredState( ToggleAlbumsMonitoredState(
albums.Where(s => monitoredAlbums.Any(t => t == s.ForeignAlbumId)), true); albums.Where(s => monitoredAlbums.Contains(s.ForeignAlbumId)), true);
ToggleAlbumsMonitoredState( ToggleAlbumsMonitoredState(
albums.Where(s => monitoredAlbums.Any(t => t != s.ForeignAlbumId)), false); albums.Where(s => !monitoredAlbums.Contains(s.ForeignAlbumId)), false);
} }
else else
{ {

Loading…
Cancel
Save