From 40b630ef100aab9bc5409ec22760d4883f739777 Mon Sep 17 00:00:00 2001 From: Gabriel Patzleiner Date: Fri, 10 Apr 2020 14:27:30 +0200 Subject: [PATCH] Fixed: Updated GetSceneName. It will clean the ReleaseTitle now. Added some SceneChecker tests --- .../MediaFiles/ImportApprovedMoviesFixture.cs | 8 ++--- .../ParserTests/ParserFixture.cs | 30 +++++++++---------- .../ParserTests/SceneCheckerFixture.cs | 17 ++++++++--- .../MovieImport/ImportApprovedMovie.cs | 16 ++++------ src/NzbDrone.Core/Parser/Parser.cs | 3 ++ src/NzbDrone.Core/Parser/SceneChecker.cs | 23 ++++++++++---- 6 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs index a2cc6ae20..799db5374 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedMoviesFixture.cs @@ -301,13 +301,13 @@ public void should_include_intermediate_folders_for_download_client_item_with_a_ } [Test] - public void should_use_folder_info_release_title_to_find_relative_path() + public void should_use_folder_info_original_title_to_find_relative_path() { - var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr"; - var outputPath = Path.Combine(@"C:\Test\Unsorted\TV\".AsOsAgnostic(), name); + var name = "Transformers.2007.720p.BluRay.x264-Radarr"; + var outputPath = Path.Combine(@"C:\Test\Unsorted\movies\".AsOsAgnostic(), name); var localEpisode = _approvedDecisions.First().LocalMovie; - localEpisode.FolderMovieInfo = new ParsedMovieInfo { SimpleReleaseTitle = name }; + localEpisode.FolderMovieInfo = new ParsedMovieInfo { OriginalTitle = name }; localEpisode.Path = Path.Combine(outputPath, "subfolder", name + ".mkv"); Subject.Import(new List { _approvedDecisions.First() }, true, null); diff --git a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs index 00c76beca..96e73f4cb 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs @@ -33,7 +33,6 @@ public void should_remove_accents_from_title() title.CleanSeriesTitle().Should().Be("carnivale"); } - //Note: This assumes extended language parser is activated [TestCase("The.Man.from.U.N.C.L.E.2015.1080p.BluRay.x264-SPARKS", "The Man from U.N.C.L.E.")] [TestCase("1941.1979.EXTENDED.720p.BluRay.X264-AMIABLE", "1941")] [TestCase("MY MOVIE (2016) [R][Action, Horror][720p.WEB-DL.AVC.8Bit.6ch.AC3].mkv", "MY MOVIE")] @@ -74,26 +73,27 @@ public void should_parse_movie_title(string postTitle, string title) [TestCase("96.Hours.Taken.3.EXTENDED.2014.German.DL.1080p.BluRay.x264-ENCOUNTERS", "96 Hours Taken 3", "EXTENDED", 2014)] [TestCase("World.War.Z.EXTENDED.CUT.2013.German.DL.1080p.BluRay.x264-HQX", "World War Z", "EXTENDED CUT", 2013)] [TestCase("Sin.City.2005.RECUT.EXTENDED.German.DL.1080p.BluRay.x264-DETAiLS", "Sin City", "RECUT EXTENDED", 2005)] - [TestCase("Die.Klasse.von.1999.1990.German.720p.HDTV.x264-NORETAiL", "Die Klasse von 1999", "", 1990)] //year in the title [TestCase("2.Tage.in.L.A.1996.GERMAN.DL.720p.WEB.H264-SOV", "2 Tage in L.A.", "", 1996)] [TestCase("8.2019.GERMAN.720p.BluRay.x264-UNiVERSUM", "8", "", 2019)] [TestCase("Life.Partners.2014.German.DL.PAL.DVDR-ETM", "Life Partners", "", 2014)] [TestCase("Joe.Dreck.2.EXTENDED.EDITION.2015.German.DL.PAL.DVDR-ETM", "Joe Dreck 2", "EXTENDED EDITION", 2015)] [TestCase("Rango.EXTENDED.2011.HDRip.AC3.German.XviD-POE", "Rango", "EXTENDED", 2011)] - //Special cases (see comment to the right) - [TestCase("Suicide.Squad.2016.EXTENDED.German.DL.AC3.BDRip.x264-hqc", "Suicide Squad", "EXTENDED", 2016)] //edition after year - [TestCase("Knight.and.Day.2010.Extended.Cut.German.DTS.DL.720p.BluRay.x264-HDS", "Knight and Day", "Extended Cut", 2010)] //edition after year - [TestCase("Der.Soldat.James.German.Bluray.FuckYou.Pso.Why.cant.you.follow.scene.rules.1998", "Der Soldat James", "", 1998)] //year at the end - [TestCase("Der.Hobbit.Eine.Unerwartete.Reise.Extended.German.720p.BluRay.x264-EXQUiSiTE", "Der Hobbit Eine Unerwartete Reise", "Extended", 0)] //no year - [TestCase("Wolverine.Weg.des.Kriegers.EXTENDED.German.720p.BluRay.x264-EXQUiSiTE", "Wolverine Weg des Kriegers", "EXTENDED", 0)] //no year - [TestCase("Die.Unfassbaren.Now.You.See.Me.EXTENDED.German.DTS.720p.BluRay.x264-RHD", "Die Unfassbaren Now You See Me", "EXTENDED", 0)] //no year - [TestCase("Die Unfassbaren Now You See Me EXTENDED German DTS 720p BluRay x264-RHD", "Die Unfassbaren Now You See Me", "EXTENDED", 0)] //no year & without dots - [TestCase("Passengers.German.DL.AC3.Dubbed..BluRay.x264-PsO", "Passengers", "", 0)] //no year - [TestCase("Das.A.Team.Der.Film.Extended.Cut.German.720p.BluRay.x264-ANCIENT", "Das A Team Der Film", "Extended Cut", 0)] //no year - [TestCase("Cars.2.German.DL.720p.BluRay.x264-EmpireHD", "Cars 2", "", 0)] //no year - [TestCase("Die.fantastische.Reise.des.Dr.Dolittle.2020.German.DL.LD.1080p.WEBRip.x264-PRD", "Die fantastische Reise des Dr. Dolittle", "", 2020)] //year at wrong position - [TestCase("Der.Film.deines.Lebens.German.2011.PAL.DVDR-ETM", "Der Film deines Lebens", "", 2011)] //year at wrong position + //Special cases (see description) + [TestCase("Die.Klasse.von.1999.1990.German.720p.HDTV.x264-NORETAiL", "Die Klasse von 1999", "", 1990, Description = "year in the title")] + [TestCase("Suicide.Squad.2016.EXTENDED.German.DL.AC3.BDRip.x264-hqc", "Suicide Squad", "EXTENDED", 2016, Description = "edition after year")] + [TestCase("Knight.and.Day.2010.Extended.Cut.German.DTS.DL.720p.BluRay.x264-HDS", "Knight and Day", "Extended Cut", 2010, Description = "edition after year")] + [TestCase("Der.Soldat.James.German.Bluray.FuckYou.Pso.Why.cant.you.follow.scene.rules.1998", "Der Soldat James", "", 1998, Description = "year at the end")] + [TestCase("Der.Hobbit.Eine.Unerwartete.Reise.Extended.German.720p.BluRay.x264-EXQUiSiTE", "Der Hobbit Eine Unerwartete Reise", "Extended", 0, Description = "no year & edition")] + [TestCase("Wolverine.Weg.des.Kriegers.EXTENDED.German.720p.BluRay.x264-EXQUiSiTE", "Wolverine Weg des Kriegers", "EXTENDED", 0, Description = "no year & edition")] + [TestCase("Die.Unfassbaren.Now.You.See.Me.EXTENDED.German.DTS.720p.BluRay.x264-RHD", "Die Unfassbaren Now You See Me", "EXTENDED", 0, Description = "no year & edition")] + [TestCase("Die Unfassbaren Now You See Me EXTENDED German DTS 720p BluRay x264-RHD", "Die Unfassbaren Now You See Me", "EXTENDED", 0, Description = "no year & edition & without dots")] + [TestCase("Passengers.German.DL.AC3.Dubbed..BluRay.x264-PsO", "Passengers", "", 0, Description = "no year")] + [TestCase("Das.A.Team.Der.Film.Extended.Cut.German.720p.BluRay.x264-ANCIENT", "Das A Team Der Film", "Extended Cut", 0, Description = "no year")] + [TestCase("Cars.2.German.DL.720p.BluRay.x264-EmpireHD", "Cars 2", "", 0, Description = "no year")] + [TestCase("Die.fantastische.Reise.des.Dr.Dolittle.2020.German.DL.LD.1080p.WEBRip.x264-PRD", "Die fantastische Reise des Dr. Dolittle", "", 2020, Description = "dot after dr")] + [TestCase("Der.Film.deines.Lebens.German.2011.PAL.DVDR-ETM", "Der Film deines Lebens", "", 2011, Description = "year at wrong position")] + [TestCase("Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate_", "Kick Ass 2", "", 2013, Description = "underscore at the end")] public void should_parse_german_movie(string postTitle, string title, string edition, int year) { ParsedMovieInfo movie = Parser.Parser.ParseMovieTitle(postTitle); diff --git a/src/NzbDrone.Core.Test/ParserTests/SceneCheckerFixture.cs b/src/NzbDrone.Core.Test/ParserTests/SceneCheckerFixture.cs index 0162c3b81..36943382f 100644 --- a/src/NzbDrone.Core.Test/ParserTests/SceneCheckerFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/SceneCheckerFixture.cs @@ -12,6 +12,7 @@ public class SceneCheckerFixture //[TestCase("Archer.2009.720p.WEB-DL.DD5.1.H.264-iT00NZ")] //[TestCase("30.Rock.S04E17.720p.HDTV.X264-DIMENSION")] //[TestCase("30.Rock.S04.720p.HDTV.X264-DIMENSION")] + [TestCase("Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate")] public void should_return_true_for_scene_names(string title) { SceneChecker.IsSceneTitle(title).Should().BeTrue(); @@ -21,13 +22,21 @@ public void should_return_true_for_scene_names(string title) [TestCase("S08E05 - Virtual In-Stanity.With.Dots [WEBDL-720p]")] [TestCase("Something")] [TestCase("86de66b7ef385e2fa56a3e41b98481ea1658bfab")] - [TestCase("30.Rock.2017.720p.HDTV.X264", Description = "no group")] - [TestCase("2017.720p.HDTV.X264-DIMENSION", Description = "no series title")] - [TestCase("30.Rock.2017-DIMENSION", Description = "no quality")] - [TestCase("30.Rock.720p.HDTV.X264-DIMENSION", Description = "no episode")] + [TestCase("Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-", Description = "no group")] + [TestCase("Kick.Ass.2.2013.German.DTS.DL-Pate", Description = "no quality")] + [TestCase("2013.German.DTS.DL.BluRay.x264-Pate", Description = "no movietitle")] public void should_return_false_for_non_scene_names(string title) { SceneChecker.IsSceneTitle(title).Should().BeFalse(); } + + [TestCase("Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate_", "Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate", Description = "underscore at the end")] + [TestCase("Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate.mkv", "Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate", Description = "file extension")] + [TestCase("Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate.nzb", "Kick.Ass.2.2013.German.DTS.DL.720p.BluRay.x264-Pate", Description = "file extension")] + [TestCase("Kick.Ass.2.2013.German.DTS.DL.怐720p怑.BluRay.x264-Pate.nzb", "Kick.Ass.2.2013.German.DTS.DL.[720p].BluRay.x264-Pate", Description = "brackets")] + public void should_correctly_parse_scene_names(string title, string result) + { + SceneChecker.GetSceneTitle(title).Should().Be(result); + } } } diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs index 17464473b..e511fde8a 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/ImportApprovedMovie.cs @@ -120,7 +120,6 @@ public List Import(List decisions, bool newDownloa { movieFile.OriginalFilePath = GetOriginalFilePath(downloadClientItem, localMovie); movieFile.SceneName = GetSceneName(downloadClientItem, localMovie); - var moveResult = _movieFileUpgrader.UpgradeMovieFile(movieFile, localMovie, copyOnly); //TODO: Check if this works oldFiles = moveResult.OldFiles; } @@ -212,21 +211,18 @@ private string GetSceneName(DownloadClientItem downloadClientItem, LocalMovie lo { if (downloadClientItem != null) { - var title = Parser.Parser.RemoveFileExtension(downloadClientItem.Title); - - var parsedTitle = Parser.Parser.ParseMovieTitle(title); - - if (parsedTitle != null) + var sceneNameTitle = SceneChecker.GetSceneTitle(downloadClientItem.Title); + if (sceneNameTitle != null) { - return title; + return sceneNameTitle; } } var fileName = Path.GetFileNameWithoutExtension(localMovie.Path.CleanFilePath()); - - if (SceneChecker.IsSceneTitle(fileName)) + var sceneNameFile = SceneChecker.GetSceneTitle(fileName); + if (sceneNameFile != null) { - return fileName; + return sceneNameFile; } return null; diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 0cd4b97ee..2e3fb70f0 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -187,6 +187,9 @@ public static ParsedMovieInfo ParseMovieTitle(string title, bool isDir = false) var releaseTitle = RemoveFileExtension(title); + //Trim dashes from end + releaseTitle = releaseTitle.Trim('-', '_'); + releaseTitle = releaseTitle.Replace("怐", "[").Replace("怑", "]"); var simpleTitle = SimpleTitleRegex.Replace(releaseTitle); diff --git a/src/NzbDrone.Core/Parser/SceneChecker.cs b/src/NzbDrone.Core/Parser/SceneChecker.cs index e23e17345..9b6403829 100644 --- a/src/NzbDrone.Core/Parser/SceneChecker.cs +++ b/src/NzbDrone.Core/Parser/SceneChecker.cs @@ -4,16 +4,21 @@ public static class SceneChecker { //This method should prefer false negatives over false positives. //It's better not to use a title that might be scene than to use one that isn't scene - public static bool IsSceneTitle(string title) + public static string GetSceneTitle(string title) { + if (title == null) + { + return null; + } + if (!title.Contains(".")) { - return false; + return null; } if (title.Contains(" ")) { - return false; + return null; } var parsedTitle = Parser.ParseMovieTitle(title); @@ -21,12 +26,18 @@ public static bool IsSceneTitle(string title) if (parsedTitle == null || parsedTitle.ReleaseGroup == null || parsedTitle.Quality.Quality == Qualities.Quality.Unknown || - string.IsNullOrWhiteSpace(parsedTitle.MovieTitle)) + string.IsNullOrWhiteSpace(parsedTitle.MovieTitle) || + string.IsNullOrWhiteSpace(parsedTitle.ReleaseTitle)) { - return false; + return null; } - return true; + return parsedTitle.ReleaseTitle; + } + + public static bool IsSceneTitle(string title) + { + return GetSceneTitle(title) != null; } } }