Fixed: Special title matching when special title has an apostrophe

Closes #2872
This commit is contained in:
Mark McDowall 2019-08-16 21:48:43 -07:00
parent 72bc7ed6d4
commit ec6d407fbb
2 changed files with 34 additions and 7 deletions

View File

@ -93,5 +93,19 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeServiceTests
episode.Should().NotBeNull(); episode.Should().NotBeNull();
episode.Title.Should().Be(expectedTitle); episode.Title.Should().Be(expectedTitle);
} }
[Test]
public void should_handle_special_with_apostrophe_in_title()
{
var releaseTitle = "The.Profit.S06E00.An.Inside.Look-Sweet.Petes.720p.HDTV.";
var title = "An Inside Look- Sweet Petes";
GivenEpisodesWithTitles(title);
var episode = Subject.FindEpisodeByTitle(1, 0, releaseTitle);
episode.Should().NotBeNull();
episode.Title.Should().Be(title);
}
} }
} }

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
@ -108,15 +109,27 @@ namespace NzbDrone.Core.Tv
{ {
// TODO: can replace this search mechanism with something smarter/faster/better // TODO: can replace this search mechanism with something smarter/faster/better
var normalizedReleaseTitle = Parser.Parser.NormalizeEpisodeTitle(releaseTitle); var normalizedReleaseTitle = Parser.Parser.NormalizeEpisodeTitle(releaseTitle);
var cleanNormalizedReleaseTitle = Parser.Parser.CleanSeriesTitle(normalizedReleaseTitle);
var episodes = _episodeRepository.GetEpisodes(seriesId, seasonNumber); var episodes = _episodeRepository.GetEpisodes(seriesId, seasonNumber);
var matches = episodes.Select( var possibleMatches = episodes.SelectMany(
episode => new episode => new[]
{ {
Position = normalizedReleaseTitle.IndexOf(Parser.Parser.NormalizeEpisodeTitle(episode.Title), StringComparison.CurrentCultureIgnoreCase), new
Length = Parser.Parser.NormalizeEpisodeTitle(episode.Title).Length, {
Episode = episode Position = normalizedReleaseTitle.IndexOf(Parser.Parser.NormalizeEpisodeTitle(episode.Title), StringComparison.CurrentCultureIgnoreCase),
}) Length = Parser.Parser.NormalizeEpisodeTitle(episode.Title).Length,
Episode = episode
},
new
{
Position = cleanNormalizedReleaseTitle.IndexOf(Parser.Parser.CleanSeriesTitle(Parser.Parser.NormalizeEpisodeTitle(episode.Title)), StringComparison.CurrentCultureIgnoreCase),
Length = Parser.Parser.NormalizeEpisodeTitle(episode.Title).Length,
Episode = episode
}
});
var matches = possibleMatches
.Where(e => e.Episode.Title.Length > 0 && e.Position >= 0) .Where(e => e.Episode.Title.Length > 0 && e.Position >= 0)
.OrderBy(e => e.Position) .OrderBy(e => e.Position)
.ThenByDescending(e => e.Length) .ThenByDescending(e => e.Length)