mirror of
https://github.com/Radarr/Radarr
synced 2025-02-24 23:23:21 +00:00
Fixed: Throw to manual import if multiple movies found during title mapping
This commit is contained in:
parent
84e0f5bfcf
commit
e32383e763
4 changed files with 55 additions and 19 deletions
|
@ -132,12 +132,25 @@ public ManualImportItem ReprocessItem(string path, string downloadId, int movieI
|
|||
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 @@ public Movie FindByTitle(List<string> titles, int? year, List<string> otherTitle
|
|||
{
|
||||
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 @@ public bool ExistsByMetadataId(int metadataId)
|
|||
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;
|
||||
|
|
12
src/NzbDrone.Core/Movies/MultipleMoviesFoundException.cs
Normal file
12
src/NzbDrone.Core/Movies/MultipleMoviesFoundException.cs
Normal file
|
@ -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…
Reference in a new issue