fix: zero-pad track numbers and show warning count in summary
This commit is contained in:
@@ -3,6 +3,7 @@ package deezer
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/flytam/filenamify"
|
||||
)
|
||||
@@ -54,8 +55,12 @@ func (s *Song) GetFileName(resourceType, mediaFormat string) string {
|
||||
|
||||
prefix := ""
|
||||
if resourceType == "album" {
|
||||
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, _ = filenamify.Filenamify(fileName, filenamify.Options{MaxLength: 255})
|
||||
|
||||
@@ -22,6 +22,7 @@ type downloadStats struct {
|
||||
downloaded int
|
||||
skipped int
|
||||
failed int
|
||||
warnings int
|
||||
}
|
||||
|
||||
type progressTracker struct {
|
||||
@@ -71,6 +72,9 @@ func (pt *progressTracker) handleResult(index int, song *deezer.Song, result dow
|
||||
}
|
||||
|
||||
pt.stats.downloaded++
|
||||
if len(result.warnings) > 0 {
|
||||
pt.stats.warnings++
|
||||
}
|
||||
pt.logger.Infof("Downloaded %s - %s\n", song.Artist, songTitle)
|
||||
|
||||
symbol := "✔"
|
||||
@@ -92,11 +96,15 @@ func (pt *progressTracker) printSummary(resourceTitle, resourceID, outputDir str
|
||||
}
|
||||
|
||||
if pt.resourceType != "track" {
|
||||
warningsLine := ""
|
||||
if pt.stats.warnings > 0 {
|
||||
warningsLine = fmt.Sprintf("\nWarnings: %d", pt.stats.warnings)
|
||||
}
|
||||
fmt.Printf(`
|
||||
================== [ Summary ] ==================
|
||||
Downloaded: %d
|
||||
Skipped: %d
|
||||
Failed: %d
|
||||
Failed: %d%s
|
||||
Elapsed time: %s
|
||||
Files saved to: %s
|
||||
=================================================
|
||||
@@ -104,6 +112,7 @@ Files saved to: %s
|
||||
pt.stats.downloaded,
|
||||
pt.stats.skipped,
|
||||
pt.stats.failed,
|
||||
warningsLine,
|
||||
elapsed.Round(time.Second),
|
||||
outputDir,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user