feat(export): output path from a project's export folder and name template
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+23
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Titano.Core.Naming;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Core.Video;
|
||||
|
||||
namespace Titano.Core.Export;
|
||||
@@ -114,6 +115,16 @@ public static class ExportNaming
|
||||
return Unique(folder, name, extension);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Output path of a project's export: <see cref="ExportSettings.Folder"/> or, when unset, the sequence's exports folder,
|
||||
/// named by <see cref="ExportSettings.NameTemplate"/>.
|
||||
/// </summary>
|
||||
public static string OutputPath(ExportSettings settings, string sequenceExportsFolder, ExportNameContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
return OutputPath(string.IsNullOrWhiteSpace(settings.Folder) ? sequenceExportsFolder : settings.Folder, settings.NameTemplate, context);
|
||||
}
|
||||
|
||||
/// <summary>"name.ext", or "name (2).ext", "name (3).ext"… when a file or folder of that name exists.</summary>
|
||||
public static string Unique(string folder, string name, string extension)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Core.Video;
|
||||
using Titano.Testing;
|
||||
|
||||
@@ -68,4 +69,15 @@ public sealed class ExportNamingTests
|
||||
Assert.Equal(Path.Combine(dir, "Harbour sunset (2)"), ExportNaming.OutputPath(dir, "{title}", Context(VideoCodec.PngSequence)));
|
||||
Assert.Equal(Path.Combine(dir, "Harbour sunset.gif"), ExportNaming.OutputPath(dir, "{title}", Context(VideoCodec.Gif)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProjectSettingsChooseFolderAndTemplate()
|
||||
{
|
||||
var exports = _context.CreateTempDirectory("exports");
|
||||
var custom = _context.CreateTempDirectory("custom");
|
||||
var byDefault = ExportNaming.OutputPath(new ExportSettings(), exports, Context());
|
||||
Assert.Equal(Path.Combine(exports, "2024-06-21 Harbour sunset - 4K UHD HEVC.mp4"), byDefault);
|
||||
var chosen = ExportNaming.OutputPath(new ExportSettings { Folder = custom, NameTemplate = "{title} {width}" }, exports, Context());
|
||||
Assert.Equal(Path.Combine(custom, "Harbour sunset 3840.mp4"), chosen);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user