initial Go port of streamrip

This commit is contained in:
2026-04-19 21:11:38 +02:00
commit 97e8b758b3
32 changed files with 7008 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package download
import (
"context"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
)
func TestDownloaderFile(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("abc123"))
}))
defer ts.Close()
d := New()
out := filepath.Join(t.TempDir(), "x", "a.bin")
if err := d.File(context.Background(), ts.URL, out); err != nil {
t.Fatalf("File() error = %v", err)
}
b, err := os.ReadFile(out)
if err != nil {
t.Fatalf("ReadFile() error = %v", err)
}
if string(b) != "abc123" {
t.Fatalf("contents = %q, want %q", string(b), "abc123")
}
}
func TestManifestDetection(t *testing.T) {
if !isManifestResponse("application/dash+xml", []byte("x")) {
t.Fatalf("expected dash content-type to be manifest")
}
if !isManifestResponse("application/octet-stream", []byte("<?xml version='1.0'?><MPD></MPD>")) {
t.Fatalf("expected MPD XML body to be manifest")
}
if !isManifestResponse("text/plain", []byte("#EXTM3U\n#EXT-X-VERSION:3")) {
t.Fatalf("expected HLS body to be manifest")
}
if isManifestResponse("audio/flac", []byte("fLaC")) {
t.Fatalf("did not expect flac to be manifest")
}
}