mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
harden qobuz and downloader reliability edge cases
This commit is contained in:
@@ -146,7 +146,7 @@ func (c *Client) searchPlaylists(ctx context.Context, query string, limit int) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`/[A-Za-z0-9_-]+/sets/[A-Za-z0-9_-]+`)
|
||||
re := regexp.MustCompile(`/(?:[A-Za-z0-9._-]+)/sets/(?:[A-Za-z0-9._%~-]+)`)
|
||||
paths := re.FindAllString(string(body), -1)
|
||||
if len(paths) == 0 {
|
||||
return []map[string]any{}, nil
|
||||
@@ -435,10 +435,11 @@ func canonicalSoundcloudURL(info map[string]any) string {
|
||||
continue
|
||||
}
|
||||
host := strings.ToLower(strings.TrimPrefix(u.Host, "www."))
|
||||
if host != "soundcloud.com" {
|
||||
if host != "soundcloud.com" && !strings.HasSuffix(host, ".soundcloud.com") {
|
||||
continue
|
||||
}
|
||||
u.Scheme = "https"
|
||||
u.Host = "soundcloud.com"
|
||||
u.RawQuery = ""
|
||||
u.Fragment = ""
|
||||
u.Path = strings.TrimSuffix(u.Path, "/")
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user