3 Commits
Author SHA1 Message Date
l4kr 304d9ad047 Bump version to 1.0.5
Handle [TAG] NN episode-only filenames: when a file already
carries a bracket tag prefix followed directly by an episode
number (e.g. [WBDP] 03 - Deus Vult), inject the show name
from the parent folder between the tag and the episode part.

Also update ExtractShowName to handle bracket-style folder
names (text before the first [ is the show name).
2026-07-07 14:15:43 +02:00
l4kr 11a519d309 Ignore publish/ build output 2026-07-05 17:14:16 +02:00
l4kr 8b94fefe0f Bump version to 1.0.4
Extract in-filename suffix release tag (e.g. -DemiHuman) and
move it to a [DemiHuman] bracket prefix, stripping it from the
filename. File-level tag takes priority over folder-derived tag.
2026-07-05 17:14:08 +02:00
3 changed files with 96 additions and 33 deletions
+1
View File
@@ -1,5 +1,6 @@
bin/ bin/
obj/ obj/
publish/
*.user *.user
history.json history.json
settings.json settings.json
+2 -2
View File
@@ -9,8 +9,8 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>Futonizer</AssemblyName> <AssemblyName>Futonizer</AssemblyName>
<RootNamespace>Futonizer</RootNamespace> <RootNamespace>Futonizer</RootNamespace>
<Version>1.0.3</Version> <Version>1.0.5</Version>
<FileVersion>1.0.3.0</FileVersion> <FileVersion>1.0.5.0</FileVersion>
<ApplicationIcon>Assets\app.ico</ApplicationIcon> <ApplicationIcon>Assets\app.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
+87 -25
View File
@@ -9,19 +9,30 @@ namespace Futonizer.Services;
/// </summary> /// </summary>
public static class FileNameHelper public static class FileNameHelper
{ {
// Suffix release tag: "Show Name-TTGA" → tag = "TTGA" // Folder suffix release tag: "Show Name-TTGA" → tag = "TTGA"
// Must be 2-8 uppercase letters/digits at the very end, preceded by a dash. // All-uppercase, 2-8 chars, at end of folder name.
private static readonly Regex SuffixTagRegex = private static readonly Regex FolderSuffixTagRegex =
new(@"-([A-Z][A-Z0-9]{1,7})$", RegexOptions.Compiled); new(@"-([A-Z][A-Z0-9]{1,7})$", RegexOptions.Compiled);
// File suffix release tag: "…HEVC-DemiHuman" → tag = "DemiHuman"
// Mixed case, 3-21 chars (no dots/spaces), at end of filename stem.
// Min 3 chars avoids false-positives like "-v2" or "-HD".
private static readonly Regex FileSuffixTagRegex =
new(@"-([A-Za-z][A-Za-z0-9]{2,20})$", RegexOptions.Compiled);
// Prefix release tag: "[KAA] Show Name" → tag = "KAA" // Prefix release tag: "[KAA] Show Name" → tag = "KAA"
private static readonly Regex PrefixTagRegex = private static readonly Regex PrefixTagRegex =
new(@"^\[(.+?)\]", RegexOptions.Compiled); new(@"^\[(.+?)\]", RegexOptions.Compiled);
// Episode-only filename: starts with S01E01, S1E1, etc. (no show name present) // Episode-only filename (no tag prefix): starts with S01E01, S1E1, etc.
private static readonly Regex EpisodeOnlyRegex = private static readonly Regex EpisodeOnlyRegex =
new(@"^S\d+E\d+", RegexOptions.IgnoreCase | RegexOptions.Compiled); new(@"^S\d+E\d+", RegexOptions.IgnoreCase | RegexOptions.Compiled);
// Episode start after a tag prefix is stripped: plain number OR S01E01 style.
// e.g. "03 - Deus Vult ..." or "S01E01-Deep Blue"
private static readonly Regex EpisodeStartRegex =
new(@"^(\d+|S\d+E\d+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
// Individual metadata-token patterns used to find where the show name ends // Individual metadata-token patterns used to find where the show name ends
// inside a folder name. // inside a folder name.
private static readonly Regex[] MetadataPatterns = private static readonly Regex[] MetadataPatterns =
@@ -44,36 +55,74 @@ public static class FileNameHelper
/// Computes the final output filename for a given source file path, applying /// Computes the final output filename for a given source file path, applying
/// (in order): /// (in order):
/// <list type="number"> /// <list type="number">
/// <item>Show-name injection — if the filename starts with an episode code /// <item>Filename suffix tag extraction — a trailing <c>-GroupName</c> on
/// (e.g. S01E01) the show name is derived from the parent folder and /// the filename stem is stripped and promoted to a bracket prefix.
/// prepended.</item> /// Takes priority over any folder-derived tag.</item>
/// <item>Release-tag prefix — a <c>[TAG]</c> bracket prefix derived from /// <item>Show-name injection — if the (now tag-free) filename starts with
/// the parent folder name, either from a suffix pattern (<c>-TAG</c>) /// an episode code (e.g. S01E01) the show name is derived from the
/// or a prefix pattern (<c>[TAG]</c>).</item> /// parent folder and prepended.</item>
/// <item>Release-tag prefix — a <c>[TAG]</c> bracket prefix, sourced from
/// the filename suffix, the folder suffix, or the folder prefix,
/// in that priority order.</item>
/// </list> /// </list>
/// Returns the original filename unchanged when the parent folder provides /// Returns the original filename unchanged when no transformations apply.
/// no actionable information.
/// </summary> /// </summary>
public static string ComputeOutputFileName(string sourceFilePath) public static string ComputeOutputFileName(string sourceFilePath)
{ {
string fileName = Path.GetFileName(sourceFilePath); string fileName = Path.GetFileName(sourceFilePath);
string ext = Path.GetExtension(fileName);
string stemNoExt = Path.GetFileNameWithoutExtension(fileName);
string? folder = Path.GetDirectoryName(sourceFilePath); string? folder = Path.GetDirectoryName(sourceFilePath);
if (string.IsNullOrEmpty(folder)) return fileName; string folderName = string.IsNullOrEmpty(folder) ? "" : (Path.GetFileName(folder) ?? "");
string folderName = Path.GetFileName(folder); // 1. Extract in-filename suffix tag and remove it from the stem.
if (string.IsNullOrEmpty(folderName)) return fileName; // e.g. "...HEVC-DemiHuman" → tag="DemiHuman", stem="...HEVC"
string? fileTag = null;
var fileSuffixMatch = FileSuffixTagRegex.Match(stemNoExt);
if (fileSuffixMatch.Success)
{
fileTag = fileSuffixMatch.Groups[1].Value;
stemNoExt = stemNoExt[..fileSuffixMatch.Index];
fileName = stemNoExt + ext;
}
// 1. Inject show name when only an episode code is present. // 2. Determine the release tag: filename suffix > folder tag.
string fileNameNoExt = Path.GetFileNameWithoutExtension(fileName); string? tag = fileTag;
if (EpisodeOnlyRegex.IsMatch(fileNameNoExt)) if (string.IsNullOrEmpty(tag) && !string.IsNullOrEmpty(folderName))
tag = ExtractReleaseTag(folderName);
// 3. Check for episode-only patterns and inject show name if needed.
if (!string.IsNullOrEmpty(folderName))
{
// Pattern A: untagged stem starts with S01E01 (e.g. "S01E01-Deep Blue.mkv")
if (EpisodeOnlyRegex.IsMatch(stemNoExt))
{ {
string showName = ExtractShowName(folderName); string showName = ExtractShowName(folderName);
if (!string.IsNullOrEmpty(showName)) if (!string.IsNullOrEmpty(showName))
fileName = showName + " " + fileName; fileName = showName + " " + fileName;
} }
// Pattern B: file already carries [TAG] but episode number follows directly.
// e.g. "[WBDP] 03 - Deus Vult ..." → insert show name after the tag.
else if (!string.IsNullOrEmpty(tag))
{
string tagPfx = $"[{tag}] ";
if (stemNoExt.StartsWith(tagPfx, StringComparison.OrdinalIgnoreCase))
{
string afterTag = stemNoExt[tagPfx.Length..];
if (EpisodeStartRegex.IsMatch(afterTag))
{
string showName = ExtractShowName(folderName);
if (!string.IsNullOrEmpty(showName))
{
// Strip the tag, inject show name; tag is re-prepended in step 4.
fileName = showName + " " + fileName[tagPfx.Length..];
}
}
}
}
}
// 2. Prepend release tag if not already present. // 4. Prepend release tag if not already present.
string? tag = ExtractReleaseTag(folderName);
if (!string.IsNullOrEmpty(tag)) if (!string.IsNullOrEmpty(tag))
{ {
string tagPrefix = $"[{tag}]"; string tagPrefix = $"[{tag}]";
@@ -91,7 +140,7 @@ public static class FileNameHelper
/// </summary> /// </summary>
public static string? ExtractReleaseTag(string folderName) public static string? ExtractReleaseTag(string folderName)
{ {
var suffixMatch = SuffixTagRegex.Match(folderName); var suffixMatch = FolderSuffixTagRegex.Match(folderName);
if (suffixMatch.Success) return suffixMatch.Groups[1].Value; if (suffixMatch.Success) return suffixMatch.Groups[1].Value;
var prefixMatch = PrefixTagRegex.Match(folderName); var prefixMatch = PrefixTagRegex.Match(folderName);
@@ -102,16 +151,29 @@ public static class FileNameHelper
/// <summary> /// <summary>
/// Derives the show name from a folder name by stripping any release tag /// Derives the show name from a folder name by stripping any release tag
/// (prefix or suffix) and then taking all words that precede the first /// (prefix or suffix) and then:
/// recognised metadata token (season, quality, source, codec, etc.). /// <list type="bullet">
/// <item>If the remainder contains brackets (e.g. <c>[BD][1080p-FLAC]</c>),
/// returns the text that precedes the first bracket.</item>
/// <item>Otherwise splits on spaces and collects words up to the first
/// recognised metadata token (season, quality, source, codec, etc.).</item>
/// </list>
/// </summary> /// </summary>
public static string ExtractShowName(string folderName) public static string ExtractShowName(string folderName)
{ {
// Strip release tags first. // Strip release tags first.
string name = SuffixTagRegex.Replace(folderName, "").Trim(); string name = FolderSuffixTagRegex.Replace(folderName, "").Trim();
name = PrefixTagRegex.Replace(name, "").Trim(); name = PrefixTagRegex.Replace(name, "").Trim();
// Collect words up to the first metadata token. // Nothing left, or what remains immediately starts with a bracket — no show name.
if (string.IsNullOrEmpty(name) || name[0] == '[') return string.Empty;
// Bracket-style metadata: "The Saga of Tanya the Evil [BD][1080p-FLAC][HEVC]"
int bracketIdx = name.IndexOf('[');
if (bracketIdx > 0)
return name[..bracketIdx].Trim();
// Space-separated metadata: "Grand Blue Dreaming S01 1080p BD Remux FLAC"
var words = name.Split(' ', StringSplitOptions.RemoveEmptyEntries); var words = name.Split(' ', StringSplitOptions.RemoveEmptyEntries);
var showWords = new List<string>(); var showWords = new List<string>();
foreach (var word in words) foreach (var word in words)