Duplicated helpers
cmd/rip had its own copies of six helpers that already existed in
internal/jsonutil: asString (StringFromAny), searchInt (IntFromAny),
nestedSearchInt and nestedSearchString (NestedAny/NestedString),
firstNonEmpty (FirstNonEmpty) and firstPositiveInt. firstPositiveInt was
duplicated a third and fourth time in provider/yandex and provider/beatport,
so it moves into jsonutil alongside the rest. jsonutil is back to 100%
coverage.
searchBool is deliberately left alone, with a comment saying why: it accepts
only a real bool, and switching it to jsonutil.BoolFromAny would start
coercing strings and numbers, changing how search results get labelled.
config auto-upgrade is no longer destructive
UpgradeOutdated re-serializes the whole config from the parsed struct, so any
key this version does not know about is dropped, and it runs automatically
from run() without prompting. It now copies the original to
<path>.bak-<unixtime> (0600, since it holds the same credentials) and
validates the result before writing. It returns the backup path so the CLI
can tell the user where it went. The comment states plainly that this is a
version stamp rather than a migration framework.
cmd/rip tests
The command bodies are testable now that they are functions returning exit
codes rather than arms of a switch that called os.Exit. Covers the usage
errors for every command, the quality floor on `rip id`, config path output,
the --version flag, and that applyQualityOverride reaches all six sources and
clamps only the two with a floor. cmd/rip coverage 17% -> 26%.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The repo had no README, Makefile, CI, linter config or version string.
- README.md: requirements (ffmpeg/ffprobe, plus yt-dlp for SoundCloud), build,
the per-source credentials table, usage, the quality scale and the download
database's migration behaviour. Every claim was checked against the code
rather than written from memory, which is how the quality-range bug below was
found. It also records the two deferred refactors (no shared HTTP layer, and
metadata as map[string]any) so they are documented rather than lore, and
notes that there is no LICENSE file.
- Makefile: build, install, test, race, cover, fmt, fmt-check, vet, lint,
check, clean, help. `make build` stamps version/commit/date via -ldflags.
- .github/workflows/ci.yml: gofmt, vet, build, test and test -race, plus a
lint job. The linter is intentionally unpinned, with a comment: a
golangci-lint built against an older Go cannot analyse a go1.25 module, which
is the same reason a locally installed staticcheck built with go1.24 cannot
run here.
- .golangci.yml: standard set plus bodyclose, errorlint, nilerr and
govet/copylocks. copylocks matters now that config.Config carries a mutex;
bodyclose and errorlint target defects this codebase actually has.
- `rip --version` / `-V`, documented in the help output, falling back to the
VCS revision the toolchain embeds for `go install` builds.
Fixes a bug introduced in the previous commit: Validate capped deezer quality
at 2 and soundcloud at 1, but config.toml.example documents deezer as 2/3/4 and
the global -q flag accepts 0-4, so a documented config would have failed to
load. deezer's buildFormatPriority treats anything >= 2 as FLAC and soundcloud
ignores the value entirely, so the real ceiling is 4 everywhere; only the Qobuz
and Beatport floor of 1 is a genuine constraint. Pinned with a test that walks
the whole documented range.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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>
- Extracted common JSON parsing helpers into internal/jsonutil
- Removed duplicated helper functions from provider packages
- Removed dead code in internal/app/app.go and downloader.go
- Replaced deprecated strings.Title with jsonutil.TitleCase
- Added graceful shutdown with signal handling in main.go
- Split monolithic cmd/rip/main.go into args.go, helpers.go, lastfm.go, search.go