mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
add optional tidal atmos preference with immersive fallback
This commit is contained in:
@@ -160,3 +160,86 @@ func TestGetMetadataArtistPaginatesAlbums(t *testing.T) {
|
||||
t.Fatalf("albums len = %d, want 102", len(items))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDownloadablePrefersAtmosWhenEnabled(t *testing.T) {
|
||||
var calls []string
|
||||
allImmersive := true
|
||||
var ts *httptest.Server
|
||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/v1/tracks/42":
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"id": 42, "audioModes": []any{"DOLBY_ATMOS", "STEREO"}, "mediaMetadata": map[string]any{"tags": []any{"LOSSLESS", "DOLBY_ATMOS"}}})
|
||||
case "/v1/tracks/42/playbackinfopostpaywall":
|
||||
if r.URL.Query().Get("immersiveaudio") != "true" {
|
||||
allImmersive = false
|
||||
}
|
||||
aq := r.URL.Query().Get("audioquality")
|
||||
calls = append(calls, aq)
|
||||
manifest := map[string]any{"urls": []string{ts.URL + "/stereo.m3u8"}, "codecs": "flac"}
|
||||
if aq == "HI_RES" {
|
||||
manifest = map[string]any{"urls": []string{ts.URL + "/atmos.m3u8"}, "codecs": "ec-3", "audioMode": "DOLBY_ATMOS"}
|
||||
}
|
||||
b, _ := json.Marshal(manifest)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"manifest": base64.StdEncoding.EncodeToString(b), "audioMode": manifest["audioMode"]})
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
cfgData := config.DefaultConfigData()
|
||||
cfgData.Tidal.AccessToken = "token"
|
||||
cfgData.Tidal.CountryCode = "US"
|
||||
cfgData.Tidal.PreferAtmos = true
|
||||
c := New(&config.Config{File: cfgData, Session: cfgData})
|
||||
c.loggedIn = true
|
||||
c.baseURL = ts.URL + "/v1"
|
||||
|
||||
d, err := c.GetDownloadable(context.Background(), "42", 3)
|
||||
if err != nil {
|
||||
t.Fatalf("GetDownloadable() err = %v", err)
|
||||
}
|
||||
if d.URL != ts.URL+"/atmos.m3u8" {
|
||||
t.Fatalf("url = %q, want %q", d.URL, ts.URL+"/atmos.m3u8")
|
||||
}
|
||||
if d.Extension != "mka" {
|
||||
t.Fatalf("extension = %q, want mka", d.Extension)
|
||||
}
|
||||
if len(calls) < 2 || calls[0] != "HI_RES_LOSSLESS" || calls[1] != "HI_RES" {
|
||||
t.Fatalf("unexpected audioquality call order: %+v", calls)
|
||||
}
|
||||
if !allImmersive {
|
||||
t.Fatalf("expected immersiveaudio=true on Atmos probing calls")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaybackLooksAtmosFromManifest(t *testing.T) {
|
||||
manifest := map[string]any{"urls": []string{"https://cdn.example/stream.m3u8"}, "codecs": "ec-3"}
|
||||
b, _ := json.Marshal(manifest)
|
||||
resp := map[string]any{"manifest": base64.StdEncoding.EncodeToString(b)}
|
||||
if !playbackLooksAtmos(resp) {
|
||||
t.Fatalf("expected atmos detection from manifest codec")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrackSupportsAtmosFromTags(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v1/tracks/42" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"id": 42, "audioModes": []any{"STEREO"}, "mediaMetadata": map[string]any{"tags": []any{"LOSSLESS", "DOLBY_ATMOS"}}})
|
||||
}))
|
||||
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"
|
||||
|
||||
if !c.trackSupportsAtmos(context.Background(), "42") {
|
||||
t.Fatalf("expected atmos support from mediaMetadata tags")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user