mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-10-16 22:07:30 +02:00
improve lastfm playlist parity and fallback resolution
Queue resolved last.fm tracks as playlist media to preserve playlist semantics, and add a robust mirror-based parser fallback for last.fm temporary unavailable responses while keeping track order and duplicates.
This commit is contained in:
1 parent
47b754a216
commit
0748d5a325
3 files changed
+260
-14
No files matched your search
@@ -166,3 +166,41 @@ func TestNormalizeCodecRejectsUnknown(t *testing.T) {
|
||||
t.Fatalf("expected error for unsupported codec")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupLastFMResolvedTracksBySourcePreservesOrderAndDuplicates(t *testing.T) {
|
||||
resolved := []resolvedLastFMTrack{
|
||||
{Source: "tidal", ID: "1"},
|
||||
{Source: "tidal", ID: "1"},
|
||||
{Source: "qobuz", ID: "2"},
|
||||
{Source: "tidal", ID: "3"},
|
||||
{Source: "", ID: "4"},
|
||||
}
|
||||
groups := groupLastFMResolvedTracksBySource(resolved)
|
||||
if len(groups["tidal"]) != 3 {
|
||||
t.Fatalf("tidal ids len = %d, want 3", len(groups["tidal"]))
|
||||
}
|
||||
if len(groups["qobuz"]) != 1 {
|
||||
t.Fatalf("qobuz ids len = %d, want 1", len(groups["qobuz"]))
|
||||
}
|
||||
if groups["tidal"][0] != "1" || groups["tidal"][1] != "1" || groups["tidal"][2] != "3" {
|
||||
t.Fatalf("unexpected tidal ordering: %+v", groups["tidal"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractLastFMTracksFromMirrorMarkdown(t *testing.T) {
|
||||
md := `Title: My Playlist | user playlists | Last.fm
|
||||
| Play | Image | Loved | Name | Artist name | Buy | Options | Duration |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| [Play track](https://x) | [img](https://i) | x | [Song A](https://a) | [Artist A](https://aa) | | | 3:00 |
|
||||
| [Play track](https://x) | [img](https://i) | x | [Song B](https://b) | [Artist B](https://bb) | | | 4:00 |`
|
||||
title, tracks := extractLastFMTracksFromMirrorMarkdown(md)
|
||||
if title != "My Playlist" {
|
||||
t.Fatalf("title = %q, want %q", title, "My Playlist")
|
||||
}
|
||||
if len(tracks) != 2 {
|
||||
t.Fatalf("tracks len = %d, want 2", len(tracks))
|
||||
}
|
||||
if tracks[0].Title != "Song A" || tracks[0].Artist != "Artist A" {
|
||||
t.Fatalf("unexpected first track: %+v", tracks[0])
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user