feat: resolve_link_hits + handle_link — Odesli link -> Lidarr-first flow
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -86,3 +86,60 @@ def test_is_direct_url_other_platforms_false():
|
||||
|
||||
def test_is_direct_url_youtube_playlist_true():
|
||||
assert mf._is_direct_url("https://www.youtube.com/playlist?list=PLabc")
|
||||
|
||||
|
||||
def _resolved(yt="https://music.youtube.com/watch?v=YYY"):
|
||||
return mf.Resolved(title="Bloom", artist="ODESZA",
|
||||
thumb="https://img/cover.jpg", youtube_url=yt)
|
||||
|
||||
|
||||
def test_resolve_link_hits_builds_query_and_exact_yt(monkeypatch):
|
||||
monkeypatch.setattr(mf, "odesli_resolve", lambda url: _resolved())
|
||||
lid = mf.Hit(source="lidarr", kind="album", title="A Moment Apart",
|
||||
artist="ODESZA", album="A Moment Apart", year="2017",
|
||||
payload={"album": {"id": 9}})
|
||||
monkeypatch.setattr(mf, "lidarr_search", lambda q, limit: [lid])
|
||||
query, hits = mf.resolve_link_hits("https://open.spotify.com/track/abc", 10)
|
||||
assert query == "ODESZA - Bloom"
|
||||
assert hits[0].source == "lidarr"
|
||||
yt = hits[-1]
|
||||
assert yt.source == "youtube" and yt.kind == "track"
|
||||
assert yt.title == "Bloom" and yt.artist == "ODESZA"
|
||||
assert yt.payload["url"] == "https://music.youtube.com/watch?v=YYY"
|
||||
|
||||
|
||||
def test_resolve_link_hits_no_yt_link_lidarr_only(monkeypatch):
|
||||
monkeypatch.setattr(mf, "odesli_resolve", lambda url: _resolved(yt=""))
|
||||
lid = mf.Hit(source="lidarr", kind="album", title="X", artist="ODESZA",
|
||||
payload={"album": {"id": 9}})
|
||||
monkeypatch.setattr(mf, "lidarr_search", lambda q, limit: [lid])
|
||||
query, hits = mf.resolve_link_hits("https://open.spotify.com/track/abc", 10)
|
||||
assert all(h.source == "lidarr" for h in hits)
|
||||
|
||||
|
||||
def test_resolve_link_hits_odesli_miss_raises(monkeypatch):
|
||||
import pytest
|
||||
monkeypatch.setattr(mf, "odesli_resolve", lambda url: None)
|
||||
with pytest.raises(mf.OdesliError):
|
||||
mf.resolve_link_hits("https://open.spotify.com/track/abc", 10)
|
||||
|
||||
|
||||
def test_handle_link_miss_prints_and_returns(monkeypatch, capsys):
|
||||
monkeypatch.setattr(mf, "odesli_resolve", lambda url: None)
|
||||
mf.handle_link("https://open.spotify.com/track/abc", "/m", "best",
|
||||
False, True, False, 10)
|
||||
out = capsys.readouterr()
|
||||
assert "Couldn't resolve" in (out.err + out.out)
|
||||
|
||||
|
||||
def test_handle_link_dispatches_chosen(monkeypatch):
|
||||
monkeypatch.setattr(mf, "odesli_resolve", lambda url: _resolved())
|
||||
monkeypatch.setattr(mf, "lidarr_search", lambda q, limit: [])
|
||||
chosen = {}
|
||||
monkeypatch.setattr(mf, "pick", lambda hits, q, ni, yf: hits[0])
|
||||
monkeypatch.setattr(mf, "_dispatch_chosen",
|
||||
lambda c, hits, root, quality, dry, lo, sa: chosen.update(c=c, root=root))
|
||||
mf.handle_link("https://open.spotify.com/track/abc", "/m", "best",
|
||||
False, True, False, 10)
|
||||
assert chosen["c"].source == "youtube"
|
||||
assert chosen["root"] == "/m"
|
||||
|
||||
Reference in New Issue
Block a user