mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
New: Use Translations for Movie Mapping
This commit is contained in:
parent
6d4be67e36
commit
e2165eb51b
@ -167,7 +167,7 @@ private ManualImportItem ProcessFile(string rootFolder, string baseFolder, strin
|
||||
|
||||
if (relativeParseInfo != null)
|
||||
{
|
||||
movie = _movieService.FindByTitle(relativeParseInfo.MovieTitle);
|
||||
movie = _movieService.FindByTitle(relativeParseInfo.MovieTitle, relativeParseInfo.Year);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Movies.AlternativeTitles;
|
||||
using NzbDrone.Core.Movies.Translations;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
@ -15,7 +16,6 @@ public interface IMovieRepository : IBasicRepository<Movie>
|
||||
{
|
||||
bool MoviePathExists(string path);
|
||||
List<Movie> FindByTitles(List<string> titles);
|
||||
List<Movie> FindByTitleInexact(string cleanTitle);
|
||||
Movie FindByImdbId(string imdbid);
|
||||
Movie FindByTmdbId(int tmdbid);
|
||||
List<Movie> FindByTmdbId(List<int> tmdbids);
|
||||
@ -45,7 +45,7 @@ public MovieRepository(IMainDatabase database,
|
||||
.LeftJoin<Movie, AlternativeTitle>((m, t) => m.Id == t.MovieId)
|
||||
.LeftJoin<Movie, MovieFile>((m, f) => m.Id == f.MovieId);
|
||||
|
||||
private Movie Map(Dictionary<int, Movie> dict, Movie movie, Profile profile, AlternativeTitle altTitle, MovieFile movieFile)
|
||||
private Movie Map(Dictionary<int, Movie> dict, Movie movie, Profile profile, AlternativeTitle altTitle, MovieFile movieFile, MovieTranslation translation = null)
|
||||
{
|
||||
Movie movieEntry;
|
||||
|
||||
@ -62,6 +62,11 @@ private Movie Map(Dictionary<int, Movie> dict, Movie movie, Profile profile, Alt
|
||||
movieEntry.AlternativeTitles.Add(altTitle);
|
||||
}
|
||||
|
||||
if (translation != null)
|
||||
{
|
||||
movieEntry.Translations.Add(translation);
|
||||
}
|
||||
|
||||
return movieEntry;
|
||||
}
|
||||
|
||||
@ -102,13 +107,19 @@ public bool MoviePathExists(string path)
|
||||
public List<Movie> FindByTitles(List<string> titles)
|
||||
{
|
||||
var distinct = titles.Distinct().ToList();
|
||||
return Query(Builder().OrWhere<Movie>(x => distinct.Contains(x.CleanTitle))
|
||||
.OrWhere<AlternativeTitle>(x => distinct.Contains(x.CleanTitle)));
|
||||
}
|
||||
var movieDictionary = new Dictionary<int, Movie>();
|
||||
|
||||
public List<Movie> FindByTitleInexact(string cleanTitle)
|
||||
{
|
||||
return Query(x => cleanTitle.Contains(x.CleanTitle));
|
||||
var builder = Builder()
|
||||
.LeftJoin<Movie, MovieTranslation>((m, tr) => m.Id == tr.MovieId)
|
||||
.OrWhere<Movie>(x => distinct.Contains(x.CleanTitle))
|
||||
.OrWhere<AlternativeTitle>(x => distinct.Contains(x.CleanTitle))
|
||||
.OrWhere<MovieTranslation>(x => distinct.Contains(x.CleanTitle));
|
||||
|
||||
_ = _database.QueryJoined<Movie, Profile, AlternativeTitle, MovieFile, MovieTranslation>(
|
||||
builder,
|
||||
(movie, profile, altTitle, file, trans) => Map(movieDictionary, movie, profile, altTitle, file, trans));
|
||||
|
||||
return movieDictionary.Values.ToList();
|
||||
}
|
||||
|
||||
public Movie FindByImdbId(string imdbid)
|
||||
|
@ -27,7 +27,6 @@ public interface IMovieService
|
||||
List<Movie> FindByTmdbId(List<int> tmdbids);
|
||||
Movie FindByTitle(string title);
|
||||
Movie FindByTitle(string title, int year);
|
||||
Movie FindByTitleInexact(string title, int? year);
|
||||
Movie FindByTitleSlug(string slug);
|
||||
Movie FindByPath(string path);
|
||||
List<string> AllMoviePaths();
|
||||
@ -58,10 +57,10 @@ public class MovieService : IMovieService, IHandle<MovieFileAddedEvent>,
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MovieService(IMovieRepository movieRepository,
|
||||
IEventAggregator eventAggregator,
|
||||
IConfigService configService,
|
||||
IBuildMoviePaths moviePathBuilder,
|
||||
Logger logger)
|
||||
IEventAggregator eventAggregator,
|
||||
IConfigService configService,
|
||||
IBuildMoviePaths moviePathBuilder,
|
||||
Logger logger)
|
||||
{
|
||||
_movieRepository = movieRepository;
|
||||
_eventAggregator = eventAggregator;
|
||||
@ -134,15 +133,24 @@ private Movie FindByTitle(string cleanTitle, int? year)
|
||||
result =
|
||||
candidates.Where(movie => movie.CleanTitle == cleanTitleWithArabicNumbers).FirstWithYear(year) ??
|
||||
candidates.Where(movie => movie.CleanTitle == cleanTitleWithRomanNumbers).FirstWithYear(year);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
result = candidates
|
||||
.Where(m => m.AlternativeTitles.Any(t => t.CleanTitle == cleanTitle ||
|
||||
t.CleanTitle == cleanTitleWithArabicNumbers ||
|
||||
t.CleanTitle == cleanTitleWithRomanNumbers))
|
||||
.FirstWithYear(year);
|
||||
}
|
||||
if (result == null)
|
||||
{
|
||||
result = candidates
|
||||
.Where(m => m.AlternativeTitles.Any(t => t.CleanTitle == cleanTitle ||
|
||||
t.CleanTitle == cleanTitleWithArabicNumbers ||
|
||||
t.CleanTitle == cleanTitleWithRomanNumbers))
|
||||
.FirstWithYear(year);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
result = candidates
|
||||
.Where(m => m.Translations.Any(t => t.CleanTitle == cleanTitle ||
|
||||
t.CleanTitle == cleanTitleWithArabicNumbers ||
|
||||
t.CleanTitle == cleanTitleWithRomanNumbers))
|
||||
.FirstWithYear(year);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -163,57 +171,6 @@ public List<Movie> FindByTmdbId(List<int> tmdbids)
|
||||
return _movieRepository.FindByTmdbId(tmdbids);
|
||||
}
|
||||
|
||||
private List<Movie> FindByTitleInexactAll(string title)
|
||||
{
|
||||
// find any movie clean title within the provided release title
|
||||
string cleanTitle = title.CleanMovieTitle();
|
||||
var list = _movieRepository.FindByTitleInexact(cleanTitle);
|
||||
if (!list.Any())
|
||||
{
|
||||
// no movie matched
|
||||
return list;
|
||||
}
|
||||
|
||||
// build ordered list of movie by position in the search string
|
||||
var query =
|
||||
list.Select(movie => new
|
||||
{
|
||||
position = cleanTitle.IndexOf(movie.CleanTitle),
|
||||
length = movie.CleanTitle.Length,
|
||||
movie
|
||||
})
|
||||
.Where(s => (s.position >= 0))
|
||||
.ToList()
|
||||
.OrderBy(s => s.position)
|
||||
.ThenByDescending(s => s.length)
|
||||
.Select(s => s.movie)
|
||||
.ToList();
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public Movie FindByTitleInexact(string title)
|
||||
{
|
||||
var query = FindByTitleInexactAll(title);
|
||||
|
||||
// get the leftmost movie that is the longest
|
||||
// movie are usually the first thing in release title, so we select the leftmost and longest match
|
||||
var match = query.First();
|
||||
|
||||
_logger.Debug("Multiple movie matched {0} from title {1}", match.Title, title);
|
||||
foreach (var entry in query)
|
||||
{
|
||||
_logger.Debug("Multiple movie match candidate: {0} cleantitle: {1}", entry.Title, entry.CleanTitle);
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
public Movie FindByTitleInexact(string title, int? year)
|
||||
{
|
||||
return FindByTitleInexactAll(title).FirstWithYear(year);
|
||||
}
|
||||
|
||||
public Movie FindByPath(string path)
|
||||
{
|
||||
return _movieRepository.FindByPath(path);
|
||||
|
@ -115,14 +115,14 @@ public Movie GetMovie(string title)
|
||||
return _movieService.FindByTitle(title);
|
||||
}
|
||||
|
||||
var movies = _movieService.FindByTitle(parsedMovieInfo.MovieTitle, parsedMovieInfo.Year);
|
||||
var movie = _movieService.FindByTitle(parsedMovieInfo.MovieTitle, parsedMovieInfo.Year);
|
||||
|
||||
if (movies == null)
|
||||
if (movie == null)
|
||||
{
|
||||
movies = _movieService.FindByTitle(parsedMovieInfo.MovieTitle.Replace("DC", "").Trim());
|
||||
movie = _movieService.FindByTitle(parsedMovieInfo.MovieTitle.Replace("DC", "").Trim());
|
||||
}
|
||||
|
||||
return movies;
|
||||
return movie;
|
||||
}
|
||||
|
||||
public MappingResult Map(ParsedMovieInfo parsedMovieInfo, string imdbId, SearchCriteriaBase searchCriteria = null)
|
||||
|
Loading…
Reference in New Issue
Block a user