Detect release group after bracketed metadata suffix

Naming-bot style releases like:
  Family Guy (1999) - S22E15 - Faith No More [HULU WEBDL-1080p]
  [EAC3 5.1][h264]-NTb
tack the group on with a dash right after the last metadata bracket,
rather than as a bare word ("x264-Group") or inside a trailing
parenthetical. FileSuffixTagRegex only matched the bare-word case, so
this pattern fell through untouched.

Added FileSuffixBracketDashTagRegex to catch "[bracket]-Group" at the
end of the stem, guarded by IsMetadataBracket on the bracket contents
so an ordinary hyphenated word after an unrelated bracket (e.g.
"[Interview]-Style") is never mistaken for a group suffix.
This commit is contained in:
2026-07-14 11:14:59 +02:00
parent 89bba70ee1
commit 08aae68525
2 changed files with 29 additions and 6 deletions
+27 -4
View File
@@ -30,6 +30,16 @@ public static class FileNameHelper
private static readonly Regex FileSuffixTagRegex =
new(@"(?:^|[\s.])([A-Za-z0-9]+)-([A-Za-z][A-Za-z0-9]{2,20})$", RegexOptions.Compiled);
// File suffix release tag directly after a bracketed metadata block:
// "...[HULU WEBDL-1080p][EAC3 5.1][h264]-NTb" → tag = "NTb"
// Common on naming-bot-style releases that group tech specs into their
// own brackets and tack the group on with a dash at the very end. The
// bracket immediately before the dash must itself be recognisable
// metadata (checked by the caller via IsMetadataBracket), mirroring
// FileSuffixTagRegex's guard for the bare-word case.
private static readonly Regex FileSuffixBracketDashTagRegex =
new(@"\[([^\[\]]+)\]-([A-Za-z][A-Za-z0-9]{2,20})$", RegexOptions.Compiled);
// Trailing parenthesised metadata block ending in the release group as its
// last word, e.g. "... (1080p AMZN WEB-DL x265 Celdra)" → group="Celdra".
// Common on Amazon/streaming rips that don't set the group off with a
@@ -87,10 +97,12 @@ public static class FileNameHelper
/// (in order):
/// <list type="number">
/// <item>Filename suffix tag extraction — a trailing <c>-GroupName</c> on
/// the filename stem, or a release group tucked in as the last word
/// of a trailing <c>(...)</c> metadata block (e.g. Amazon rips like
/// <c>(1080p AMZN WEB-DL x265 Celdra)</c>), is stripped and promoted
/// to a bracket prefix. Takes priority over any folder-derived tag.</item>
/// the filename stem, a group tacked on after a bracketed metadata
/// block (e.g. <c>[h264]-NTb</c>), or a release group tucked in as
/// the last word of a trailing <c>(...)</c> metadata block (e.g.
/// Amazon rips like <c>(1080p AMZN WEB-DL x265 Celdra)</c>), is
/// stripped and promoted to a bracket prefix. Takes priority over
/// any folder-derived tag.</item>
/// <item>Show-name injection — if the (now tag-free) filename starts with
/// an episode code (e.g. S01E01) the show name is derived from the
/// parent folder and prepended.</item>
@@ -121,6 +133,7 @@ public static class FileNameHelper
// hyphenated title words are left alone.
string? fileTag = null;
var fileSuffixMatch = FileSuffixTagRegex.Match(stemNoExt);
var bracketDashMatch = FileSuffixBracketDashTagRegex.Match(stemNoExt);
if (fileSuffixMatch.Success
&& IsMetadataToken(fileSuffixMatch.Groups[1].Value)
&& !IsMetadataToken(fileSuffixMatch.Groups[2].Value))
@@ -129,6 +142,16 @@ public static class FileNameHelper
stemNoExt = stemNoExt[..(fileSuffixMatch.Groups[2].Index - 1)];
fileName = stemNoExt + ext;
}
else if (bracketDashMatch.Success
&& IsMetadataBracket(bracketDashMatch.Groups[1].Value)
&& !IsMetadataToken(bracketDashMatch.Groups[2].Value))
{
// 1a. Extract a release group tacked on after a bracketed metadata
// block, e.g. "...[h264]-NTb" → tag="NTb", stem="...[h264]".
fileTag = bracketDashMatch.Groups[2].Value;
stemNoExt = stemNoExt[..(bracketDashMatch.Groups[2].Index - 1)];
fileName = stemNoExt + ext;
}
else
{
// 1b. Extract a release group tucked in as the last word of a