Movies with Umlauts are now correctly matched and have correct CleanTitles.

An update library is recommended. Fixes #1338
Leonardo Galli 8 years ago
parent 475851775f
commit 10091b9454

@ -23,6 +23,8 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
private ParsedMovieInfo _wrongYearInfo; private ParsedMovieInfo _wrongYearInfo;
private ParsedMovieInfo _romanTitleInfo; private ParsedMovieInfo _romanTitleInfo;
private ParsedMovieInfo _alternativeTitleInfo; private ParsedMovieInfo _alternativeTitleInfo;
private ParsedMovieInfo _umlautInfo;
private ParsedMovieInfo _umlautAltInfo;
private MovieSearchCriteria _movieSearchCriteria; private MovieSearchCriteria _movieSearchCriteria;
private List<Episode> _episodes; private List<Episode> _episodes;
private ParsedEpisodeInfo _parsedEpisodeInfo; private ParsedEpisodeInfo _parsedEpisodeInfo;
@ -37,10 +39,10 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
.Build(); .Build();
_movie = Builder<Movie>.CreateNew() _movie = Builder<Movie>.CreateNew()
.With(m => m.Title = "Mission Impossible 3") .With(m => m.Title = "Fack Ju Göthe 2")
.With(m => m.CleanTitle = "missionimpossible3") .With(m => m.CleanTitle = "fackjugoethe2")
.With(m => m.Year = 2006) .With(m => m.Year = 2015)
.With(m => m.AlternativeTitles = new List<string> { "Mission Impossible 3: Same same" }) .With(m => m.AlternativeTitles = new List<string> { "Fack Ju Göthe 2: Same same" })
.Build(); .Build();
_episodes = Builder<Episode>.CreateListOfSize(1) _episodes = Builder<Episode>.CreateListOfSize(1)
@ -77,10 +79,22 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
_romanTitleInfo = new ParsedMovieInfo _romanTitleInfo = new ParsedMovieInfo
{ {
MovieTitle = "Mission Impossible III", MovieTitle = "Fack Ju Göthe II",
Year = _movie.Year, Year = _movie.Year,
}; };
_umlautInfo = new ParsedMovieInfo
{
MovieTitle = "Fack Ju Goethe 2",
Year = _movie.Year
};
_umlautAltInfo = new ParsedMovieInfo
{
MovieTitle = "Fack Ju Goethe 2: Same same",
Year = _movie.Year
};
_singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria _singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria
{ {
Series = _series, Series = _series,
@ -148,5 +162,12 @@ namespace NzbDrone.Core.Test.ParserTests.ParsingServiceTests
Subject.Map(_romanTitleInfo, "", _movieSearchCriteria).Movie.Should().Be(_movieSearchCriteria.Movie); Subject.Map(_romanTitleInfo, "", _movieSearchCriteria).Movie.Should().Be(_movieSearchCriteria.Movie);
} }
[Test]
public void should_match_umlauts()
{
Subject.Map(_umlautInfo, "", _movieSearchCriteria).Movie.Should().Be(_movieSearchCriteria.Movie);
Subject.Map(_umlautAltInfo, "", _movieSearchCriteria).Movie.Should().Be(_movieSearchCriteria.Movie);
}
} }
} }

@ -1275,6 +1275,7 @@
<Compile Include="Datastore\Migration\131_make_parsed_episode_info_nullable.cs" /> <Compile Include="Datastore\Migration\131_make_parsed_episode_info_nullable.cs" />
<Compile Include="Housekeeping\Housekeepers\FixWronglyMatchedMovieFiles.cs" /> <Compile Include="Housekeeping\Housekeepers\FixWronglyMatchedMovieFiles.cs" />
<Compile Include="Datastore\Migration\135_add_haspredbentry_to_movies.cs" /> <Compile Include="Datastore\Migration\135_add_haspredbentry_to_movies.cs" />
<Compile Include="Tv\QueryExtensions.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client"> <BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

