Adding multiple cases for comic naming conventions
This commit is contained in:
parent
d68600c1ed
commit
3748356199
3 changed files with 86 additions and 36 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace API.Tests.Parser
|
namespace API.Tests.Parser
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +30,12 @@ namespace API.Tests.Parser
|
||||||
[InlineData("Saga 001 (2012) (Digital) (Empire-Zone).cbr", "Saga")]
|
[InlineData("Saga 001 (2012) (Digital) (Empire-Zone).cbr", "Saga")]
|
||||||
[InlineData("spawn-123", "spawn")]
|
[InlineData("spawn-123", "spawn")]
|
||||||
[InlineData("Batman Beyond 04 (of 6) (1999)", "Batman Beyond")]
|
[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)
|
public void ParseComicSeriesTest(string filename, string expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, API.Parser.Parser.ParseComicSeries(filename));
|
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("Invincible 033.5 - Marvel Team-Up 14 (2006) (digital) (Minutemen-Slayer)", "0")]
|
||||||
[InlineData("Cyberpunk 2077 - Trauma Team 04.cbz", "0")]
|
[InlineData("Cyberpunk 2077 - Trauma Team 04.cbz", "0")]
|
||||||
[InlineData("spawn-123", "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)
|
public void ParseComicVolumeTest(string filename, string expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, API.Parser.Parser.ParseComicVolume(filename));
|
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("Batman Beyond 04 (of 6) (1999)", "4")]
|
||||||
[InlineData("Invincible 052 (c2c) (2008) (Minutemen-TheCouple)", "52")]
|
[InlineData("Invincible 052 (c2c) (2008) (Minutemen-TheCouple)", "52")]
|
||||||
[InlineData("Y - The Last Man #001", "1")]
|
[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)
|
public void ParseComicChapterTest(string filename, string expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, API.Parser.Parser.ParseComicChapter(filename));
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ namespace API.Tests.Parser
|
||||||
[InlineData("Beastars SP01", true)]
|
[InlineData("Beastars SP01", true)]
|
||||||
[InlineData("Beastars Special 01", false)]
|
[InlineData("Beastars Special 01", false)]
|
||||||
[InlineData("Beastars Extra 01", false)]
|
[InlineData("Beastars Extra 01", false)]
|
||||||
|
[InlineData("Batman Beyond - Return of the Joker (2001) SP01", true)]
|
||||||
public void HasSpecialTest(string input, bool expected)
|
public void HasSpecialTest(string input, bool expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, HasSpecialMarker(input));
|
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("[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("[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)
|
public void CleanTitleTest(string input, string expected)
|
||||||
{
|
{
|
||||||
Assert.Equal(expected, CleanTitle(input));
|
Assert.Equal(expected, CleanTitle(input));
|
||||||
|
|
|
||||||
|
|
@ -272,6 +272,11 @@ namespace API.Parser
|
||||||
@"(?<Series>.*)(\b|_)(vol\.?)( |_)(?<Volume>\d+(-\d+)?)",
|
@"(?<Series>.*)(\b|_)(vol\.?)( |_)(?<Volume>\d+(-\d+)?)",
|
||||||
MatchOptions,
|
MatchOptions,
|
||||||
RegexTimeout),
|
RegexTimeout),
|
||||||
|
// Batman Beyond 2.0 001 (2013)
|
||||||
|
new Regex(
|
||||||
|
@"^(?<Series>.+?\S\.\d) (?<Chapter>\d+)",
|
||||||
|
MatchOptions,
|
||||||
|
RegexTimeout),
|
||||||
// 04 - Asterix the Gladiator (1964) (Digital-Empire) (WebP by Doc MaKS)
|
// 04 - Asterix the Gladiator (1964) (Digital-Empire) (WebP by Doc MaKS)
|
||||||
new Regex(
|
new Regex(
|
||||||
@"^(?<Volume>\d+) (- |_)?(?<Series>.*(\d{4})?)( |_)(\(|\d+)",
|
@"^(?<Volume>\d+) (- |_)?(?<Series>.*(\d{4})?)( |_)(\(|\d+)",
|
||||||
|
|
@ -341,44 +346,11 @@ namespace API.Parser
|
||||||
|
|
||||||
private static readonly Regex[] ComicVolumeRegex = new[]
|
private static readonly Regex[] ComicVolumeRegex = new[]
|
||||||
{
|
{
|
||||||
// // 04 - Asterix the Gladiator (1964) (Digital-Empire) (WebP by Doc MaKS)
|
|
||||||
// new Regex(
|
|
||||||
// @"^(?<Volume>\d+) (- |_)?(?<Series>.*(\d{4})?)( |_)(\(|\d+)",
|
|
||||||
// MatchOptions,
|
|
||||||
// RegexTimeout),
|
|
||||||
// // 01 Spider-Man & Wolverine 01.cbr
|
|
||||||
// new Regex(
|
|
||||||
// @"^(?<Volume>\d+) (?:- )?(?<Series>.*) (\d+)?",
|
|
||||||
// MatchOptions,
|
|
||||||
// RegexTimeout),
|
|
||||||
// // Batman & Wildcat (1 of 3)
|
|
||||||
// new Regex(
|
|
||||||
// @"(?<Series>.*(\d{4})?)( |_)(?:\((?<Chapter>\d+) of \d+)",
|
|
||||||
// MatchOptions,
|
|
||||||
// RegexTimeout),
|
|
||||||
// Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)
|
// Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)
|
||||||
new Regex(
|
new Regex(
|
||||||
@"^(?<Series>.*)(?: |_)v(?<Volume>\d+)",
|
@"^(?<Series>.*)(?: |_)v(?<Volume>\d+)",
|
||||||
MatchOptions,
|
MatchOptions,
|
||||||
RegexTimeout),
|
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(
|
|
||||||
// @"^(?<Series>.+?)(?<!c(hapter)|i(ssue))(?<!of)(?: |_)(?<!of )(?<Volume>\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(
|
|
||||||
// @"^(?<Series>.+?)(?<!c(hapter)|i(ssue))(?<!of)(?: (?<Volume>\d+))",
|
|
||||||
// MatchOptions,
|
|
||||||
// RegexTimeout),
|
|
||||||
// // Batman & Robin the Teen Wonder #0
|
|
||||||
// new Regex(
|
|
||||||
// @"^(?<Series>.*)(?: |_)#(?<Volume>\d+)",
|
|
||||||
// MatchOptions,
|
|
||||||
// RegexTimeout),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly Regex[] ComicChapterRegex = new[]
|
private static readonly Regex[] ComicChapterRegex = new[]
|
||||||
|
|
@ -393,6 +365,11 @@ namespace API.Parser
|
||||||
@"(?<Series>.+?)(?<Chapter>\d+)(\s|_|-)?\(of",
|
@"(?<Series>.+?)(?<Chapter>\d+)(\s|_|-)?\(of",
|
||||||
MatchOptions,
|
MatchOptions,
|
||||||
RegexTimeout),
|
RegexTimeout),
|
||||||
|
// Batman Beyond 2.0 001 (2013)
|
||||||
|
new Regex(
|
||||||
|
@"^(?<Series>.+?\S\.\d) (?<Chapter>\d+)",
|
||||||
|
MatchOptions,
|
||||||
|
RegexTimeout),
|
||||||
// Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)
|
// Teen Titans v1 001 (1966-02) (digital) (OkC.O.M.P.U.T.O.-Novus)
|
||||||
new Regex(
|
new Regex(
|
||||||
@"^(?<Series>.+?)(?: |_)v(?<Volume>\d+)(?: |_)(c? ?)(?<Chapter>(\d+(\.\d)?)-?(\d+(\.\d)?)?)(c? ?)",
|
@"^(?<Series>.+?)(?: |_)v(?<Volume>\d+)(?: |_)(c? ?)(?<Chapter>(\d+(\.\d)?)-?(\d+(\.\d)?)?)(c? ?)",
|
||||||
|
|
@ -551,6 +528,15 @@ namespace API.Parser
|
||||||
RegexTimeout),
|
RegexTimeout),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly Regex[] ComicSpecialRegex =
|
||||||
|
{
|
||||||
|
// All Keywords, does not account for checking if contains volume/chapter identification. Parser.Parse() will handle.
|
||||||
|
new Regex(
|
||||||
|
@"(?<Special>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.
|
// 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(
|
private static readonly Regex SpecialMarkerRegex = new Regex(
|
||||||
@"(?<Special>SP\d+)",
|
@"(?<Special>SP\d+)",
|
||||||
|
|
@ -767,6 +753,23 @@ namespace API.Parser
|
||||||
return string.Empty;
|
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)
|
public static string ParseSeries(string filename)
|
||||||
{
|
{
|
||||||
foreach (var regex in MangaSeriesRegex)
|
foreach (var regex in MangaSeriesRegex)
|
||||||
|
|
@ -932,7 +935,7 @@ namespace API.Parser
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string RemoveSpecialTags(string title)
|
private static string RemoveMangaSpecialTags(string title)
|
||||||
{
|
{
|
||||||
foreach (var regex in MangaSpecialRegex)
|
foreach (var regex in MangaSpecialRegex)
|
||||||
{
|
{
|
||||||
|
|
@ -949,6 +952,23 @@ namespace API.Parser
|
||||||
return title;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -965,7 +985,9 @@ namespace API.Parser
|
||||||
|
|
||||||
title = RemoveEditionTagHolders(title);
|
title = RemoveEditionTagHolders(title);
|
||||||
|
|
||||||
title = RemoveSpecialTags(title);
|
title = RemoveMangaSpecialTags(title);
|
||||||
|
|
||||||
|
title = RemoveComicSpecialTags(title);
|
||||||
|
|
||||||
title = title.Replace("_", " ").Trim();
|
title = title.Replace("_", " ").Trim();
|
||||||
if (title.EndsWith("-") || title.EndsWith(","))
|
if (title.EndsWith("-") || title.EndsWith(","))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue