Fix FileFlows Sonarr season-pack path routing #7
2 changed files with 86 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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,69 @@ def run_script(scenario):
|
||||||
|
|
||||||
|
|
||||||
class SonarrImportSafetyTests(unittest.TestCase):
|
class SonarrImportSafetyTests(unittest.TestCase):
|
||||||
|
def test_fhd_scope_does_not_match_uhd_sibling_prefix(self):
|
||||||
|
exact = (
|
||||||
|
"/tdarr/converted/serien4k/Marshals.2026.S01.GERMAN.DUBBED/"
|
||||||
|
"Marshals.2026.S01E05.GERMAN.DUBBED.mkv"
|
||||||
|
)
|
||||||
|
result = run_script(
|
||||||
|
{
|
||||||
|
"releaseTitle": "Marshals.2026.S01E05.GERMAN.DUBBED",
|
||||||
|
"exactPath": exact,
|
||||||
|
"scopeRoot": "/tdarr/converted/serien",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(result["result"], 1)
|
||||||
|
self.assertEqual(result["calls"], [])
|
||||||
|
|
||||||
|
def test_season_pack_history_uses_exact_episode_filename_for_parse(self):
|
||||||
|
pack = "Marshals.2026.S01.GERMAN.DUBBED.DL.2160p.WEB.H265-TSCC"
|
||||||
|
episode = "Marshals.2026.S01E05.GERMAN.DUBBED.DL.2160p.WEB.H265-TSCC"
|
||||||
|
exact = f"/tdarr/converted/serien4k/{pack}/{episode}.mkv"
|
||||||
|
queue_records = [
|
||||||
|
{"title": pack, "seriesId": 600, "episodeId": 37500 + number}
|
||||||
|
for number in range(1, 14)
|
||||||
|
]
|
||||||
|
history_records = [
|
||||||
|
{
|
||||||
|
"sourceTitle": pack,
|
||||||
|
"seriesId": 600,
|
||||||
|
"episodeId": 37500 + number,
|
||||||
|
"eventType": "grabbed",
|
||||||
|
}
|
||||||
|
for number in range(1, 14)
|
||||||
|
]
|
||||||
|
result = run_script(
|
||||||
|
{
|
||||||
|
"releaseTitle": episode,
|
||||||
|
"exactPath": exact,
|
||||||
|
"scopeRoot": "/tdarr/converted/serien4k",
|
||||||
|
"queueResponse": {"records": queue_records},
|
||||||
|
"historyResponse": {"records": history_records},
|
||||||
|
"parseResponse": {
|
||||||
|
"series": {"id": 600, "title": "Marshals"},
|
||||||
|
"episodes": [{"id": 37505}],
|
||||||
|
},
|
||||||
|
"candidates": [
|
||||||
|
{
|
||||||
|
"path": exact,
|
||||||
|
"quality": {"quality": {"id": 19, "name": "WEBDL-2160p"}},
|
||||||
|
"languages": [{"id": 4, "name": "German"}],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(result["result"], 1)
|
||||||
|
command = next(call for call in result["calls"] if call["type"] == "command")
|
||||||
|
self.assertEqual(command["body"]["files"][0]["episodeIds"], [37505])
|
||||||
|
parse_call = next(
|
||||||
|
call for call in result["calls"]
|
||||||
|
if call["type"] == "fetch" and call["endpoint"] == "parse"
|
||||||
|
)
|
||||||
|
self.assertIn("s01e05", parse_call["query"].lower())
|
||||||
|
|
||||||
def test_percent_title_matches_queue_and_imports_exact_episode_file(self):
|
def test_percent_title_matches_queue_and_imports_exact_episode_file(self):
|
||||||
source_title = (
|
source_title = (
|
||||||
"100%.Wolf.S01E01.Die.Aufnahmeprufung.German.1080p."
|
"100%.Wolf.S01E01.Die.Aufnahmeprufung.German.1080p."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue