From c2b4fcfa11766b6f16fe5e85e54c6472d1bb6377 Mon Sep 17 00:00:00 2001 From: Mathis Maquenne <124215603+mathismqn@users.noreply.github.com> Date: Wed, 10 Sep 2025 11:10:52 +0200 Subject: [PATCH] feat(cli): simplify output for individual songs --- cmd/download.go | 9 ++++----- internal/deezer/client.go | 13 ++++++------- internal/deezer/track.go | 6 +----- internal/downloader/client.go | 24 ++++++++++++++++-------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/cmd/download.go b/cmd/download.go index 52cf653..008e121 100644 --- a/cmd/download.go +++ b/cmd/download.go @@ -78,12 +78,11 @@ func newDownloadCmd(resourceType string) *cobra.Command { }, } - if resourceType == "artist" { - cmd.Flags().IntVarP(&opts.Limit, "limit", "l", 10, "number of songs to download") + switch resourceType { + case "artist": cmd.Short = "Download top songs from an artist" - } - - if resourceType == "track" { + cmd.Flags().IntVarP(&opts.Limit, "limit", "l", 10, "number of songs to download") + case "track": cmd.Short = "Download a single track" } diff --git a/internal/deezer/client.go b/internal/deezer/client.go index 7b7d5fa..b276900 100644 --- a/internal/deezer/client.go +++ b/internal/deezer/client.go @@ -77,18 +77,17 @@ func (c *Client) FetchResource(ctx context.Context, resource Resource, id string return err } - if strings.Contains(string(body), `"DATA_ERROR":"playlist::getData"`) { + switch { + case strings.Contains(string(body), `"DATA_ERROR":"playlist::getData"`): return fmt.Errorf("invalid playlist ID") - } - if strings.Contains(string(body), `"DATA_ERROR":"album::getData"`) { + case strings.Contains(string(body), `"DATA_ERROR":"album::getData"`): return fmt.Errorf("invalid album ID") - } - if strings.Contains(string(body), `"DATA_ERROR":"artist::getData"`) { + case strings.Contains(string(body), `"DATA_ERROR":"artist::getData"`): return fmt.Errorf("invalid artist ID") - } - if strings.Contains(string(body), `"DATA_ERROR":"song::getData"`) { + case strings.Contains(string(body), `"DATA_ERROR":"song::getData"`): return fmt.Errorf("invalid track ID") } + if strings.Contains(string(body), `"results":{}`) { return fmt.Errorf("unexpected response") } diff --git a/internal/deezer/track.go b/internal/deezer/track.go index 4f1e180..d110b8d 100644 --- a/internal/deezer/track.go +++ b/internal/deezer/track.go @@ -57,11 +57,7 @@ func (t *Track) GetSongs() []*Song { return []*Song{t.Results.Data} } -func (t *Track) SetSongs(songs []*Song) { - if len(songs) > 0 { - t.Results.Data = songs[0] - } -} +func (t *Track) SetSongs(songs []*Song) {} func (t *Track) GetOutputDir(outputDir string) string { if t.Results.Data == nil { diff --git a/internal/downloader/client.go b/internal/downloader/client.go index 19f17d5..cfbb430 100644 --- a/internal/downloader/client.go +++ b/internal/downloader/client.go @@ -75,6 +75,9 @@ func (c *Client) Run(ctx context.Context, opts Options, id string) error { songs := resource.GetSongs() if len(songs) == 0 { + if c.resourceType == "track" { + return fmt.Errorf("track with ID %s not found", id) + } return fmt.Errorf("%s has no songs", c.resourceType) } if c.resourceType == "artist" && len(songs) > opts.Limit { @@ -89,7 +92,9 @@ func (c *Client) Run(ctx context.Context, opts Options, id string) error { } startTime := time.Now() - fmt.Printf("%s\n\nStarting download...\n\n", resource) + if c.resourceType != "track" { + fmt.Printf("%s\n\nStarting download...\n\n", resource) + } downloaded := 0 skipped := 0 @@ -147,7 +152,9 @@ func (c *Client) Run(ctx context.Context, opts Options, id string) error { if downloaded > 0 || failed > 0 { c.Logger.Infof("Playlist %s (%s): %d downloaded, %d skipped, %d failed\n", resource.GetTitle(), id, downloaded, skipped, failed) } - fmt.Printf(` + + if c.resourceType != "track" { + fmt.Printf(` ================== [ Summary ] ================== Downloaded: %d Skipped: %d @@ -156,12 +163,13 @@ Elapsed time: %s Files saved to: %s ================================================= `, - downloaded, - skipped, - failed, - time.Since(startTime).Round(time.Second), - resourceOutputDir, - ) + downloaded, + skipped, + failed, + time.Since(startTime).Round(time.Second), + resourceOutputDir, + ) + } return nil }