mirror of
https://github.com/Lidarr/Lidarr
synced 2025-12-06 08:25:54 +01:00
Fixed: Multiple artists found during manual import prevents manual importing from folder
(cherry picked from commit 00c922875f7a41c9e1750e0257764bd633f41746) Fix
This commit is contained in:
parent
aaf025033e
commit
eb7e77b8e2
4 changed files with 56 additions and 4 deletions
|
|
@ -135,8 +135,8 @@ public void should_not_find_artist_if_multiple_artists_have_same_name()
|
|||
|
||||
_artistRepo.All().Should().HaveCount(4);
|
||||
|
||||
var artist = _artistRepo.FindByName(Parser.Parser.CleanArtistName(name));
|
||||
artist.Should().BeNull();
|
||||
Action act = () => _artistRepo.FindByName(Parser.Parser.CleanArtistName(name));
|
||||
act.Should().Throw<MultipleArtistsFoundException>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
|
|
@ -153,7 +153,15 @@ private List<ManualImportItem> ProcessFolder(string folder, string downloadId, A
|
|||
{
|
||||
DownloadClientItem downloadClientItem = null;
|
||||
var directoryInfo = new DirectoryInfo(folder);
|
||||
artist = artist ?? _parsingService.GetArtist(directoryInfo.Name);
|
||||
|
||||
try
|
||||
{
|
||||
artist ??= _parsingService.GetArtist(directoryInfo.Name);
|
||||
}
|
||||
catch (MultipleArtistsFoundException e)
|
||||
{
|
||||
_logger.Warn(e, "Unable to find artist from title");
|
||||
}
|
||||
|
||||
if (downloadId.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
|
|
|
|||
27
src/NzbDrone.Core/Music/MultipleArtistsFoundException.cs
Normal file
27
src/NzbDrone.Core/Music/MultipleArtistsFoundException.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using NzbDrone.Common.Exceptions;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class MultipleArtistsFoundException : NzbDroneException
|
||||
{
|
||||
public MultipleArtistsFoundException(string message, params object[] args)
|
||||
: base(message, args)
|
||||
{
|
||||
}
|
||||
|
||||
public MultipleArtistsFoundException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public MultipleArtistsFoundException(string message, System.Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
protected MultipleArtistsFoundException(string message, System.Exception innerException, params object[] args)
|
||||
: base(message, innerException, args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +61,9 @@ public Artist FindByName(string cleanName)
|
|||
{
|
||||
cleanName = cleanName.ToLowerInvariant();
|
||||
|
||||
return Query(s => s.CleanName == cleanName).ExclusiveOrDefault();
|
||||
var artists = Query(s => s.CleanName == cleanName).ToList();
|
||||
|
||||
return ReturnSingleArtistOrThrow(artists);
|
||||
}
|
||||
|
||||
public Artist GetArtistByMetadataId(int artistMetadataId)
|
||||
|
|
@ -91,5 +93,20 @@ public List<Artist> GetArtistByMetadataId(IEnumerable<int> artistMetadataIds)
|
|||
{
|
||||
return Query(s => artistMetadataIds.Contains(s.ArtistMetadataId));
|
||||
}
|
||||
|
||||
private static Artist ReturnSingleArtistOrThrow(List<Artist> artists)
|
||||
{
|
||||
if (artists.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (artists.Count == 1)
|
||||
{
|
||||
return artists[0];
|
||||
}
|
||||
|
||||
throw new MultipleArtistsFoundException("Expected one artist, but found {0}. Matching artists: {1}", artists.Count, string.Join(",", artists.Select(s => s.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue