mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
fix tidal lossless quality negotiation and atmos format fallback
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
@@ -243,3 +244,75 @@ func TestTrackSupportsAtmosFromTags(t *testing.T) {
|
||||
t.Fatalf("expected atmos support from mediaMetadata tags")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatsForQuality(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
q int
|
||||
atmos bool
|
||||
wants []string
|
||||
}{
|
||||
{name: "low", q: 0, wants: []string{"HEAACV1"}},
|
||||
{name: "high", q: 1, wants: []string{"HEAACV1", "AACLC"}},
|
||||
{name: "lossless", q: 2, wants: []string{"HEAACV1", "AACLC", "FLAC"}},
|
||||
{name: "hires", q: 4, wants: []string{"HEAACV1", "AACLC", "FLAC", "FLAC_HIRES"}},
|
||||
{name: "atmos adds eac3", q: 2, atmos: true, wants: []string{"HEAACV1", "AACLC", "FLAC", "EAC3_JOC"}},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := formatsForQuality(tc.q, tc.atmos)
|
||||
if !reflect.DeepEqual(got, tc.wants) {
|
||||
t.Fatalf("formatsForQuality(%d, atmos=%v) = %#v, want %#v", tc.q, tc.atmos, got, tc.wants)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDownloadableLosslessUsesTrackManifestWhenPlaybackIsAAC(t *testing.T) {
|
||||
var gotFormats string
|
||||
var ts *httptest.Server
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/v1/tracks/42/playbackinfopostpaywall":
|
||||
manifest := map[string]any{"urls": []string{ts.URL + "/aac.m3u8"}, "codecs": "mp4a.40.2"}
|
||||
b, _ := json.Marshal(manifest)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"manifest": base64.StdEncoding.EncodeToString(b)})
|
||||
case "/v2/trackManifests/42":
|
||||
gotFormats = r.URL.Query().Get("formats")
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"data": map[string]any{
|
||||
"attributes": map[string]any{
|
||||
"uri": ts.URL + "/song.flac",
|
||||
"formats": []any{"FLAC"},
|
||||
},
|
||||
},
|
||||
})
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
cfgData := config.DefaultConfigData()
|
||||
cfgData.Tidal.AccessToken = "token"
|
||||
cfgData.Tidal.CountryCode = "US"
|
||||
c := New(&config.Config{File: cfgData, Session: cfgData})
|
||||
c.loggedIn = true
|
||||
c.baseURL = ts.URL + "/v1"
|
||||
c.openAPI = ts.URL + "/v2"
|
||||
|
||||
d, err := c.GetDownloadable(context.Background(), "42", 2)
|
||||
if err != nil {
|
||||
t.Fatalf("GetDownloadable() err = %v", err)
|
||||
}
|
||||
if gotFormats != "HEAACV1,AACLC,FLAC" {
|
||||
t.Fatalf("formats query = %q, want %q", gotFormats, "HEAACV1,AACLC,FLAC")
|
||||
}
|
||||
if d.URL != ts.URL+"/song.flac" {
|
||||
t.Fatalf("url = %q, want %q", d.URL, ts.URL+"/song.flac")
|
||||
}
|
||||
if d.Extension != "flac" {
|
||||
t.Fatalf("extension = %q, want flac", d.Extension)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user