feat: update download cmd to use new functions

This commit is contained in:
Mathis Maquenne
2024-10-14 16:21:13 +02:00
parent 258671004f
commit ea9fcead7e
+32 -4
View File
@@ -1,12 +1,40 @@
package cmd package cmd
import "github.com/spf13/cobra" import (
"fmt"
"os"
"github.com/mathismqn/godeez/internal/album"
"github.com/mathismqn/godeez/internal/song"
"github.com/spf13/cobra"
)
var downloadCmd = &cobra.Command{ var downloadCmd = &cobra.Command{
Use: "download [ID]", Use: "download [album_id...]",
Short: "Download a track from Deezer", Short: "Download songs from one or more albums",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// Your code here if len(args) == 0 {
cmd.Help()
return
}
for _, id := range args {
albumData, err := album.GetDataByID(id)
if err != nil {
fmt.Fprintf(os.Stderr, "could not fetch album data: %v\n", err)
continue
}
for _, s := range albumData.Songs.Data {
media, err := song.GetMedia(s)
if err != nil {
fmt.Fprintf(os.Stderr, "could not fetch media data: %v\n", err)
continue
}
fmt.Println(media)
}
}
}, },
} }