feat(cli): add --strict flag to fail track download if quality is unavailable

This commit is contained in:
Mathis Maquenne
2025-08-09 19:17:29 +02:00
parent 7154c15cc3
commit 283c5d76e9
3 changed files with 15 additions and 4 deletions
+3
View File
@@ -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}
+10 -3
View File
@@ -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