feat: add log hooks

This commit is contained in:
lb-a
2026-05-07 18:45:05 +02:00
parent ef741434cb
commit 04cc56040b
3 changed files with 80 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ import (
"golang.org/x/term"
"streamrip-go/internal/netutil"
"streamrip-go/internal/verbose"
"golang.org/x/crypto/blowfish"
)
@@ -67,6 +68,7 @@ func (d *Downloader) FileVideo(ctx context.Context, sourceURL, outputPath string
}
func (d *Downloader) FileDeezerEncrypted(ctx context.Context, sourceURL, outputPath, trackID string) error {
logDownloadStart(sourceURL, outputPath)
if err := os.MkdirAll(filepath.Dir(outputPath), 0o755); err != nil {
return err
}
@@ -176,6 +178,7 @@ func (d *Downloader) FileDeezerEncrypted(ctx context.Context, sourceURL, outputP
}
func (d *Downloader) file(ctx context.Context, sourceURL, outputPath string, allowProgress bool, includeVideo bool) error {
logDownloadStart(sourceURL, outputPath)
if err := os.MkdirAll(filepath.Dir(outputPath), 0o755); err != nil {
return err
}
@@ -309,6 +312,16 @@ func (d *Downloader) Logf(format string, args ...any) {
fmt.Print(msg)
}
// logDownloadStart emits the source URL and destination filename when the
// user passed -v or higher. The transport-level logger covers the same
// requests at -vv, but this line gives a friendlier per-track summary.
func logDownloadStart(sourceURL, outputPath string) {
if !verbose.Enabled(verbose.V) {
return
}
verbose.Printf(verbose.V, "download %s -> %s\n", sourceURL, filepath.Base(outputPath))
}
func shortenName(name string, max int) string {
if max <= 0 {
return name