fix: zero-pad track numbers and show warning count in summary
This commit is contained in:
@@ -3,6 +3,7 @@ package deezer
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/flytam/filenamify"
|
"github.com/flytam/filenamify"
|
||||||
)
|
)
|
||||||
@@ -54,8 +55,12 @@ func (s *Song) GetFileName(resourceType, mediaFormat string) string {
|
|||||||
|
|
||||||
prefix := ""
|
prefix := ""
|
||||||
if resourceType == "album" {
|
if resourceType == "album" {
|
||||||
|
if n, err := strconv.Atoi(s.TrackNumber); err == nil {
|
||||||
|
prefix = fmt.Sprintf("%02d. ", n)
|
||||||
|
} else {
|
||||||
prefix = s.TrackNumber + ". "
|
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)
|
||||||
fileName, _ = filenamify.Filenamify(fileName, filenamify.Options{MaxLength: 255})
|
fileName, _ = filenamify.Filenamify(fileName, filenamify.Options{MaxLength: 255})
|
||||||
|
|||||||
@@ -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,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user