harden deezer quality fallback and metadata handling

Improve Deezer full-quality mode behavior by returning explicit errors when yt-dlp mode fails with fallback disabled, parse structured API errors, and correctly map explicit_lyrics booleans into explicit tags.
This commit is contained in:
2026-04-20 01:07:28 +02:00
parent b5a5368fa8
commit 47b754a216
2 changed files with 102 additions and 4 deletions

View File

@@ -175,7 +175,7 @@ func (c *Client) GetDownloadable(ctx context.Context, item string, _ int) (*prov
return d, nil
}
if !c.cfg.Session.Deezer.LowerQualityIfNotAvailable {
return nil, dlErr
return nil, fmt.Errorf("deezer full-quality mode failed and fallback is disabled: %w", dlErr)
}
}
preview := strings.TrimSpace(stringFromAny(meta["preview"]))
@@ -352,8 +352,15 @@ func (c *Client) apiGet(ctx context.Context, path string, params url.Values) (ma
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("deezer api failed: status=%d body=%s", resp.StatusCode, string(body))
}
if e := stringFromAny(out["error"]); e != "" {
return nil, fmt.Errorf("deezer api error: %s", e)
if errObj, ok := out["error"].(map[string]any); ok {
msg := strings.TrimSpace(stringFromAny(errObj["message"]))
if msg == "" {
msg = strings.TrimSpace(stringFromAny(errObj["type"]))
}
if msg == "" {
msg = "unknown deezer error"
}
return nil, fmt.Errorf("deezer api error: %s", msg)
}
return out, nil
}
@@ -375,7 +382,7 @@ func enrichTrack(track map[string]any) {
track["media_number"] = d
}
}
if v := stringFromAny(track["explicit_lyrics"]); v == "true" {
if boolFromAny(track["explicit_lyrics"]) {
track["explicit"] = true
}
}
@@ -441,6 +448,11 @@ func intFromAny(v any) int {
}
}
func boolFromAny(v any) bool {
b, ok := v.(bool)
return ok && b
}
func runCommand(ctx context.Context, name string, args ...string) ([]byte, error) {
cmd := exec.CommandContext(ctx, name, args...)
b, err := cmd.CombinedOutput()