Fix FileFlows Sonarr season-pack path routing #7

Merged
sascha merged 2 commits from fix/sonarr-pack-path-scope-20260913 into main 2026-09-14 09:15:07 +02:00
Showing only changes of commit cb054cbac7 - Show all commits

View file

@ -2,7 +2,7 @@
* @name Sonarr - Trigger Manual Import * @name Sonarr - Trigger Manual Import
* @description Safely trigger Sonarr ManualImport for exactly one processed episode file. * @description Safely trigger Sonarr ManualImport for exactly one processed episode file.
* @author FileFlows + Sascha * @author FileFlows + Sascha
* @revision 10 * @revision 11
* @output Import erfolgreich * @output Import erfolgreich
* @output Fehler * @output Fehler
* @param {string} URL Sonarr root URL and port * @param {string} URL Sonarr root URL and port
@ -31,13 +31,16 @@ function Script(URL, ApiKey, ImportPath, UseUnmappedPath, MoveMode, TimeOut) {
} }
// ── SKIP-GUARD: Nur API-Call machen, wenn der aktuelle ImportPath // ── SKIP-GUARD: Nur API-Call machen, wenn der aktuelle ImportPath
// mit dem konfigurierten Pfad uebereinstimmt. Sonst sofort OK. // mit dem konfigurierten Pfad als vollständiges Pfadsegment
// Das verhindert 3 unnoetige API-Calls pro Datei (4 Arr-Instanzen). // übereinstimmt. Ein nacktes Prefix würde z. B. /serien4k
if (ImportPath && ImportPath.indexOf(URL) === -1) { // fälschlich dem FHD-Root /serien zuordnen.
if (currentFile && ImportPath && currentFile.indexOf(ImportPath) === -1) { const normalizedCurrentPath = normalizeImportPath(exactImportPath);
Logger.ILog(`Skip: current file '${currentFile}' not under ImportPath '${ImportPath}' - not responsible`); const normalizedScopeRoot = normalizeImportPath(ImportPath);
return 1; const isInScope = normalizedCurrentPath === normalizedScopeRoot
} || normalizedCurrentPath.startsWith(normalizedScopeRoot + '/');
if (!isInScope) {
Logger.ILog(`Skip: current file '${currentFile}' not under ImportPath '${ImportPath}' - not responsible`);
return 1;
} }
const sonarr = new Sonarr(URL, ApiKey); const sonarr = new Sonarr(URL, ApiKey);
@ -58,7 +61,18 @@ function Script(URL, ApiKey, ImportPath, UseUnmappedPath, MoveMode, TimeOut) {
?? findEpisodeFromGrabHistory(pattern, sonarr); ?? findEpisodeFromGrabHistory(pattern, sonarr);
if (trackedEpisode) break; if (trackedEpisode) break;
} }
if (!trackedEpisode) trackedEpisode = parseSeries(searchPatterns[0] || '', sonarr); if (!trackedEpisode) {
// Ein Staffelpaket-Ordner ist absichtlich mehrdeutig. Zuerst
// den exakten Episoden-Dateinamen parsen, danach erst den
// Ordnernamen als letzten Fallback versuchen.
const parsePatterns = [filePattern, folderPattern]
.filter(Boolean)
.filter((value, index, values) => values.indexOf(value) === index);
for (const pattern of parsePatterns) {
trackedEpisode = parseSeries(pattern, sonarr);
if (trackedEpisode?.id && trackedEpisode?.episodeIds?.length) break;
}
}
seriesId = trackedEpisode?.id ?? null; seriesId = trackedEpisode?.id ?? null;
episodeIds = trackedEpisode?.episodeIds ?? null; episodeIds = trackedEpisode?.episodeIds ?? null;
} }