diff --git a/fileflows/scripts/Sonarr_-_Trigger_Manual_Import.js b/fileflows/scripts/Sonarr_-_Trigger_Manual_Import.js index 2daabe3..dac74c2 100644 --- a/fileflows/scripts/Sonarr_-_Trigger_Manual_Import.js +++ b/fileflows/scripts/Sonarr_-_Trigger_Manual_Import.js @@ -1,3 +1,17 @@ +/** + * @name Sonarr - Trigger Manual Import + * @description Trigger Sonarr ManualImport or downloadedEpisodesScan with skip-guard. + * @author FileFlows + Sascha + * @revision 8 + * @output Import erfolgreich + * @output Fehler + * @param {string} URL Sonarr root URL and port + * @param {string} ApiKey Sonarr API Key + * @param {string} ImportPath Output path for import triggering + * @param {bool} UseUnmappedPath Whether to Unmap the path + * @param {bool} MoveMode Import mode: true=move, false=copy + * @param {int} TimeOut Timeout in seconds (max 3600) + */ import { Sonarr } from 'Shared/Sonarr'; @@ -9,6 +23,17 @@ function Script(URL, ApiKey, ImportPath, UseUnmappedPath, MoveMode, TimeOut) { ImportPath = UseUnmappedPath ? Flow.UnMapPath(ImportPath) : ImportPath; const importMode = MoveMode ? 'move' : 'copy'; + // ── SKIP-GUARD: Nur API-Call machen, wenn der aktuelle ImportPath + // mit dem konfigurierten Pfad uebereinstimmt. Sonst sofort OK. + // Das verhindert 3 unnoetige API-Calls pro Datei (4 Arr-Instanzen). + if (ImportPath && ImportPath.indexOf(URL) === -1) { + var currentFile = Variables['file.FullName'] || ''; + if (currentFile && ImportPath && currentFile.indexOf(ImportPath) === -1) { + Logger.ILog(`Skip: current file '${currentFile}' not under ImportPath '${ImportPath}' - not responsible`); + return 1; + } + } + const sonarr = new Sonarr(URL, ApiKey); /*── seriesId / episodeId detection ──────────────────────────────────*/