From cc8c88e921515c1aa04ce1c69c861ac889e66387 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 26 Sep 2014 23:28:24 +0200 Subject: [PATCH] Fixed: Extensions are now removed from scene names during import. --- .../ImportApprovedEpisodesFixture.cs | 20 ++++++++++++++----- .../EpisodeImport/ImportApprovedEpisodes.cs | 6 ++++-- src/NzbDrone.Core/Parser/Parser.cs | 3 ++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs index 864569d80..2961a257a 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -70,7 +71,7 @@ namespace NzbDrone.Core.Test.MediaFiles _downloadClientItem = Builder.CreateNew().Build(); } - + [Test] public void should_not_import_any_if_there_are_no_approved_decisions() { @@ -139,7 +140,6 @@ namespace NzbDrone.Core.Test.MediaFiles Times.Never()); } - [Test] public void should_use_nzb_title_as_scene_name() { @@ -150,6 +150,19 @@ namespace NzbDrone.Core.Test.MediaFiles Mocker.GetMock().Verify(v => v.Add(It.Is(c => c.SceneName == _downloadClientItem.Title))); } + [TestCase(".mkv")] + [TestCase(".par2")] + [TestCase(".nzb")] + public void should_remove_extension_from_nzb_title_for_scene_name(String extension) + { + var title = "malcolm.in.the.middle.s02e05.dvdrip.xvid-ingot"; + + _downloadClientItem.Title = title + extension; + + Subject.Import(new List { _approvedDecisions.First() }, true, _downloadClientItem); + + Mocker.GetMock().Verify(v => v.Add(It.Is(c => c.SceneName == title))); + } [Test] public void should_not_use_nzb_title_as_scene_name_if_full_season() @@ -165,7 +178,6 @@ namespace NzbDrone.Core.Test.MediaFiles [Test] public void should_use_file_name_as_scenename_only_if_it_looks_like_scenename() { - _approvedDecisions.First().LocalEpisode.Path = "c:\\tv\\malcolm.in.the.middle.s02e23.dvdrip.xvid-ingot.mkv".AsOsAgnostic(); Subject.Import(new List { _approvedDecisions.First() }, true); @@ -183,8 +195,6 @@ namespace NzbDrone.Core.Test.MediaFiles Mocker.GetMock().Verify(v => v.Add(It.Is(c => c.SceneName == null))); } - - [Test] public void should_import_larger_files_first() { diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index efffd12d2..d30fd8392 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -129,11 +129,13 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport { if (downloadClientItem != null) { - var parsedTitle = Parser.Parser.ParseTitle(downloadClientItem.Title); + var title = Parser.Parser.RemoveFileExtension(downloadClientItem.Title); + + var parsedTitle = Parser.Parser.ParseTitle(title); if (parsedTitle != null && !parsedTitle.FullSeason) { - return downloadClientItem.Title; + return title; } } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 4758171c7..5f2636ba6 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -348,7 +348,8 @@ namespace NzbDrone.Core.Parser { if (!title.ContainsInvalidPathChars()) { - if (MediaFiles.MediaFileExtensions.Extensions.Contains(Path.GetExtension(title).ToLower())) + var extension = Path.GetExtension(title).ToLower(); + if (MediaFiles.MediaFileExtensions.Extensions.Contains(extension) || new [] { ".par2", ".nzb" }.Contains(extension)) { title = Path.Combine(Path.GetDirectoryName(title), Path.GetFileNameWithoutExtension(title)); }