mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-10-16 22:07:30 +02:00
fix: database migration, config validation and provider client defects
Completes the correctness pass. Download database migration no longer destroys dedupe state The pre-source-column migration carried every legacy row over with source='' and then dropped downloads_legacy, while IsDownloaded matched source exactly. The result was that every previously recorded download looked new, the user silently re-downloaded their whole library, and the original rows were gone. Now the file is copied to <path>.bak-<unixtime> first, downloads_legacy is kept, and IsDownloaded falls back to the sourceless rows (over-matching across sources costs a skipped re-download, which is the cheaper error). Schema state is tracked in PRAGMA user_version so later migrations can be ordered explicitly. Databases already migrated by the old code are detected on open. Also enables WAL and a 10s busy_timeout and caps the pool at one connection, so a concurrent reader no longer gets SQLITE_BUSY with no retry, and builds the DSN through url.URL so a path containing '?' is not parsed as query parameters. --quality now applies to every source applyGlobalConfigOverrides set only qobuz, tidal, deezer and soundcloud, so `rip -q 4 url <beatport-url>` was a silent no-op even though qualityForSource reads Yandex and Beatport. All six are set, with the per-source floor applied and reported rather than silently ignored. config: validation and a fixed reset Load checked nothing but misc.version, so a negative max_connections or a bogus conversion codec was accepted and only surfaced mid-rip. Adds Validate() covering per-source quality ranges, max_connections, requests_per_minute and truncate_to, and normalizes the conversion codec from the file through the same path as --codec. `config reset` assigned one value to both Config.File and Config.Session, so their Secrets slices shared a backing array; it now takes separate copies. Tests cover the shipped defaults and config.toml.example, which is how the over-strict artwork max-width bound in the first draft was caught: -1 is the documented "do not downscale" sentinel. soundcloud: use the shared HTTP client It was the only provider constructing its own http.Client, so it silently ignored downloads.verify_ssl and max_connections and bypassed the transport that redacts credentials from -vv logs. It also had no rate limiter at all. qobuz: mobile fallback could not download a long track http.Client.Timeout bounds the whole request including the body read, so the 30s API client aborted any track that took longer than 30s to stream. The body copy now uses a no-timeout client, as internal/download already does. qobuz: HKDF no longer fails silently hexDecodeOrNil discarded its error, so a non-hex app secret keyed HKDF on nil, derived a wrong KEK and produced silently corrupt audio instead of an error. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
9 files changed
+570
-51
No files matched your search
+49
-13
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -124,16 +125,10 @@ func parseGlobalArgs(args []string) (globalOptions, error) {
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// normalizeCodec delegates to config so the --codec flag and a codec set in
|
||||
// the config file are validated by the same rules.
|
||||
func normalizeCodec(raw string) (string, error) {
|
||||
codec := strings.ToUpper(strings.TrimSpace(raw))
|
||||
switch codec {
|
||||
case "ALAC", "FLAC", "MP3", "AAC", "VORBIS":
|
||||
return codec, nil
|
||||
case "OGG":
|
||||
return "VORBIS", nil
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported codec %q (expected ALAC, FLAC, OGG, MP3, AAC)", raw)
|
||||
}
|
||||
return config.NormalizeCodec(raw)
|
||||
}
|
||||
|
||||
func applyGlobalConfigOverrides(cfg *config.Config, opts globalOptions) {
|
||||
@@ -144,10 +139,7 @@ func applyGlobalConfigOverrides(cfg *config.Config, opts globalOptions) {
|
||||
cfg.Session.Database.DownloadsEnabled = false
|
||||
}
|
||||
if opts.qualitySet {
|
||||
cfg.Session.Qobuz.Quality = opts.quality
|
||||
cfg.Session.Tidal.Quality = opts.quality
|
||||
cfg.Session.Deezer.Quality = opts.quality
|
||||
cfg.Session.Soundcloud.Quality = opts.quality
|
||||
applyQualityOverride(cfg, opts.quality)
|
||||
}
|
||||
if opts.codecSet {
|
||||
cfg.Session.Conversion.Enabled = true
|
||||
@@ -161,6 +153,50 @@ func applyGlobalConfigOverrides(cfg *config.Config, opts globalOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
// minQualityForSource is the lowest quality id each source accepts. Qobuz and
|
||||
// Beatport have no equivalent of the "lowest" tier that 0 means elsewhere.
|
||||
var minQualityForSource = map[string]int{
|
||||
"qobuz": 1,
|
||||
"beatport": 1,
|
||||
}
|
||||
|
||||
// applyQualityOverride applies a global -q/--quality to every source.
|
||||
//
|
||||
// It previously set only qobuz, tidal, deezer and soundcloud, so
|
||||
// `rip -q 4 url <beatport-url>` was a silent no-op even though
|
||||
// Main.qualityForSource reads Yandex and Beatport too. Sources with a higher
|
||||
// floor are clamped rather than erroring, because one global flag has to work
|
||||
// across a mixed queue.
|
||||
func applyQualityOverride(cfg *config.Config, quality int) {
|
||||
clamped := map[string]int{}
|
||||
for _, source := range []string{"qobuz", "tidal", "deezer", "soundcloud", "yandex", "beatport"} {
|
||||
q := quality
|
||||
if min, ok := minQualityForSource[source]; ok && q < min {
|
||||
q = min
|
||||
clamped[source] = q
|
||||
}
|
||||
switch source {
|
||||
case "qobuz":
|
||||
cfg.Session.Qobuz.Quality = q
|
||||
case "tidal":
|
||||
cfg.Session.Tidal.Quality = q
|
||||
case "deezer":
|
||||
cfg.Session.Deezer.Quality = q
|
||||
case "soundcloud":
|
||||
cfg.Session.Soundcloud.Quality = q
|
||||
case "yandex":
|
||||
cfg.Session.Yandex.Quality = q
|
||||
case "beatport":
|
||||
cfg.Session.Beatport.Quality = q
|
||||
}
|
||||
}
|
||||
for _, source := range []string{"qobuz", "beatport"} {
|
||||
if q, ok := clamped[source]; ok {
|
||||
fmt.Fprintf(os.Stderr, "note: %s has no quality %d; using %d for %s\n", source, quality, q, source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func errorWithActionableHint(err error, opts globalOptions) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
|
||||
Reference in new issue
Block a user