FF-1524: Added more comic options

This commit is contained in:
John Andrews
2024-05-09 08:40:37 +12:00
parent affbeafff3
commit a024e69cae
3 changed files with 48 additions and 4 deletions

View File

@@ -177,16 +177,32 @@ public class ComicConverter: Node
if (DeleteNonPageImages)
{
List<string> nonPages = new();
float imageCount = 0;
foreach (var file in Directory.GetFiles(destinationPath, "*.*", SearchOption.AllDirectories))
{
if(rgxImages.IsMatch(file) == false)
continue;
imageCount++;
string nameNoExtension = FileHelper.GetShortFileName(file);
nameNoExtension = nameNoExtension[..nameNoExtension.LastIndexOf(".", StringComparison.Ordinal)];
if (Regex.IsMatch(nameNoExtension, @"[\d]{2,}$") == false)
{
args.Logger?.ILog("Deleting non page image: " + file);
File.Delete(file);
nonPages.Add(file);
}
}
if (nonPages.Any())
{
float percent = ((float)nonPages.Count) / imageCount * 100;
if (percent < 10)
{
// only delete if the number of non images is low, we dont want to mistakenly identify all pages as non images
foreach (var file in nonPages)
{
args.Logger?.ILog("Deleting non page image: " + file);
File.Delete(file);
}
}
}
}

View File

@@ -194,7 +194,9 @@ public class CreateComicInfo : Node
else
{
// Pad the number with leading zeros based on the specified number of digits
string paddedNumber = info.Number.Value.ToString().PadLeft(issueDigits, '0');
string paddedNumber = info.Number < 0 ?
("-" + info.Number.Value.ToString()[1..].PadLeft(issueDigits -1, '0')) :
info.Number.Value.ToString().PadLeft(issueDigits, '0');
// Add the padded number to the name
name += $" - #{paddedNumber}";
@@ -268,8 +270,9 @@ public class CreateComicInfo : Node
if (parts.Length < 2)
{
// remove any junk
shortname = Regex.Replace(shortname, @"\(([\-]?\d+)\)", "$1").Trim();
shortname = Regex.Replace(shortname, @"\s*\([^)]*\)\s*", " ").Trim();
var lastChanceMatch = Regex.Match(shortname, @"(\d)+$");
var lastChanceMatch = Regex.Match(shortname, @"([\-]?\d)+$");
if(lastChanceMatch.Success)
{
info.Number = int.Parse(lastChanceMatch.Value);

View File

@@ -119,6 +119,31 @@ public class ComicInfoTests : TestBase
Assert.AreEqual("X-Man - #045.cbz", name.Value);
}
[TestMethod]
public void MinusOne()
{
var result = CreateComicInfo.GetInfo(Logger,
"/home/john/Comics/Marvel/X-Men/Cable (1993)/Cable (-1) (1997) (Digital) (Dark-Star).cbz",
"/home/john/Comics",
true);
TestContext.WriteLine(Logger.ToString());
Assert.IsFalse(result.IsFailed);
var info = result.Value;
Assert.IsNotNull(info);
Assert.AreEqual("Marvel", info.Publisher);
Assert.AreEqual("Cable (1993)", info.Series);
Assert.AreEqual(-1, info.Number);
var xml = CreateComicInfo.SerializeToXml(info);
Assert.IsFalse(string.IsNullOrWhiteSpace(xml));
TestContext.WriteLine(new string('-', 70));
TestContext.WriteLine(xml);
var name = CreateComicInfo.GetNewName(info, "cbz", 3);
Assert.AreEqual("Cable (1993) - #-01.cbz", name.Value);
}
[TestMethod]
public void NameAndNumber2()