mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-01-08 01:10:01 -06:00
FF-1530: DeleteNonPageImages
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
using System.Xml;
|
||||
using FileFlows.ComicNodes.Helpers;
|
||||
using FileHelper = FileFlows.Plugin.Helpers.FileHelper;
|
||||
@@ -35,6 +36,14 @@ public class CreateComicInfo : Node
|
||||
/// </summary>
|
||||
[Boolean(2)]
|
||||
public bool RenameFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets how many digits the issues should use when renaming
|
||||
/// </summary>
|
||||
[NumberInt(3)]
|
||||
[DefaultValue(3)]
|
||||
[ConditionEquals(nameof(RenameFile), true)]
|
||||
public int IssueDigits { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Execute(NodeParameters args)
|
||||
@@ -130,7 +139,7 @@ public class CreateComicInfo : Node
|
||||
|
||||
if (RenameFile)
|
||||
{
|
||||
var newNameResult = GetNewName(info, FileHelper.GetExtension(args.WorkingFile));
|
||||
var newNameResult = GetNewName(info, FileHelper.GetExtension(args.WorkingFile), IssueDigits);
|
||||
if (newNameResult.Failed(out error))
|
||||
{
|
||||
args.Logger?.WLog(error);
|
||||
@@ -155,8 +164,9 @@ public class CreateComicInfo : Node
|
||||
/// </summary>
|
||||
/// <param name="info">the comic info</param>
|
||||
/// <param name="extension">the extension to use</param>
|
||||
/// <param name="issueDigits">the number of digits to pad by</param>
|
||||
/// <returns>the new name</returns>
|
||||
internal static Result<string> GetNewName(ComicInfo info, string extension)
|
||||
internal static Result<string> GetNewName(ComicInfo info, string extension, int issueDigits)
|
||||
{
|
||||
if (info.Number == null && info.Volume?.StartsWith("Volume") == false)
|
||||
return Result<string>.Fail("No issue number found, cannot rename");
|
||||
@@ -165,7 +175,25 @@ public class CreateComicInfo : Node
|
||||
|
||||
string name = info.Series;
|
||||
if (info.Number != null)
|
||||
name += $" - #{info.Number + (info.Count > 0 ? $" (of {info.Count})" : "")}";
|
||||
{
|
||||
if (issueDigits > 0)
|
||||
{
|
||||
// Pad the number with leading zeros based on the specified number of digits
|
||||
string paddedNumber = info.Number.Value.ToString().PadLeft(issueDigits, '0');
|
||||
|
||||
// Add the padded number to the name
|
||||
name += $" - #{paddedNumber}";
|
||||
|
||||
// Optionally add information about the count
|
||||
if (info.Count > 0)
|
||||
{
|
||||
name += $" (of {info.Count})";
|
||||
}
|
||||
}
|
||||
else
|
||||
name += $" - #{info.Number + (info.Count > 0 ? $" (of {info.Count})" : "")}";
|
||||
|
||||
}
|
||||
else
|
||||
name += " - " + info.Volume;
|
||||
|
||||
@@ -217,7 +245,7 @@ public class CreateComicInfo : Node
|
||||
var lastChanceMatch = Regex.Match(shortname, @"(\d)+$");
|
||||
if(lastChanceMatch.Success)
|
||||
{
|
||||
info.Number = int.Parse(lastChanceMatch.Groups[1].Value);
|
||||
info.Number = int.Parse(lastChanceMatch.Value);
|
||||
return info;
|
||||
}
|
||||
return Result<ComicInfo>.Fail("Invalid filename: " + shortname);
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ComicInfoTests : TestBase
|
||||
TestContext.WriteLine(new string('-', 70));
|
||||
TestContext.WriteLine(xml);
|
||||
|
||||
var name = CreateComicInfo.GetNewName(info, "cbz");
|
||||
var name = CreateComicInfo.GetNewName(info, "cbz", 0);
|
||||
Assert.AreEqual("Batman (1939) - #42 - Batman vs. Joker (old) (great) (amazing).cbz", name.Value);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ComicInfoTests : TestBase
|
||||
TestContext.WriteLine(new string('-', 70));
|
||||
TestContext.WriteLine(xml);
|
||||
|
||||
var name = CreateComicInfo.GetNewName(info, "cbz");
|
||||
var name = CreateComicInfo.GetNewName(info, "cbz", 2);
|
||||
Assert.AreEqual("He-Man and the Masters of the Universe (2013) - #123 - Desperate Times.cbz", name.Value);
|
||||
}
|
||||
|
||||
@@ -88,10 +88,38 @@ public class ComicInfoTests : TestBase
|
||||
TestContext.WriteLine(new string('-', 70));
|
||||
TestContext.WriteLine(xml);
|
||||
|
||||
var name = CreateComicInfo.GetNewName(info, "cbz");
|
||||
var name = CreateComicInfo.GetNewName(info, "cbz", 0);
|
||||
Assert.AreEqual("Ultimate Spider-Man (2000) - Volume 5 - Public Scrutiny.cbz", name.Value);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void NameAndNumber()
|
||||
{
|
||||
var result = CreateComicInfo.GetInfo(Logger,
|
||||
"/home/john/Comics/Marvel/X-Men/X-Man/X-Man 45.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("X-Man", info.Series);
|
||||
Assert.AreEqual(45, 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("X-Man - #045.cbz", name.Value);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void PhysicalFileTest()
|
||||
{
|
||||
|
||||
@@ -40,7 +40,9 @@
|
||||
"Publisher": "Publisher",
|
||||
"Publisher-Help": "If the comic is in a publisher directory, see help for more information.",
|
||||
"RenameFile": "Rename File",
|
||||
"RenameFile-Help": "If the file should be renamed `Series - Issue - Title.extension`"
|
||||
"RenameFile-Help": "If the file should be renamed `Series - Issue - Title.extension`",
|
||||
"IssueDigits": "Issue Digits",
|
||||
"IssueDigits-Help": "Will pad the issue number with leading zeros for up to this amount.\nFor example, for issue 1 if padding is 3, then the issue will appear as #001"
|
||||
},
|
||||
"Outputs": {
|
||||
"1": "ComicInfo added to comic archive",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user