fix: zero-pad track numbers and show warning count in summary

This commit is contained in:
Mathis Maquenne
2026-03-01 22:29:38 +01:00
parent 08160b0290
commit d50945a7ef
2 changed files with 16 additions and 2 deletions
+6 -1
View File
@@ -3,6 +3,7 @@ package deezer
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv"
"github.com/flytam/filenamify" "github.com/flytam/filenamify"
) )
@@ -54,7 +55,11 @@ func (s *Song) GetFileName(resourceType, mediaFormat string) string {
prefix := "" prefix := ""
if resourceType == "album" { if resourceType == "album" {
prefix = s.TrackNumber + ". " if n, err := strconv.Atoi(s.TrackNumber); err == nil {
prefix = fmt.Sprintf("%02d. ", n)
} else {
prefix = s.TrackNumber + ". "
}
} }
fileName := fmt.Sprintf("%s%s - %s.%s", prefix, s.Artist, s.GetTitle(), ext) fileName := fmt.Sprintf("%s%s - %s.%s", prefix, s.Artist, s.GetTitle(), ext)
+10 -1
View File
@@ -22,6 +22,7 @@ type downloadStats struct {
downloaded int downloaded int
skipped int skipped int
failed int failed int
warnings int
} }
type progressTracker struct { type progressTracker struct {
@@ -71,6 +72,9 @@ func (pt *progressTracker) handleResult(index int, song *deezer.Song, result dow
} }
pt.stats.downloaded++ pt.stats.downloaded++
if len(result.warnings) > 0 {
pt.stats.warnings++
}
pt.logger.Infof("Downloaded %s - %s\n", song.Artist, songTitle) pt.logger.Infof("Downloaded %s - %s\n", song.Artist, songTitle)
symbol := "✔" symbol := "✔"
@@ -92,11 +96,15 @@ func (pt *progressTracker) printSummary(resourceTitle, resourceID, outputDir str
} }
if pt.resourceType != "track" { if pt.resourceType != "track" {
warningsLine := ""
if pt.stats.warnings > 0 {
warningsLine = fmt.Sprintf("\nWarnings: %d", pt.stats.warnings)
}
fmt.Printf(` fmt.Printf(`
================== [ Summary ] ================== ================== [ Summary ] ==================
Downloaded: %d Downloaded: %d
Skipped: %d Skipped: %d
Failed: %d Failed: %d%s
Elapsed time: %s Elapsed time: %s
Files saved to: %s Files saved to: %s
================================================= =================================================
@@ -104,6 +112,7 @@ Files saved to: %s
pt.stats.downloaded, pt.stats.downloaded,
pt.stats.skipped, pt.stats.skipped,
pt.stats.failed, pt.stats.failed,
warningsLine,
elapsed.Round(time.Second), elapsed.Round(time.Second),
outputDir, outputDir,
) )