Fixed: Multiple series found during manual import prevents manual importing from folder

Fixes #3512
This commit is contained in:
Mark McDowall 2020-03-18 19:30:02 -07:00
parent 8c93d73b42
commit 00c922875f
3 changed files with 53 additions and 8 deletions

View File

@ -105,11 +105,25 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual
private List<ManualImportItem> ProcessFolder(string rootFolder, string baseFolder, string downloadId, int? seriesId, bool filterExistingFiles) private List<ManualImportItem> ProcessFolder(string rootFolder, string baseFolder, string downloadId, int? seriesId, bool filterExistingFiles)
{ {
DownloadClientItem downloadClientItem = null; DownloadClientItem downloadClientItem = null;
Series series = null;
var directoryInfo = new DirectoryInfo(baseFolder); var directoryInfo = new DirectoryInfo(baseFolder);
var series = seriesId.HasValue ? if (seriesId.HasValue)
_seriesService.GetSeries(seriesId.Value) : {
_parsingService.GetSeries(directoryInfo.Name); 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()) if (downloadId.IsNotNullOrWhiteSpace())
{ {

View File

@ -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)
{
}
}
}

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Exceptions;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -36,17 +37,21 @@ namespace NzbDrone.Core.Tv
{ {
cleanTitle = cleanTitle.ToLowerInvariant(); cleanTitle = cleanTitle.ToLowerInvariant();
return Query.Where(s => s.CleanTitle == cleanTitle) var series = Query.Where(s => s.CleanTitle == cleanTitle)
.SingleOrDefault(); .ToList();
return ReturnSingleSeriesOrThrow(series);
} }
public Series FindByTitle(string cleanTitle, int year) public Series FindByTitle(string cleanTitle, int year)
{ {
cleanTitle = cleanTitle.ToLowerInvariant(); cleanTitle = cleanTitle.ToLowerInvariant();
return Query.Where(s => s.CleanTitle == cleanTitle) var series = Query.Where(s => s.CleanTitle == cleanTitle)
.AndWhere(s => s.Year == year) .AndWhere(s => s.Year == year)
.SingleOrDefault(); .ToList();
return ReturnSingleSeriesOrThrow(series);
} }
public List<Series> FindByTitleInexact(string cleanTitle) public List<Series> FindByTitleInexact(string cleanTitle)
@ -72,5 +77,20 @@ namespace NzbDrone.Core.Tv
return Query.Where(s => s.Path == path) return Query.Where(s => s.Path == path)
.FirstOrDefault(); .FirstOrDefault();
} }
private Series ReturnSingleSeriesOrThrow(List<Series> 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));
}
} }
} }