Recognize trailing [tag] on folder, guard metadata tags
Folders that carry their release tag as a bracket at the end (rather than a -TAG suffix or [TAG] prefix), e.g.: Gravity Falls 2012 Season 2 Complete + EXTRAS 720p BluRay x264 [i_c] now have that tag ([i_c]) prepended to the episode filename. Also fixes a real bug where a title's own hyphenated word (e.g. "Scary-oke") could be mistaken for a "-GroupName" suffix; the word before the dash must now itself look like quality/source/codec metadata for that pattern to fire. Every tag-extraction path (file dash-suffix, file trailing-parens group, folder dash-suffix, folder bracket-suffix, folder bracket- prefix) now also refuses to promote something that's obviously a metadata token itself (e.g. WEB, 1080p, HDR, WEBRip) to a release tag.
This commit is contained in:
+2
-2
@@ -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.8</Version>
|
<Version>1.0.9</Version>
|
||||||
<FileVersion>1.0.8.0</FileVersion>
|
<FileVersion>1.0.9.0</FileVersion>
|
||||||
<ApplicationIcon>Assets\app.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\app.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
+46
-11
@@ -14,11 +14,21 @@ public static class FileNameHelper
|
|||||||
private static readonly Regex FolderSuffixTagRegex =
|
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);
|
||||||
|
|
||||||
|
// Folder suffix bracket release tag: "Show Name ... x264 [i_c]" → tag = "i_c"
|
||||||
|
// A bracketed tag at the very end of the folder name (as opposed to
|
||||||
|
// PrefixTagRegex, which matches one at the start).
|
||||||
|
private static readonly Regex FolderSuffixBracketTagRegex =
|
||||||
|
new(@"\[([^\[\]]+)\]$", RegexOptions.Compiled);
|
||||||
|
|
||||||
// File suffix release tag: "…HEVC-DemiHuman" → tag = "DemiHuman"
|
// File suffix release tag: "…HEVC-DemiHuman" → tag = "DemiHuman"
|
||||||
// Mixed case, 3-21 chars (no dots/spaces), at end of filename stem.
|
// Mixed case, 3-21 chars (no dots/spaces), at end of filename stem.
|
||||||
// Min 3 chars avoids false-positives like "-v2" or "-HD".
|
// Min 3 chars avoids false-positives like "-v2" or "-HD". The word
|
||||||
|
// immediately preceding the dash must itself be recognisable quality/
|
||||||
|
// source/codec metadata (checked by the caller via IsMetadataToken), so
|
||||||
|
// an ordinary hyphenated title word (e.g. "Scary-oke") is never mistaken
|
||||||
|
// for a "-GroupName" suffix.
|
||||||
private static readonly Regex FileSuffixTagRegex =
|
private static readonly Regex FileSuffixTagRegex =
|
||||||
new(@"-([A-Za-z][A-Za-z0-9]{2,20})$", RegexOptions.Compiled);
|
new(@"(?:^|[\s.])([A-Za-z0-9]+)-([A-Za-z][A-Za-z0-9]{2,20})$", RegexOptions.Compiled);
|
||||||
|
|
||||||
// Trailing parenthesised metadata block ending in the release group as its
|
// Trailing parenthesised metadata block ending in the release group as its
|
||||||
// last word, e.g. "... (1080p AMZN WEB-DL x265 Celdra)" → group="Celdra".
|
// last word, e.g. "... (1080p AMZN WEB-DL x265 Celdra)" → group="Celdra".
|
||||||
@@ -86,13 +96,18 @@ public static class FileNameHelper
|
|||||||
string folderName = string.IsNullOrEmpty(folder) ? "" : (Path.GetFileName(folder) ?? "");
|
string folderName = string.IsNullOrEmpty(folder) ? "" : (Path.GetFileName(folder) ?? "");
|
||||||
|
|
||||||
// 1. Extract in-filename suffix tag and remove it from the stem.
|
// 1. Extract in-filename suffix tag and remove it from the stem.
|
||||||
// e.g. "...HEVC-DemiHuman" → tag="DemiHuman", stem="...HEVC"
|
// e.g. "...x264-DemiHuman" → tag="DemiHuman", stem="...x264"
|
||||||
|
// Only fires when the word right before the dash is itself a
|
||||||
|
// recognised metadata token (codec/source/etc.), so ordinary
|
||||||
|
// hyphenated title words are left alone.
|
||||||
string? fileTag = null;
|
string? fileTag = null;
|
||||||
var fileSuffixMatch = FileSuffixTagRegex.Match(stemNoExt);
|
var fileSuffixMatch = FileSuffixTagRegex.Match(stemNoExt);
|
||||||
if (fileSuffixMatch.Success)
|
if (fileSuffixMatch.Success
|
||||||
|
&& IsMetadataToken(fileSuffixMatch.Groups[1].Value)
|
||||||
|
&& !IsMetadataToken(fileSuffixMatch.Groups[2].Value))
|
||||||
{
|
{
|
||||||
fileTag = fileSuffixMatch.Groups[1].Value;
|
fileTag = fileSuffixMatch.Groups[2].Value;
|
||||||
stemNoExt = stemNoExt[..fileSuffixMatch.Index];
|
stemNoExt = stemNoExt[..(fileSuffixMatch.Groups[2].Index - 1)];
|
||||||
fileName = stemNoExt + ext;
|
fileName = stemNoExt + ext;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -169,17 +184,24 @@ public static class FileNameHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extracts the release tag string (without brackets) from a folder name.
|
/// Extracts the release tag string (without brackets) from a folder name,
|
||||||
/// Suffix pattern (<c>-TAG</c>) takes priority over prefix pattern
|
/// checking (in priority order): a dash suffix (<c>-TAG</c>), a bracketed
|
||||||
/// (<c>[TAG]</c>). Returns <c>null</c> when neither is present.
|
/// suffix (<c>[tag]</c> at the end), then a bracketed prefix (<c>[tag]</c>
|
||||||
|
/// at the start). Returns <c>null</c> when none are present.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string? ExtractReleaseTag(string folderName)
|
public static string? ExtractReleaseTag(string folderName)
|
||||||
{
|
{
|
||||||
var suffixMatch = FolderSuffixTagRegex.Match(folderName);
|
var suffixMatch = FolderSuffixTagRegex.Match(folderName);
|
||||||
if (suffixMatch.Success) return suffixMatch.Groups[1].Value;
|
if (suffixMatch.Success && !IsMetadataToken(suffixMatch.Groups[1].Value))
|
||||||
|
return suffixMatch.Groups[1].Value;
|
||||||
|
|
||||||
|
var bracketSuffixMatch = FolderSuffixBracketTagRegex.Match(folderName);
|
||||||
|
if (bracketSuffixMatch.Success && !IsMetadataBracket(bracketSuffixMatch.Groups[1].Value))
|
||||||
|
return bracketSuffixMatch.Groups[1].Value;
|
||||||
|
|
||||||
var prefixMatch = PrefixTagRegex.Match(folderName);
|
var prefixMatch = PrefixTagRegex.Match(folderName);
|
||||||
if (prefixMatch.Success) return prefixMatch.Groups[1].Value;
|
if (prefixMatch.Success && !IsMetadataBracket(prefixMatch.Groups[1].Value))
|
||||||
|
return prefixMatch.Groups[1].Value;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -198,6 +220,7 @@ public static class FileNameHelper
|
|||||||
{
|
{
|
||||||
// Strip release tags first.
|
// Strip release tags first.
|
||||||
string name = FolderSuffixTagRegex.Replace(folderName, "").Trim();
|
string name = FolderSuffixTagRegex.Replace(folderName, "").Trim();
|
||||||
|
name = FolderSuffixBracketTagRegex.Replace(name, "").Trim();
|
||||||
name = PrefixTagRegex.Replace(name, "").Trim();
|
name = PrefixTagRegex.Replace(name, "").Trim();
|
||||||
|
|
||||||
// Nothing left, or what remains immediately starts with a bracket — no show name.
|
// Nothing left, or what remains immediately starts with a bracket — no show name.
|
||||||
@@ -226,4 +249,16 @@ public static class FileNameHelper
|
|||||||
if (pattern.IsMatch(token)) return true;
|
if (pattern.IsMatch(token)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True when every word inside a bracketed block is recognisable quality/
|
||||||
|
/// source/codec metadata (e.g. "[HEVC]", "[1080p-FLAC]"), meaning it's
|
||||||
|
/// just another metadata tag rather than an actual release group name
|
||||||
|
/// (e.g. "[i_c]").
|
||||||
|
/// </summary>
|
||||||
|
private static bool IsMetadataBracket(string content)
|
||||||
|
{
|
||||||
|
var parts = content.Split(new[] { ' ', '-' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
return parts.Length > 0 && parts.All(IsMetadataToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user