mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
add CLI parity flags and expand provider support
This brings the Go CLI closer to upstream behavior with global flag handling and clearer resolve failures, while adding Tidal video downloads plus initial Deezer and SoundCloud no-account flows for broader end-to-end coverage.
This commit is contained in:
@@ -2,6 +2,7 @@ package tidal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -50,3 +51,50 @@ func TestSearch(t *testing.T) {
|
||||
t.Fatalf("pages = %d", len(pages))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetVideoDownloadable(t *testing.T) {
|
||||
var server *httptest.Server
|
||||
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/v1/sessions":
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"countryCode": "US", "userId": 123})
|
||||
case "/v1/videos/42/playbackinfopostpaywall":
|
||||
manifest := map[string]any{"urls": []string{server.URL + "/master.m3u8"}}
|
||||
b, _ := json.Marshal(manifest)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"manifest": base64.StdEncoding.EncodeToString(b)})
|
||||
case "/master.m3u8":
|
||||
_, _ = w.Write([]byte("#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=1000,CODECS=\"avc1.42E01E,mp4a.40.2\",RESOLUTION=640x360\nlow/stream.m3u8\n#EXT-X-STREAM-INF:BANDWIDTH=2000,CODECS=\"avc1.4D401F,mp4a.40.2\",RESOLUTION=1280x720\nhi/stream.m3u8\n"))
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
cfgData := config.DefaultConfigData()
|
||||
cfgData.Tidal.AccessToken = "token"
|
||||
cfgData.Tidal.CountryCode = "US"
|
||||
c := New(&config.Config{File: cfgData, Session: cfgData})
|
||||
c.baseURL = server.URL + "/v1"
|
||||
|
||||
if err := c.Login(context.Background()); err != nil {
|
||||
t.Fatalf("login err = %v", err)
|
||||
}
|
||||
d, err := c.GetVideoDownloadable(context.Background(), "42")
|
||||
if err != nil {
|
||||
t.Fatalf("GetVideoDownloadable() err = %v", err)
|
||||
}
|
||||
if d.Extension != "mp4" {
|
||||
t.Fatalf("extension = %q, want mp4", d.Extension)
|
||||
}
|
||||
if d.URL != server.URL+"/hi/stream.m3u8" {
|
||||
t.Fatalf("url = %q, want %q", d.URL, server.URL+"/hi/stream.m3u8")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBestHLSVariantURLFallsBackToMaster(t *testing.T) {
|
||||
master := "https://example.com/master.m3u8"
|
||||
got := bestHLSVariantURL(master, "#EXTM3U\n#comment")
|
||||
if got != master {
|
||||
t.Fatalf("url = %q, want %q", got, master)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user