diff --git a/API.Tests/Parser/ComicParserTests.cs b/API.Tests/Parser/ComicParserTests.cs index d1d8209e7..3e74782d2 100644 --- a/API.Tests/Parser/ComicParserTests.cs +++ b/API.Tests/Parser/ComicParserTests.cs @@ -1,4 +1,4 @@ -using Xunit; +using Xunit; namespace API.Tests.Parser { @@ -30,6 +30,12 @@ namespace API.Tests.Parser [InlineData("Saga 001 (2012) (Digital) (Empire-Zone).cbr", "Saga")] [InlineData("spawn-123", "spawn")] [InlineData("Batman Beyond 04 (of 6) (1999)", "Batman Beyond")] + [InlineData("Batman Beyond 001 (2012)", "Batman Beyond")] + [InlineData("Batman Beyond 2.0 001 (2013)", "Batman Beyond 2.0")] + [InlineData("Batman - Catwoman 001 (2021) (Webrip) (The Last Kryptonian-DCP)", "Batman - Catwoman")] + [InlineData("Chew v1 - Taster´s Choise (2012) (Digital) (1920) (Kingpin-Empire)", "Chew")] + [InlineData("Chew Script Book (2011) (digital-Empire) SP04", "Chew Script Book")] + [InlineData("Batman - Detective Comics - Rebirth Deluxe Edition Book 02 (2018) (digital) (Son of Ultron-Empire)", "Batman - Detective Comics - Rebirth Deluxe Edition Book")] public void ParseComicSeriesTest(string filename, string expected) { Assert.Equal(expected, API.Parser.Parser.ParseComicSeries(filename)); @@ -54,6 +60,12 @@ namespace API.Tests.Parser [InlineData("Invincible 033.5 - Marvel Team-Up 14 (2006) (digital) (Minutemen-Slayer)", "0")] [InlineData("Cyberpunk 2077 - Trauma Team 04.cbz", "0")] [InlineData("spawn-123", "0")] + [InlineData("Batman Beyond 04 (of 6) (1999)", "0")] + [InlineData("Batman Beyond 001 (2012)", "0")] + [InlineData("Batman Beyond 2.0 001 (2013)", "0")] + [InlineData("Batman - Catwoman 001 (2021) (Webrip) (The Last Kryptonian-DCP)", "0")] + [InlineData("Chew v1 - Taster´s Choise (2012) (Digital) (1920) (Kingpin-Empire)", "1")] + [InlineData("Chew Script Book (2011) (digital-Empire) SP04", "0")] public void ParseComicVolumeTest(string filename, string expected) { Assert.Equal(expected, API.Parser.Parser.ParseComicVolume(filename)); @@ -83,9 +95,23 @@ namespace API.Tests.Parser [InlineData("Batman Beyond 04 (of 6) (1999)", "4")] [InlineData("Invincible 052 (c2c) (2008) (Minutemen-TheCouple)", "52")] [InlineData("Y - The Last Man #001", "1")] + [InlineData("Batman Beyond 001 (2012)", "1")] + [InlineData("Batman Beyond 2.0 001 (2013)", "1")] + [InlineData("Batman - Catwoman 001 (2021) (Webrip) (The Last Kryptonian-DCP)", "1")] + [InlineData("Chew v1 - Taster´s Choise (2012) (Digital) (1920) (Kingpin-Empire)", "0")] + [InlineData("Chew Script Book (2011) (digital-Empire) SP04", "0")] public void ParseComicChapterTest(string filename, string expected) { Assert.Equal(expected, API.Parser.Parser.ParseComicChapter(filename)); } + + + [Theory] + [InlineData("Batman - Detective Comics - Rebirth Deluxe Edition Book 02 (2018) (digital) (Son of Ultron-Empire)", true)] + public void ParseComcSpecialTest(string input, bool expected) + { + Assert.Equal(expected, !string.IsNullOrEmpty(API.Parser.Parser.ParseComicSpecial(input))); + } + } } diff --git a/API.Tests/Parser/ParserTest.cs b/API.Tests/Parser/ParserTest.cs index 6660ba2af..3a8b7ba6a 100644 --- a/API.Tests/Parser/ParserTest.cs +++ b/API.Tests/Parser/ParserTest.cs @@ -11,6 +11,7 @@ namespace API.Tests.Parser [InlineData("Beastars SP01", true)] [InlineData("Beastars Special 01", false)] [InlineData("Beastars Extra 01", false)] + [InlineData("Batman Beyond - Return of the Joker (2001) SP01", true)] public void HasSpecialTest(string input, bool expected) { Assert.Equal(expected, HasSpecialMarker(input)); @@ -40,6 +41,7 @@ namespace API.Tests.Parser [InlineData("[ReleaseGroup] The Title", "The Title")] [InlineData("[ReleaseGroup]_The_Title", "The Title")] [InlineData("[Suihei Kiki]_Kasumi_Otoko_no_Ko_[Taruby]_v1.1", "Kasumi Otoko no Ko v1.1")] + [InlineData("Batman - Detective Comics - Rebirth Deluxe Edition Book 04 (2019) (digital) (Son of Ultron-Empire)", "Batman - Detective Comics - Rebirth Deluxe Edition")] public void CleanTitleTest(string input, string expected) { Assert.Equal(expected, CleanTitle(input)); diff --git a/API/Parser/Parser.cs b/API/Parser/Parser.cs index d1169d71c..25f6c889e 100644 --- a/API/Parser/Parser.cs +++ b/API/Parser/Parser.cs @@ -272,6 +272,11 @@ namespace API.Parser @"(?.*)(\b|_)(vol\.?)( |_)(?\d+(-\d+)?)", MatchOptions, RegexTimeout), + // Batman Beyond 2.0 001 (2013) + new Regex( + @"^(?.+?\S\.\d) (?\d+)", + MatchOptions, + RegexTimeout), // 04 - Asterix the Gladiator (1964) (Digital-Empire) (WebP by Doc MaKS) new Regex( @"^(?\d+) (- |_)?(?.*(\d{4})?)( |_)(\(|\d+)", @@ -341,44 +346,11 @@ namespace API.Parser private static readonly Regex[] ComicVolumeRegex = new[] { - // // 04 - Asterix the Gladiator (1964) (Digital-Empire) (WebP by Doc MaKS) - // new Regex( - // @"^(?\d+) (- |_)?(?.*(\d{4})?)( |_)(\(|\d+)", - // MatchOptions, - // RegexTimeout), - // // 01 Spider-Man & Wolverine 01.cbr - // new Regex( - // @"^(?\d+) (?:- )?(?.*) (\d+)?", - // MatchOptions, - // RegexTimeout), - // // Batman & Wildcat (1 of 3) - // new Regex( - // @"(?.*(\d{4})?)( |_)(?:\((?\d+) of \d+)", - // MatchOptions, - // RegexTimeout), // Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus) new Regex( @"^(?.*)(?: |_)v(?\d+)", MatchOptions, RegexTimeout), - // Scott Pilgrim 02 - Scott Pilgrim vs. The World (2005) - // BUG: Negative lookbehind has to be fixed width - // NOTE: The case this is built for does not make much sense. - // new Regex( - // @"^(?.+?)(?\d+)", - // MatchOptions, - // RegexTimeout), - - // Batman & Catwoman - Trail of the Gun 01, Batman & Grendel (1996) 01 - Devil's Bones, Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus) - // new Regex( - // @"^(?.+?)(?\d+))", - // MatchOptions, - // RegexTimeout), - // // Batman & Robin the Teen Wonder #0 - // new Regex( - // @"^(?.*)(?: |_)#(?\d+)", - // MatchOptions, - // RegexTimeout), }; private static readonly Regex[] ComicChapterRegex = new[] @@ -393,6 +365,11 @@ namespace API.Parser @"(?.+?)(?\d+)(\s|_|-)?\(of", MatchOptions, RegexTimeout), + // Batman Beyond 2.0 001 (2013) + new Regex( + @"^(?.+?\S\.\d) (?\d+)", + MatchOptions, + RegexTimeout), // Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus) new Regex( @"^(?.+?)(?: |_)v(?\d+)(?: |_)(c? ?)(?(\d+(\.\d)?)-?(\d+(\.\d)?)?)(c? ?)", @@ -551,6 +528,15 @@ namespace API.Parser RegexTimeout), }; + private static readonly Regex[] ComicSpecialRegex = + { + // All Keywords, does not account for checking if contains volume/chapter identification. Parser.Parse() will handle. + new Regex( + @"(?Specials?|OneShot|One\-Shot|Omake|Extra( Chapter)?|Book \d.+?|Compendium \d.+?|Omnibus \d.+?|TPB \d.+?|FCBD \d.+?|Absolute \d.+?|Preview \d.+?|Art Collection|Side( |_)Stories|Bonus)", + MatchOptions, + RegexTimeout), + }; + // If SP\d+ is in the filename, we force treat it as a special regardless if volume or chapter might have been found. private static readonly Regex SpecialMarkerRegex = new Regex( @"(?SP\d+)", @@ -767,6 +753,23 @@ namespace API.Parser return string.Empty; } + public static string ParseComicSpecial(string filePath) + { + foreach (var regex in ComicSpecialRegex) + { + var matches = regex.Matches(filePath); + foreach (Match match in matches) + { + if (match.Groups["Special"].Success && match.Groups["Special"].Value != string.Empty) + { + return match.Groups["Special"].Value; + } + } + } + + return string.Empty; + } + public static string ParseSeries(string filename) { foreach (var regex in MangaSeriesRegex) @@ -932,7 +935,7 @@ namespace API.Parser return title; } - private static string RemoveSpecialTags(string title) + private static string RemoveMangaSpecialTags(string title) { foreach (var regex in MangaSpecialRegex) { @@ -949,6 +952,23 @@ namespace API.Parser return title; } + private static string RemoveComicSpecialTags(string title) + { + foreach (var regex in ComicSpecialRegex) + { + var matches = regex.Matches(title); + foreach (Match match in matches) + { + if (match.Success) + { + title = title.Replace(match.Value, "").Trim(); + } + } + } + + return title; + } + /// @@ -965,7 +985,9 @@ namespace API.Parser title = RemoveEditionTagHolders(title); - title = RemoveSpecialTags(title); + title = RemoveMangaSpecialTags(title); + + title = RemoveComicSpecialTags(title); title = title.Replace("_", " ").Trim(); if (title.EndsWith("-") || title.EndsWith(","))