diff --git a/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs b/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs index 966a71183..a8a6f35be 100644 --- a/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs +++ b/src/NzbDrone.Core.Test/MusicTests/ArtistRepositoryTests/ArtistRepositoryFixture.cs @@ -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(); } [Test] diff --git a/src/NzbDrone.Core/MediaFiles/TrackImport/Manual/ManualImportService.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/Manual/ManualImportService.cs index 912bd4a9d..fb35fa4a8 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackImport/Manual/ManualImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/Manual/ManualImportService.cs @@ -153,7 +153,15 @@ private List 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()) { diff --git a/src/NzbDrone.Core/Music/MultipleArtistsFoundException.cs b/src/NzbDrone.Core/Music/MultipleArtistsFoundException.cs new file mode 100644 index 000000000..fdc6a348f --- /dev/null +++ b/src/NzbDrone.Core/Music/MultipleArtistsFoundException.cs @@ -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) + { + } + } +} diff --git a/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs b/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs index f38056a36..f11194c54 100644 --- a/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs +++ b/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs @@ -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 GetArtistByMetadataId(IEnumerable artistMetadataIds) { return Query(s => artistMetadataIds.Contains(s.ArtistMetadataId)); } + + private static Artist ReturnSingleArtistOrThrow(List 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))); + } } }