feat(cli): add --strict flag to fail track download if quality is unavailable
This commit is contained in:
@@ -179,6 +179,9 @@ func (c *Client) downloadSong(ctx context.Context, resource deezer.Resource, son
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get media format: %w", err)
|
||||
}
|
||||
if opts.Strict && strings.ToLower(mediaFormat) != opts.Quality {
|
||||
return nil, fmt.Errorf("requested quality '%s' not available", opts.Quality)
|
||||
}
|
||||
|
||||
if path, skip := c.shouldSkipDownload(ctx, song.ID, mediaFormat); skip {
|
||||
return nil, SkipError{Path: path}
|
||||
|
||||
@@ -14,16 +14,23 @@ var validQualities = map[string]bool{
|
||||
type Options struct {
|
||||
Quality string
|
||||
Timeout time.Duration
|
||||
BPM bool
|
||||
Limit int
|
||||
BPM bool
|
||||
Strict bool
|
||||
}
|
||||
|
||||
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")
|
||||
if o.Timeout <= 0 {
|
||||
return fmt.Errorf("timeout must be a positive duration")
|
||||
}
|
||||
if o.Limit <= 0 {
|
||||
return fmt.Errorf("limit must be a positive integer")
|
||||
}
|
||||
if o.Limit > 100 {
|
||||
return fmt.Errorf("limit must not exceed 100")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user