FF-1209 - added options to create audio book

This commit is contained in:
John Andrews
2024-01-20 10:58:10 +13:00
parent b60c14da00
commit 4a410588c3
2 changed files with 61 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
using FileFlows.Plugin;
using TagLib.Tiff.Cr2;
namespace FileFlows.AudioNodes;
@@ -32,6 +33,23 @@ public class CreateAudioBook: AudioNode
/// </summary>
public override FlowElementType Type => FlowElementType.Process;
/// <summary>
/// Gets or sets the destination path
/// </summary>
[Required]
[Folder(1)]
public string DestinationPath { get; set; }
/// <summary>
/// Gets or sets if the source files should be deleted
/// </summary>
[Boolean(2)] public bool DeleteSourceFiles { get; set; }
/// <summary>
/// Gets or sets if the working file should be updated
/// </summary>
[Boolean(3)] public bool UpdateWorkingFile { get; set; }
/// <summary>
/// Executes the flow element
/// </summary>
@@ -185,7 +203,41 @@ public class CreateAudioBook: AudioNode
args.Logger.ELog("Failed to create output file: " + outputFile);
return -1;
}
args.Logger.ELog("Created output file: " + outputFile);
args.Logger.ILog("Created output file: " + outputFile);
if (DeleteSourceFiles)
{
foreach (var file in files)
{
var result = args.FileService.FileDelete(file);
if(result.IsFailed)
args.Logger.ILog("Failed deleting source file: " + file + " -> " + result.Error);
else if(result.Value == false)
args.Logger.ILog("Failed deleting source file: " + file);
else
args.Logger.ILog("Deleted source file: " + file);
}
}
if (string.IsNullOrWhiteSpace(DestinationPath) == false)
{
var dest = args.ReplaceVariables(DestinationPath, stripMissing: true);
if (args.FileService.FileMove(outputFile, dest).Failed(out string error))
{
args.Logger?.ELog("Failed to save to destination: " + error);
return -1;
}
outputFile = dest;
}
if (UpdateWorkingFile)
{
args.Logger?.ILog("Updating working file to: " + outputFile);
args.IsDirectory = false; // no longer a directory based flow
args.SetWorkingFile(outputFile);
}
return 1;
}

View File

@@ -114,6 +114,14 @@
"Outputs": {
"1": "Audio book created",
"2": "Audio book not created"
},
"Fields": {
"DeleteSourceFiles": "Delete Source Files",
"DeleteSourceFiles-Help": "When enabled the source files that make up the newly created m4b file will be deleted, otherwise they will be left alone.",
"UpdateWorkingFile": "Update Working File",
"UpdateWorkingFile-Help": "When enabled the working file will be updated to the newly created file.",
"DestinationPath": "Destination Path",
"DestinationPath-Help": "The destination where to save the newly created file. If left empty the file will be created in the temporary directory and will be deleted if not moved afterwards."
}
}
}