Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
304d9ad047 |
+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.4</Version>
|
<Version>1.0.5</Version>
|
||||||
<FileVersion>1.0.4.0</FileVersion>
|
<FileVersion>1.0.5.0</FileVersion>
|
||||||
<ApplicationIcon>Assets\app.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\app.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,15 @@ public static class FileNameHelper
|
|||||||
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 =
|
||||||
@@ -86,12 +91,35 @@ public static class FileNameHelper
|
|||||||
if (string.IsNullOrEmpty(tag) && !string.IsNullOrEmpty(folderName))
|
if (string.IsNullOrEmpty(tag) && !string.IsNullOrEmpty(folderName))
|
||||||
tag = ExtractReleaseTag(folderName);
|
tag = ExtractReleaseTag(folderName);
|
||||||
|
|
||||||
// 3. Inject show name when only an episode code is present.
|
// 3. Check for episode-only patterns and inject show name if needed.
|
||||||
if (EpisodeOnlyRegex.IsMatch(stemNoExt) && !string.IsNullOrEmpty(folderName))
|
if (!string.IsNullOrEmpty(folderName))
|
||||||
{
|
{
|
||||||
string showName = ExtractShowName(folderName);
|
// Pattern A: untagged stem starts with S01E01 (e.g. "S01E01-Deep Blue.mkv")
|
||||||
if (!string.IsNullOrEmpty(showName))
|
if (EpisodeOnlyRegex.IsMatch(stemNoExt))
|
||||||
fileName = showName + " " + fileName;
|
{
|
||||||
|
string showName = ExtractShowName(folderName);
|
||||||
|
if (!string.IsNullOrEmpty(showName))
|
||||||
|
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..];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Prepend release tag if not already present.
|
// 4. Prepend release tag if not already present.
|
||||||
@@ -123,8 +151,13 @@ 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)
|
||||||
{
|
{
|
||||||
@@ -132,7 +165,15 @@ public static class FileNameHelper
|
|||||||
string name = FolderSuffixTagRegex.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)
|
||||||
|
|||||||
Reference in New Issue
Block a user