1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-23 08:15:27 +00:00

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