Fix Sonarr path boundary and exact episode parsing
This commit is contained in:
parent
6cf71a91e9
commit
cb054cbac7
1 changed files with 23 additions and 9 deletions
|
|
@ -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,14 +31,17 @@ 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);
|
||||||
|
const normalizedScopeRoot = normalizeImportPath(ImportPath);
|
||||||
|
const isInScope = normalizedCurrentPath === normalizedScopeRoot
|
||||||
|
|| normalizedCurrentPath.startsWith(normalizedScopeRoot + '/');
|
||||||
|
if (!isInScope) {
|
||||||
Logger.ILog(`Skip: current file '${currentFile}' not under ImportPath '${ImportPath}' - not responsible`);
|
Logger.ILog(`Skip: current file '${currentFile}' not under ImportPath '${ImportPath}' - not responsible`);
|
||||||
return 1;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue