feat(music): list and select playlist songs by their position

This commit is contained in:
imSp4rky
2026-11-30 12:39:51 -07:00
parent 40114fff19
commit 70ace41201
16 changed files with 222 additions and 38 deletions
+19
View File
@@ -146,6 +146,7 @@ def song() -> Song:
artwork_url="https://img.example/song.jpg",
synced_lyrics="[00:01.00]la",
lyrics_suffix=".lrc",
position=7,
)
@@ -398,6 +399,7 @@ REST_SONG = {
"synced_lyrics": "[00:01.00]la",
"lyrics_suffix": ".lrc",
"artwork_url": "https://img.example/song.jpg",
"position": 7,
"music_data": {"release_date": "2022-01-02", "composer": "Example Composer", "comment": "nested"},
}
@@ -783,6 +785,23 @@ def test_build_title_from_rest_song() -> None:
}
def test_a_song_of_an_older_server_has_no_position() -> None:
rebuilt = build_title({k: v for k, v in REST_SONG.items() if k != "position"}, "EXAMPLE", "fallback-id")
assert (rebuilt.position, rebuilt.listing_number) == (None, (1, 3))
@pytest.mark.parametrize("position", [0, -1, "7", 7.5, True, [7]])
def test_build_title_refuses_a_bad_song_position(position: Any) -> None:
with pytest.raises((TypeError, ValueError), match="position"):
build_title({**REST_SONG, "position": position}, "EXAMPLE", "fallback-id")
def test_apply_title_fields_keeps_the_song_position() -> None:
title = song()
apply_title_fields(title, {"position": 9, "genre": "Jazz"})
assert (title.position, title.genre) == (7, "Jazz")
def test_build_title_from_export_meta() -> None:
title = build_title(json_copy(META_EPISODE), "EXAMPLE", "fallback-id")
assert title_fields(title) == {**EPISODE_FIELDS, "data": None, "description": None}