Auto-rename safety net: never strip valid SxxExx episode token

Real-world scenario from user logs: package "Drei.Meter.ueber.dem.Himmel.
S01GERMAN.DL.720P.WEB.X264-WAYNE" (note malformed S01GERMAN with no
separator) caused the auto-renamer to strip the source's S01E01..S01E08
episode tokens because SCENE_SEASON_ONLY_RE doesn't match a season followed
by an immediate letter (no separator).

Result: all 8 episodes in the season pack collapsed to the same target name
and collided in the MKV library with (2)(3)(4)(5)(6)(7)(8) suffixes.

Fix: After buildAutoRenameBaseNameFromFoldersWithOptions, check if the
source filename has a valid episode token. If yes:
  1. If target has NO episode token: try to insert it via regex replacement
     (Sxx<garbage> -> SxxExx.<garbage>), then via applyEpisodeTokenToFolderName.
     If both fail, skip the rename entirely (preserve source name).
  2. If target has a DIFFERENT episode token: skip the rename (mislabel risk).

This guard is the last line of defense against the helper's regex
limitations on malformed package names.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sucukdeluxe
2026-04-14 11:45:41 +02:00
co-authored by Claude Opus 4.6
parent 90473b13cb
commit 1dfb486145
2 changed files with 76 additions and 1 deletions
+21
View File
@@ -762,4 +762,25 @@ describe("buildAutoRenameBaseNameFromFolders", () => {
);
expect(result).toBe("9JKL.S01E14.GERMAN.720p.WEB.x264-WvF");
});
it("documents malformed package name (S01GERMAN) limitation", () => {
// Real-world: "Drei.Meter.ueber.dem.Himmel.S01GERMAN.DL.720P.WEB.X264-WAYNE"
// is malformed (no separator between S01 and GERMAN). SCENE_SEASON_ONLY_RE
// doesn't match this, so the helper falls back to the package name as-is.
// The download-manager autoRenameExtractedVideoFiles safety net repairs
// this at runtime by inserting the source's episode token.
const result = buildAutoRenameBaseNameFromFoldersWithOptions(
[
"3MH.web.7p-101",
"Drei.Meter.ueber.dem.Himmel.S01GERMAN.DL.720P.WEB.X264-WAYNE"
],
"Drei.Meter.ueber.dem.Himmel.S01E01.GERMAN.DL.720P.WEB.X264-WAYNE",
{ forceEpisodeForSeasonFolder: true }
);
// Helper limitation: returns the malformed folder name unchanged.
// The download-manager safety net catches this at runtime.
if (result !== null) {
expect(typeof result).toBe("string");
}
});
});