Fixed: Throw to manual import if multiple movies found during title mapping

pull/8422/head
Qstick 2 years ago
parent 84e0f5bfcf
commit e32383e763

@ -132,12 +132,25 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Manual
private List<ManualImportItem> ProcessFolder(string rootFolder, string baseFolder, string downloadId, int? movieId, bool filterExistingFiles)
{
DownloadClientItem downloadClientItem = null;
Movie movie = null;
var directoryInfo = new DirectoryInfo(baseFolder);
var movie = movieId.HasValue ?
_movieService.GetMovie(movieId.Value) :
_parsingService.GetMovie(directoryInfo.Name);
if (movieId.HasValue)
{
movie = _movieService.GetMovie(movieId.Value);
}
else
{
try
{
movie = _parsingService.GetMovie(directoryInfo.Name);
}
catch (MultipleMoviesFoundException e)
{
_logger.Warn(e, "Unable to match movie by title");
}
}
if (downloadId.IsNotNullOrWhiteSpace())
{

@ -124,37 +124,33 @@ namespace NzbDrone.Core.Movies
{
var cleanTitles = titles.Select(t => t.CleanMovieTitle().ToLowerInvariant());
var result = candidates.Where(x => cleanTitles.Contains(x.MovieMetadata.Value.CleanTitle)).FirstWithYear(year);
var result = candidates.Where(x => cleanTitles.Contains(x.MovieMetadata.Value.CleanTitle) || cleanTitles.Contains(x.MovieMetadata.Value.CleanOriginalTitle))
.AllWithYear(year)
.ToList();
if (result == null)
if (result == null || result.Count == 0)
{
result =
candidates.Where(movie => cleanTitles.Contains(movie.MovieMetadata.Value.CleanOriginalTitle)).FirstWithYear(year);
candidates.Where(movie => otherTitles.Contains(movie.MovieMetadata.Value.CleanTitle)).AllWithYear(year).ToList();
}
if (result == null)
{
result =
candidates.Where(movie => otherTitles.Contains(movie.MovieMetadata.Value.CleanTitle)).FirstWithYear(year);
}
if (result == null)
if (result == null || result.Count == 0)
{
result = candidates
.Where(m => m.MovieMetadata.Value.AlternativeTitles.Any(t => cleanTitles.Contains(t.CleanTitle) ||
otherTitles.Contains(t.CleanTitle)))
.FirstWithYear(year);
.AllWithYear(year).ToList();
}
if (result == null)
if (result == null || result.Count == 0)
{
result = candidates
.Where(m => m.MovieMetadata.Value.Translations.Any(t => cleanTitles.Contains(t.CleanTitle) ||
otherTitles.Contains(t.CleanTitle)))
.FirstWithYear(year);
.AllWithYear(year).ToList();
}
return result;
return ReturnSingleMovieOrThrow(result.ToList());
}
public List<Movie> FindByTitleCandidates(List<string> titles, out List<string> otherTitles)
@ -395,6 +391,21 @@ namespace NzbDrone.Core.Movies
return _movieRepository.ExistsByMetadataId(metadataId);
}
private Movie ReturnSingleMovieOrThrow(List<Movie> movies)
{
if (movies.Count == 0)
{
return null;
}
if (movies.Count == 1)
{
return movies.First();
}
throw new MultipleMoviesFoundException("Expected one movie, but found {0}. Matching movies: {1}", movies.Count, string.Join(",", movies));
}
public void Handle(MovieFileAddedEvent message)
{
var movie = message.MovieFile.Movie;

@ -0,0 +1,12 @@
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.Movies
{
public class MultipleMoviesFoundException : NzbDroneException
{
public MultipleMoviesFoundException(string message, params object[] args)
: base(message, args)
{
}
}
}

@ -5,9 +5,9 @@ namespace NzbDrone.Core.Movies
{
public static class EnumerableExtensions
{
public static Movie FirstWithYear(this IEnumerable<Movie> query, int? year)
public static IEnumerable<Movie> AllWithYear(this IEnumerable<Movie> query, int? year)
{
return year.HasValue ? query.FirstOrDefault(movie => movie.Year == year || movie.MovieMetadata.Value.SecondaryYear == year) : query.FirstOrDefault();
return year.HasValue ? query.Where(movie => movie.Year == year || movie.MovieMetadata.Value.SecondaryYear == year) : query;
}
}
}

Loading…
Cancel
Save