From 17b9e4722ac42a951f1d5f027fdfef65cf2ac133 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 15 Mar 2023 18:55:30 -0700 Subject: [PATCH] New: Parsing of poorly named absolute number-only files in batches Closes #5488 --- .../AbsoluteEpisodeNumberParserFixture.cs | 14 +++++++++++ src/NzbDrone.Core/Parser/Parser.cs | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/NzbDrone.Core.Test/ParserTests/AbsoluteEpisodeNumberParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/AbsoluteEpisodeNumberParserFixture.cs index 91afc4668..4d5107c92 100644 --- a/src/NzbDrone.Core.Test/ParserTests/AbsoluteEpisodeNumberParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/AbsoluteEpisodeNumberParserFixture.cs @@ -1,7 +1,9 @@ +using System.IO; using System.Linq; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Test.Framework; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.ParserTests { @@ -201,5 +203,17 @@ namespace NzbDrone.Core.Test.ParserTests result.SpecialAbsoluteEpisodeNumbers.Should().BeEquivalentTo(new[] { (decimal)specialEpisodeNumber }); result.FullSeason.Should().BeFalse(); } + + [TestCase("Series Title 921-928 [English Dub][1080p][onepiecedubb]", "921.mkv", "Series Title", 921)] + public void should_handle_ambiguously_named_anime_files_in_batch_release(string releaseName, string filename, string title, int absoluteEpisodeNumber) + { + var result = Parser.Parser.ParsePath(Path.Combine(@"C:\Test".AsOsAgnostic(), releaseName, filename)); + result.Should().NotBeNull(); + result.AbsoluteEpisodeNumbers.Single().Should().Be(absoluteEpisodeNumber); + result.SeasonNumber.Should().Be(0); + result.EpisodeNumbers.Should().BeEmpty(); + result.SeriesTitle.Should().Be(title); + result.FullSeason.Should().BeFalse(); + } } } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index b6133fe9f..d3fedc61e 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -516,6 +516,31 @@ namespace NzbDrone.Core.Parser var result = ParseTitle(fileInfo.Name); + if (result == null && int.TryParse(Path.GetFileNameWithoutExtension(fileInfo.Name), out var number)) + { + Logger.Debug("Attempting to parse episode info using directory and file names. {0}", fileInfo.Directory.Name); + result = ParseTitle(fileInfo.Directory.Name); + + if (result != null && result.AbsoluteEpisodeNumbers.Contains(number)) + { + result.AbsoluteEpisodeNumbers = new[] { number }; + } + else if (result != null && result.EpisodeNumbers.Contains(number)) + { + result.EpisodeNumbers = new[] { number }; + } + else + { + result = null; + } + } + + if (result == null) + { + Logger.Debug("Attempting to parse episode info using combined directory and file names. {0}", fileInfo.Directory.Name); + result = ParseTitle(fileInfo.Directory.Name + " " + fileInfo.Name); + } + if (result == null) { Logger.Debug("Attempting to parse episode info using directory and file names. {0}", fileInfo.Directory.Name);