From ff9a9a5e4d4a05fad0883e6e3b14220ce6fb4436 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 27 Aug 2018 21:35:03 -0700 Subject: [PATCH] More restrictions when using download client title or folder name for parsing Fixes #2663 --- .../Aggregators/AggregateEpisodesFixture.cs | 19 +++++++++++++++ .../Aggregators/AggregateEpisodes.cs | 24 +++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodesFixture.cs index 45d24727a..2ba2d3a0c 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodesFixture.cs @@ -105,5 +105,24 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Aggregation.Aggregators Mocker.GetMock() .Verify(v => v.GetEpisodes(folderEpisodeInfo, _series, localEpisode.SceneSource, null), Times.Once()); } + + [Test] + public void should_use_file_when_folder_is_absolute_and_file_is_not() + { + var fileEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.S01E01"); + var folderEpisodeInfo = Parser.Parser.ParseTitle("Series.Title.01"); + var localEpisode = new LocalEpisode + { + FileEpisodeInfo = fileEpisodeInfo, + FolderEpisodeInfo = folderEpisodeInfo, + Path = @"C:\Test\Unsorted TV\Series.Title.101\Series.Title.S01E01.mkv".AsOsAgnostic(), + Series = _series + }; + + Subject.Aggregate(localEpisode, false); + + Mocker.GetMock() + .Verify(v => v.GetEpisodes(fileEpisodeInfo, _series, localEpisode.SceneSource, null), Times.Once()); + } } } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodes.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodes.cs index cb624d452..01ae38ed3 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodes.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Aggregation/Aggregators/AggregateEpisodes.cs @@ -30,11 +30,15 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators if (!otherFiles && !SceneChecker.IsSceneTitle(Path.GetFileNameWithoutExtension(localEpisode.Path))) { - if (downloadClientEpisodeInfo != null && !downloadClientEpisodeInfo.FullSeason) + if (downloadClientEpisodeInfo != null && + !downloadClientEpisodeInfo.FullSeason && + PreferOtherEpisodeInfo(parsedEpisodeInfo, downloadClientEpisodeInfo)) { parsedEpisodeInfo = localEpisode.DownloadClientEpisodeInfo; } - else if (folderEpisodeInfo != null && !folderEpisodeInfo.FullSeason) + else if (folderEpisodeInfo != null && + !folderEpisodeInfo.FullSeason && + PreferOtherEpisodeInfo(parsedEpisodeInfo, folderEpisodeInfo)) { parsedEpisodeInfo = localEpisode.FolderEpisodeInfo; } @@ -68,5 +72,21 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Aggregation.Aggregators return new List(); } + + private bool PreferOtherEpisodeInfo(ParsedEpisodeInfo fileEpisodeInfo, ParsedEpisodeInfo otherEpisodeInfo) + { + if (fileEpisodeInfo == null) + { + return true; + } + + // When the files episode info is not absolute prefer it over a parsed episode info that is absolute + if (!fileEpisodeInfo.IsAbsoluteNumbering && otherEpisodeInfo.IsAbsoluteNumbering) + { + return false; + } + + return true; + } } }