@ -310,6 +310,12 @@ namespace NzbDrone.Core.Parser
private static readonly Regex RequestInfoRegex = new Regex(@"\[.+?\]", RegexOptions.Compiled); private static readonly Regex RequestInfoRegex = new Regex(@"\[.+?\]", RegexOptions.Compiled);
private static readonly string[] Numbers = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; private static readonly string[] Numbers = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
private static Dictionary<String, String> _umlautMappings = new Dictionary<string, string>
{
{"ö", "oe"},
{"ä", "ae"},
{"ü", "ue"},
};
public static ParsedEpisodeInfo ParsePath(string path) public static ParsedEpisodeInfo ParsePath(string path)
{ {
@ -660,7 +666,7 @@ namespace NzbDrone.Core.Parser
if (long.TryParse(title, out number)) if (long.TryParse(title, out number))
return title; return title;
return NormalizeRegex.Replace(title, string.Empty).ToLower().RemoveAccent(); return ReplaceGermanUmlauts(NormalizeRegex.Replace(title, string.Empty).ToLower()).RemoveAccent();
} }
public static string NormalizeEpisodeTitle(string title) public static string NormalizeEpisodeTitle(string title)

@ -36,6 +36,7 @@ namespace NzbDrone.Core.Parser
private readonly IMovieService _movieService; private readonly IMovieService _movieService;
private readonly Logger _logger; private readonly Logger _logger;
private static HashSet<ArabicRomanNumeral> _arabicRomanNumeralMappings; private static HashSet<ArabicRomanNumeral> _arabicRomanNumeralMappings;
public ParsingService(IEpisodeService episodeService, public ParsingService(IEpisodeService episodeService,
ISeriesService seriesService, ISeriesService seriesService,
@ -412,7 +413,7 @@ namespace NzbDrone.Core.Parser
return false; return false;
} }
private static bool TryGetMovieBySearchCriteria(ParsedMovieInfo parsedMovieInfo, SearchCriteriaBase searchCriteria, out Movie possibleMovie) private bool TryGetMovieBySearchCriteria(ParsedMovieInfo parsedMovieInfo, SearchCriteriaBase searchCriteria, out Movie possibleMovie)
{ {
possibleMovie = null; possibleMovie = null;
List<string> possibleTitles = new List<string>(); List<string> possibleTitles = new List<string>();
@ -424,6 +425,8 @@ namespace NzbDrone.Core.Parser
possibleTitles.Add(altTitle.CleanSeriesTitle()); possibleTitles.Add(altTitle.CleanSeriesTitle());
} }
string cleanTitle = parsedMovieInfo.MovieTitle.CleanSeriesTitle();
foreach (string title in possibleTitles) foreach (string title in possibleTitles)
{ {
if (title == parsedMovieInfo.MovieTitle.CleanSeriesTitle()) if (title == parsedMovieInfo.MovieTitle.CleanSeriesTitle())
@ -436,12 +439,14 @@ namespace NzbDrone.Core.Parser
string arabicNumeral = numeralMapping.ArabicNumeralAsString; string arabicNumeral = numeralMapping.ArabicNumeralAsString;
string romanNumeral = numeralMapping.RomanNumeralLowerCase; string romanNumeral = numeralMapping.RomanNumeralLowerCase;
_logger.Debug(cleanTitle);
if (title.Replace(arabicNumeral, romanNumeral) == parsedMovieInfo.MovieTitle.CleanSeriesTitle()) if (title.Replace(arabicNumeral, romanNumeral) == parsedMovieInfo.MovieTitle.CleanSeriesTitle())
{ {
possibleMovie = searchCriteria.Movie; possibleMovie = searchCriteria.Movie;
} }
if (title.Replace(romanNumeral, arabicNumeral) == parsedMovieInfo.MovieTitle.CleanSeriesTitle()) if (title == parsedMovieInfo.MovieTitle.CleanSeriesTitle().Replace(arabicNumeral, romanNumeral))
{ {
possibleMovie = searchCriteria.Movie; possibleMovie = searchCriteria.Movie;
} }

@ -238,35 +238,25 @@ namespace NzbDrone.Core.Tv
cleanTitleWithArabicNumbers = cleanTitleWithArabicNumbers.Replace(romanNumber, arabicNumber); cleanTitleWithArabicNumbers = cleanTitleWithArabicNumbers.Replace(romanNumber, arabicNumber);
} }
Movie result = year.HasValue Movie result = Query.Where(s => s.CleanTitle == cleanTitle).FirstWithYear(year);
? Query.Where(s => s.CleanTitle == cleanTitle).FirstOrDefault(movie => movie.Year == year.Value)
: Query.Where(s => s.CleanTitle == cleanTitle).FirstOrDefault();
if (result == null) if (result == null)
{ {
result = year.HasValue ? Query.Where(movie => movie.CleanTitle == cleanTitleWithArabicNumbers).FirstOrDefault(movie => movie.Year == year.Value) result = Query.Where(movie => movie.CleanTitle == cleanTitleWithArabicNumbers).FirstWithYear(year) ??
: Query.Where(movie => movie.CleanTitle == cleanTitleWithArabicNumbers).FirstOrDefault(); ; Query.Where(movie => movie.CleanTitle == cleanTitleWithRomanNumbers).FirstWithYear(year);
if (result == null) if (result == null)
{ {
result = year.HasValue ? Query.Where(movie => movie.CleanTitle == cleanTitleWithRomanNumbers).FirstOrDefault(movie => movie.Year == year.Value) IEnumerable<Movie> movies = All();
: Query.Where(movie => movie.CleanTitle == cleanTitleWithRomanNumbers).FirstOrDefault(); Func<string, string> titleCleaner = title => CoreParser.CleanSeriesTitle(title.ToLower());
Func<IEnumerable<string>, string, bool> altTitleComparer =
if (result == null) (alternativeTitles, atitle) =>
{ alternativeTitles.Any(altTitle => titleCleaner(altTitle) == atitle);
IEnumerable<Movie> movies = All();
Func<string, string> titleCleaner = title => CoreParser.CleanSeriesTitle(title.ToLower()); result = movies.Where(m => altTitleComparer(m.AlternativeTitles, cleanTitle) ||
Func<IEnumerable<string>, string, bool> altTitleComparer = altTitleComparer(m.AlternativeTitles, cleanTitleWithRomanNumbers) ||
(alternativeTitles, atitle) => altTitleComparer(m.AlternativeTitles, cleanTitleWithArabicNumbers)).FirstWithYear(year);
alternativeTitles.Any(altTitle => titleCleaner(altTitle) == atitle);
result = year.HasValue ? movies.Where(m => altTitleComparer(m.AlternativeTitles, cleanTitle) ||
altTitleComparer(m.AlternativeTitles, cleanTitleWithRomanNumbers) ||
altTitleComparer(m.AlternativeTitles, cleanTitleWithArabicNumbers)).FirstOrDefault(movie => movie.Year == year)
: movies.Where(m => altTitleComparer(m.AlternativeTitles, cleanTitle) ||
altTitleComparer(m.AlternativeTitles, cleanTitleWithRomanNumbers) ||
altTitleComparer(m.AlternativeTitles, cleanTitleWithArabicNumbers)).FirstOrDefault();
}
} }
} }
return result; return result;

@ -53,6 +53,7 @@ namespace NzbDrone.Core.Tv
private readonly IBuildFileNames _fileNameBuilder; private readonly IBuildFileNames _fileNameBuilder;
private readonly Logger _logger; private readonly Logger _logger;
public MovieService(IMovieRepository movieRepository, public MovieService(IMovieRepository movieRepository,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
ISceneMappingService sceneMappingService, ISceneMappingService sceneMappingService,

@ -0,0 +1,30 @@
using System;
using System.Linq;
using System.Collections.Generic;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Datastore.Extensions;
using Marr.Data.QGen;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Parser.RomanNumerals;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using CoreParser = NzbDrone.Core.Parser.Parser;
namespace NzbDrone.Core
{
public static class QueryExtensions
{
public static Movie FirstWithYear(this SortBuilder<Movie> query, int? year)
{
return year.HasValue ? query.FirstOrDefault(movie => movie.Year == year) : query.FirstOrDefault();
}
}
public static class EnumerableExtensions
{
public static Movie FirstWithYear(this IEnumerable<Movie> query, int? year)
{
return year.HasValue ? query.FirstOrDefault(movie => movie.Year == year) : query.FirstOrDefault();
}
}
}
Loading…
Cancel
Save