feat: download artist's top tracks with --limit flag
This commit is contained in:
@@ -57,6 +57,8 @@ func (c *Client) Run(ctx context.Context, opts Options, id string) error {
|
||||
resource = &deezer.Album{}
|
||||
case "playlist":
|
||||
resource = &deezer.Playlist{}
|
||||
case "artist":
|
||||
resource = &deezer.Artist{}
|
||||
default:
|
||||
return fmt.Errorf("unsupported resource type: %s", c.resourceType)
|
||||
}
|
||||
@@ -69,6 +71,10 @@ func (c *Client) Run(ctx context.Context, opts Options, id string) error {
|
||||
if len(songs) == 0 {
|
||||
return fmt.Errorf("%s has no songs", c.resourceType)
|
||||
}
|
||||
if opts.Limit > 0 && len(songs) > opts.Limit {
|
||||
songs = songs[:opts.Limit]
|
||||
resource.SetSongs(songs)
|
||||
}
|
||||
|
||||
rootOutputDir := c.appConfig.OutputDir
|
||||
resourceOutputDir := resource.GetOutputDir(rootOutputDir)
|
||||
|
||||
@@ -16,12 +16,16 @@ type Options struct {
|
||||
Quality string
|
||||
Timeout time.Duration
|
||||
BPM bool
|
||||
Limit int
|
||||
}
|
||||
|
||||
func (o *Options) Validate() error {
|
||||
if !validQualities[o.Quality] {
|
||||
return fmt.Errorf("invalid quality option: %s", o.Quality)
|
||||
}
|
||||
if o.Limit < 0 {
|
||||
return fmt.Errorf("limit must be a non-negative integer")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user