1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 07:22:35 +01:00

Use FolderEpisodeInfo instead of parent of FileEpisodeInfo

Fixes #2338
Fixed: Detecting some incorrect file name paring during import
This commit is contained in:
Mark McDowall 2018-06-09 21:42:01 -07:00
parent 783c27a584
commit 8668e8b036
2 changed files with 37 additions and 15 deletions

View File

@ -66,6 +66,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
_localEpisode.FileEpisodeInfo.EpisodeNumbers = new[] { 1 };
_localEpisode.FolderEpisodeInfo.EpisodeNumbers = new[] { 1 };
_localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01E01.720p.HDTV-Sonarr\S01E01.mkv".AsOsAgnostic();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
}
@ -75,22 +76,50 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport.Specifications
_localEpisode.FileEpisodeInfo.EpisodeNumbers = new[] { 1 };
_localEpisode.FolderEpisodeInfo.EpisodeNumbers = new[] { 1 };
_localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01E01E02.720p.HDTV-Sonarr\S01E01.mkv".AsOsAgnostic();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeTrue();
}
[Test]
public void should_be_disregard_subfolder()
{
_localEpisode.FileEpisodeInfo.EpisodeNumbers = new[] { 5, 6 };
_localEpisode.FolderEpisodeInfo.EpisodeNumbers = new[] { 1, 2 };
_localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01E01E02.720p.HDTV-Sonarr\S01E05E06.mkv".AsOsAgnostic();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}
[Test]
public void should_be_rejected_if_file_and_folder_do_not_have_same_episode()
{
_localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01E01.720p.HDTV-Sonarr\S01E05.mkv".AsOsAgnostic();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}
[Test]
public void should_be_rejected_if_file_and_folder_do_not_have_same_episodes()
public void should_be_rejected_if_file_and_folder_do_not_have_the_same_episodes()
{
_localEpisode.FileEpisodeInfo.EpisodeNumbers = new[] { 5, 6 };
_localEpisode.FolderEpisodeInfo.EpisodeNumbers = new[] { 1, 2 };
_localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01E01E02.720p.HDTV-Sonarr\S01E05E06.mkv".AsOsAgnostic();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}
[Test]
public void should_be_rejected_if_file_and_folder_do_not_have_episodes_from_the_same_season()
{
_localEpisode.FileEpisodeInfo.SeasonNumber = 2;
_localEpisode.FileEpisodeInfo.EpisodeNumbers = new[] { 1 };
_localEpisode.FolderEpisodeInfo.FullSeason = true;
_localEpisode.FolderEpisodeInfo.SeasonNumber = 1;
_localEpisode.FolderEpisodeInfo.EpisodeNumbers = new[] { 1, 2 };
_localEpisode.Path = @"C:\Test\Unsorted\Series.Title.S01.720p.HDTV-Sonarr\S02E01.mkv".AsOsAgnostic();
Subject.IsSatisfiedBy(_localEpisode, null).Accepted.Should().BeFalse();
}
}

View File

@ -1,4 +1,3 @@
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Core.DecisionEngine;
@ -25,18 +24,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
return Decision.Accept();
}
var dirInfo = new FileInfo(localEpisode.Path).Directory;
if (dirInfo == null)
{
return Decision.Accept();
}
var fileInfo = localEpisode.FileEpisodeInfo;
var folderInfo = localEpisode.FolderEpisodeInfo;
if (folderInfo != null && folderInfo.IsPossibleSceneSeasonSpecial)
{
folderInfo = _parsingService.ParseSpecialEpisodeTitle(folderInfo, dirInfo.Name, localEpisode.Series.TvdbId, 0);
folderInfo = _parsingService.ParseSpecialEpisodeTitle(folderInfo, folderInfo.ReleaseTitle, localEpisode.Series.TvdbId, 0);
}
if (folderInfo == null)
@ -49,12 +42,12 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
return Decision.Accept();
}
if (folderInfo.FullSeason)
if (folderInfo.SeasonNumber != fileInfo.SeasonNumber)
{
return Decision.Accept();
return Decision.Reject("Season number {0} was unexpected considering the folder name {1}", fileInfo.SeasonNumber, folderInfo.ReleaseTitle);
}
var unexpected = localEpisode.FileEpisodeInfo.EpisodeNumbers.Where(f => !folderInfo.EpisodeNumbers.Contains(f)).ToList();
var unexpected = fileInfo.EpisodeNumbers.Where(f => !folderInfo.EpisodeNumbers.Contains(f)).ToList();
if (unexpected.Any())
{
@ -62,10 +55,10 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications
if (unexpected.Count == 1)
{
return Decision.Reject("Episode Number {0} was unexpected considering the {1} folder name", unexpected.First(), dirInfo.Name);
return Decision.Reject("Episode number {0} was unexpected considering the {1} folder name", unexpected.First(), folderInfo.ReleaseTitle);
}
return Decision.Reject("Episode Numbers {0} were unexpected considering the {1} folder name", string.Join(", ", unexpected), dirInfo.Name);
return Decision.Reject("Episode numbers {0} were unexpected considering the {1} folder name", string.Join(", ", unexpected), folderInfo.ReleaseTitle);
}
return Decision.Accept();