fix(matcher): use folder path as series context

This commit is contained in:
Steppenstreuner
2026-08-28 20:01:15 +02:00
parent b8f042025d
commit 0844d303db
12 changed files with 475 additions and 47 deletions
+26 -1
View File
@@ -1,6 +1,6 @@
from types import SimpleNamespace
from wordarr.importer.matcher import best_matches, normalize
from wordarr.importer.matcher import best_matches, normalize, score
def req(id, title, authors="", media_type="ebook"):
@@ -70,3 +70,28 @@ def test_digit_inside_word_is_not_a_volume():
r3 = req(2, "Die dr3i - Folge 3", media_type="audiobook")
r3.volume = 3
assert score("DiE DR3i - 05 - Der Fall", r) > score("DiE DR3i - 05 - Der Fall", r3)
def test_series_in_folder_path_carries_the_match():
"""Downloads named "001 - Titel" only match via the series in their path."""
r = req(1, "Die drei ??? Folge 001", media_type="audiobook")
r.volume, r.series = 1, "Die drei ???"
item = {"path": "/d/x", "name": "001 - Der Super - Papagei",
"rel_dir": "Die Drei Fragezeichen/Folgen/3478632869 001-010",
"media_type": "audiobook", "is_dir": True, "files": ["/d/x/a.mp3"]}
out = best_matches([item], [r])
assert out[0]["suggested_request_id"] == 1
assert out[0]["score"] >= 90
# without the series context it stays a weak fuzzy guess
assert score("001 - Der Super - Papagei", r) < 90
def test_questionmarks_equal_fragezeichen():
assert normalize("Die drei ???") == normalize("Die Drei Fragezeichen")
def test_disc_count_is_not_an_episode_number():
r = req(1, "Die drei ??? und der Phantomsee", media_type="audiobook")
r.volume = 2
# "(2 CDs)" must not satisfy the volume check of episode 2
assert score("Die drei Fragezeichen 001 - Super-Papagei (2 CDs)", r) == 40.0