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:
@@ -11,7 +11,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/vbauerster/mpb/v8"
|
||||
"github.com/vbauerster/mpb/v8/decor"
|
||||
@@ -38,7 +37,7 @@ func NewWithVerifySSL(verifySSL bool) *Downloader {
|
||||
func NewWithOptions(verifySSL bool, showProgress bool) *Downloader {
|
||||
forceProgress := strings.EqualFold(os.Getenv("STREAMRIP_GO_FORCE_PROGRESS"), "1") || strings.EqualFold(os.Getenv("STREAMRIP_GO_FORCE_PROGRESS"), "true")
|
||||
interactive := showProgress && (forceProgress || (term.IsTerminal(int(os.Stderr.Fd())) && strings.ToLower(os.Getenv("TERM")) != "dumb"))
|
||||
d := &Downloader{http: netutil.NewHTTPClient(2*time.Minute, verifySSL), showProgress: interactive}
|
||||
d := &Downloader{http: netutil.NewHTTPClient(0, verifySSL), showProgress: interactive}
|
||||
if interactive {
|
||||
d.progress = mpb.New(mpb.WithWidth(40), mpb.WithOutput(os.Stderr))
|
||||
}
|
||||
@@ -46,14 +45,18 @@ func NewWithOptions(verifySSL bool, showProgress bool) *Downloader {
|
||||
}
|
||||
|
||||
func (d *Downloader) File(ctx context.Context, sourceURL, outputPath string) error {
|
||||
return d.file(ctx, sourceURL, outputPath, true)
|
||||
return d.file(ctx, sourceURL, outputPath, true, false)
|
||||
}
|
||||
|
||||
func (d *Downloader) FileNoProgress(ctx context.Context, sourceURL, outputPath string) error {
|
||||
return d.file(ctx, sourceURL, outputPath, false)
|
||||
return d.file(ctx, sourceURL, outputPath, false, false)
|
||||
}
|
||||
|
||||
func (d *Downloader) file(ctx context.Context, sourceURL, outputPath string, allowProgress bool) error {
|
||||
func (d *Downloader) FileVideo(ctx context.Context, sourceURL, outputPath string) error {
|
||||
return d.file(ctx, sourceURL, outputPath, true, true)
|
||||
}
|
||||
|
||||
func (d *Downloader) file(ctx context.Context, sourceURL, outputPath string, allowProgress bool, includeVideo bool) error {
|
||||
if err := os.MkdirAll(filepath.Dir(outputPath), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -77,7 +80,7 @@ func (d *Downloader) file(ctx context.Context, sourceURL, outputPath string, all
|
||||
peek, _ := reader.Peek(1024)
|
||||
if isManifestResponse(resp.Header.Get("Content-Type"), peek) {
|
||||
_ = resp.Body.Close()
|
||||
return d.streamManifestWithFFmpeg(ctx, sourceURL, outputPath)
|
||||
return d.streamManifestWithFFmpeg(ctx, sourceURL, outputPath, includeVideo)
|
||||
}
|
||||
|
||||
out, err := os.Create(outputPath)
|
||||
@@ -162,7 +165,7 @@ func shortenName(name string, max int) string {
|
||||
return string(r[:max-3]) + "..."
|
||||
}
|
||||
|
||||
func (d *Downloader) streamManifestWithFFmpeg(ctx context.Context, sourceURL, outputPath string) error {
|
||||
func (d *Downloader) streamManifestWithFFmpeg(ctx context.Context, sourceURL, outputPath string, includeVideo bool) error {
|
||||
if _, err := exec.LookPath("ffmpeg"); err != nil {
|
||||
return fmt.Errorf("ffmpeg not found for manifest stream: %w", err)
|
||||
}
|
||||
@@ -171,10 +174,13 @@ func (d *Downloader) streamManifestWithFFmpeg(ctx context.Context, sourceURL, ou
|
||||
"-y",
|
||||
"-protocol_whitelist", "file,http,https,tcp,tls,crypto,data",
|
||||
"-i", sourceURL,
|
||||
"-map", "0:a:0",
|
||||
"-c", "copy",
|
||||
outputPath,
|
||||
}
|
||||
if includeVideo {
|
||||
args = append(args, "-map", "0")
|
||||
} else {
|
||||
args = append(args, "-map", "0:a:0")
|
||||
}
|
||||
args = append(args, "-c", "copy", outputPath)
|
||||
|
||||
cmd := exec.CommandContext(ctx, "ffmpeg", args...)
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
Reference in New Issue
Block a user