diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs index 36985b738..7cfa88367 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs @@ -105,11 +105,25 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual private List ProcessFolder(string rootFolder, string baseFolder, string downloadId, int? seriesId, bool filterExistingFiles) { DownloadClientItem downloadClientItem = null; + Series series = null; + var directoryInfo = new DirectoryInfo(baseFolder); - var series = seriesId.HasValue ? - _seriesService.GetSeries(seriesId.Value) : - _parsingService.GetSeries(directoryInfo.Name); + if (seriesId.HasValue) + { + series = _seriesService.GetSeries(seriesId.Value); + } + else + { + try + { + series = _parsingService.GetSeries(directoryInfo.Name); + } + catch (MultipleSeriesFoundException e) + { + _logger.Warn(e, "Unable to find series from title"); + } + } if (downloadId.IsNotNullOrWhiteSpace()) { diff --git a/src/NzbDrone.Core/Tv/MultipleSeriesFoundException.cs b/src/NzbDrone.Core/Tv/MultipleSeriesFoundException.cs new file mode 100644 index 000000000..608e82c26 --- /dev/null +++ b/src/NzbDrone.Core/Tv/MultipleSeriesFoundException.cs @@ -0,0 +1,11 @@ +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Core.Tv +{ + public class MultipleSeriesFoundException : NzbDroneException + { + public MultipleSeriesFoundException(string message, params object[] args) : base(message, args) + { + } + } +} diff --git a/src/NzbDrone.Core/Tv/SeriesRepository.cs b/src/NzbDrone.Core/Tv/SeriesRepository.cs index 15f72a952..bc8f8f97f 100644 --- a/src/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/src/NzbDrone.Core/Tv/SeriesRepository.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Exceptions; using NzbDrone.Core.Messaging.Events; @@ -36,17 +37,21 @@ namespace NzbDrone.Core.Tv { cleanTitle = cleanTitle.ToLowerInvariant(); - return Query.Where(s => s.CleanTitle == cleanTitle) - .SingleOrDefault(); + var series = Query.Where(s => s.CleanTitle == cleanTitle) + .ToList(); + + return ReturnSingleSeriesOrThrow(series); } public Series FindByTitle(string cleanTitle, int year) { cleanTitle = cleanTitle.ToLowerInvariant(); - return Query.Where(s => s.CleanTitle == cleanTitle) - .AndWhere(s => s.Year == year) - .SingleOrDefault(); + var series = Query.Where(s => s.CleanTitle == cleanTitle) + .AndWhere(s => s.Year == year) + .ToList(); + + return ReturnSingleSeriesOrThrow(series); } public List FindByTitleInexact(string cleanTitle) @@ -72,5 +77,20 @@ namespace NzbDrone.Core.Tv return Query.Where(s => s.Path == path) .FirstOrDefault(); } + + private Series ReturnSingleSeriesOrThrow(List series) + { + if (series.Count == 0) + { + return null; + } + + if (series.Count == 1) + { + return series.First(); + } + + throw new MultipleSeriesFoundException("Expected one series, but found {0}. Matching series: {1}", series.Count, string.Join(",", series)); + } } }