mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
improve CLI error semantics and soundcloud canonicalization
Auto-upgrade outdated configs on startup, add actionable SSL verification hints in rip error paths, and harden SoundCloud search/metadata with canonical URL handling and richer source IDs.
This commit is contained in:
@@ -3,6 +3,8 @@ package soundcloud
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -28,6 +30,9 @@ func TestGetTrackMetadataAndDownloadable(t *testing.T) {
|
||||
if stringFromAny(meta["title"]) != "Lean On" {
|
||||
t.Fatalf("title = %q, want Lean On", stringFromAny(meta["title"]))
|
||||
}
|
||||
if stringFromAny(meta["id"]) != "https://soundcloud.com/a/b" {
|
||||
t.Fatalf("id = %q, want canonical soundcloud url", stringFromAny(meta["id"]))
|
||||
}
|
||||
|
||||
d, err := c.GetDownloadable(context.Background(), "https://soundcloud.com/a/b", 0)
|
||||
if err != nil {
|
||||
@@ -92,6 +97,44 @@ func TestSearchTrack(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchPlaylist(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="/a/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/a/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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginShowsYtDlpHint(t *testing.T) {
|
||||
cfgData := config.DefaultConfigData()
|
||||
c := New(&config.Config{File: cfgData, Session: cfgData})
|
||||
@@ -104,3 +147,33 @@ func TestLoginShowsYtDlpHint(t *testing.T) {
|
||||
t.Fatalf("expected yt-dlp hint in error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackMetadataIncludesExplicitAndISRC(t *testing.T) {
|
||||
meta := trackMetadataFromInfo("https://soundcloud.com/a/b", map[string]any{
|
||||
"title": "T",
|
||||
"uploader": "U",
|
||||
"isrc": "US123",
|
||||
"id": "9876",
|
||||
"webpage_url": "https://soundcloud.com/a/b?si=abc",
|
||||
"age_limit": float64(18),
|
||||
"thumbnail": "https://img",
|
||||
"upload_date": "20240101",
|
||||
})
|
||||
if stringFromAny(meta["isrc"]) != "US123" {
|
||||
t.Fatalf("isrc = %q, want US123", stringFromAny(meta["isrc"]))
|
||||
}
|
||||
explicit, _ := meta["explicit"].(bool)
|
||||
if !explicit {
|
||||
t.Fatalf("expected explicit=true")
|
||||
}
|
||||
if stringFromAny(meta["source_track_id"]) != "9876" {
|
||||
t.Fatalf("source_track_id = %q, want 9876", stringFromAny(meta["source_track_id"]))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanonicalSoundcloudURL(t *testing.T) {
|
||||
got := canonicalSoundcloudURL(map[string]any{"webpage_url": "https://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