harden qobuz and downloader reliability edge cases

This commit is contained in:
2026-04-21 18:54:10 +02:00
parent 0161c01a4c
commit de4e561377
8 changed files with 424 additions and 35 deletions

View File

@@ -152,6 +152,51 @@ func TestSearchPlaylist(t *testing.T) {
}
}
func TestSearchPlaylistAcceptsDotsInPath(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/search/sets" {
_, _ = w.Write([]byte(`<html><body><a href="/artist.name/sets/road.trip">x</a></body></html>`))
return
}
w.WriteHeader(http.StatusNotFound)
}))
defer ts.Close()
cfgData := config.DefaultConfigData()
c := New(&config.Config{File: cfgData, Session: cfgData})
c.loggedIn = true
c.http = ts.Client()
origBase := soundcloudSearchBaseURL
soundcloudSearchBaseURL = ts.URL
defer func() { soundcloudSearchBaseURL = origBase }()
c.run = func(_ context.Context, _ string, args ...string) ([]byte, error) {
joined := strings.Join(args, " ")
if strings.Contains(joined, "https://soundcloud.com/artist.name/sets/road.trip") {
return []byte(`{"title":"Road Trip","uploader":"User","entries":[{"webpage_url":"https://soundcloud.com/a/t1"}]}`), nil
}
return nil, fmt.Errorf("unexpected args: %v", args)
}
pages, err := c.Search(context.Background(), "playlist", "road trip", 5)
if err != nil {
t.Fatalf("Search() error = %v", err)
}
if len(pages) != 1 {
t.Fatalf("pages len = %d, want 1", len(pages))
}
items := asAnySlice(pages[0]["items"])
if len(items) != 1 {
t.Fatalf("items len = %d, want 1", len(items))
}
item0, ok := items[0].(map[string]any)
if !ok {
t.Fatalf("expected first item map")
}
if stringFromAny(item0["id"]) != "https://soundcloud.com/artist.name/sets/road.trip" {
t.Fatalf("playlist search id not canonical: %q", stringFromAny(item0["id"]))
}
}
func TestLoginShowsYtDlpHint(t *testing.T) {
cfgData := config.DefaultConfigData()
c := New(&config.Config{File: cfgData, Session: cfgData})
@@ -197,3 +242,10 @@ func TestCanonicalSoundcloudURL(t *testing.T) {
t.Fatalf("canonical url = %q, want %q", got, "https://soundcloud.com/a/b")
}
}
func TestCanonicalSoundcloudURLAcceptsSubdomain(t *testing.T) {
got := canonicalSoundcloudURL(map[string]any{"webpage_url": "https://m.soundcloud.com/a/b/?si=x#frag"})
if got != "https://soundcloud.com/a/b" {
t.Fatalf("canonical url = %q, want %q", got, "https://soundcloud.com/a/b")
}
}