feat(lidarr): add Artist - Track query splitter
This commit is contained in:
@@ -126,6 +126,15 @@ def _artist_to_hit(artist: dict) -> Hit:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _split_query(query: str) -> tuple[str, Optional[str]]:
|
||||||
|
"""Split a Shazam-style 'Artist - Track' on the first ' - '.
|
||||||
|
Returns (artist, track) or (term, None) when there is no separator."""
|
||||||
|
if " - " in query:
|
||||||
|
left, right = query.split(" - ", 1)
|
||||||
|
return left.strip(), right.strip()
|
||||||
|
return query.strip(), None
|
||||||
|
|
||||||
|
|
||||||
def lidarr_search(query: str, limit: int) -> list[Hit]:
|
def lidarr_search(query: str, limit: int) -> list[Hit]:
|
||||||
"""Universal search via /api/v1/search; fall back to album+artist lookup."""
|
"""Universal search via /api/v1/search; fall back to album+artist lookup."""
|
||||||
if not API_KEY:
|
if not API_KEY:
|
||||||
|
|||||||
18
tests/test_lidarr_match.py
Normal file
18
tests/test_lidarr_match.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import server.mf # noqa: F401 — loads musicfetch, registers musicfetch_core in sys.modules
|
||||||
|
import musicfetch_core as mf
|
||||||
|
|
||||||
|
|
||||||
|
def test_split_query_with_dash():
|
||||||
|
assert mf._split_query("Daft Punk - Discovery") == ("Daft Punk", "Discovery")
|
||||||
|
|
||||||
|
|
||||||
|
def test_split_query_no_dash():
|
||||||
|
assert mf._split_query("Daft Punk") == ("Daft Punk", None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_split_query_splits_on_first_dash_only():
|
||||||
|
assert mf._split_query("A - B - C") == ("A", "B - C")
|
||||||
|
|
||||||
|
|
||||||
|
def test_split_query_strips_whitespace():
|
||||||
|
assert mf._split_query(" Daft Punk - Discovery ") == ("Daft Punk", "Discovery")
|
||||||
Reference in New Issue
Block a user