Skip to content

Feature/metadata review fixes - #14

Merged
ByteMe6 merged 8 commits into
masterfrom
feature/metadata-review-fixes
Nov 15, 2026
Merged

ByteMe6 merged 8 commits into
masterfrom
feature/metadata-review-fixes

Conversation

@ByteMe6

@ByteMe6 ByteMe6 commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Summary

Post-implementation review fixes for the free metadata sources work
(feature/free-metadata-sources). This PR only fixes demonstrated defects,
adds regression tests and updates the affected docs. The provider
architecture, default priority and rate limits are unchanged.

Base: 0e0ade7 (tip of feature/free-metadata-sources)

Defects fixed

1. CLI selection could not override configuration (critical)

build_source_config() merged disable_sources from the config file with CLI
values into one set and always subtracted it, so -s deezer could not enable
Deezer when the config had disable_sources = deezer or
deezer_enabled = false. Config disabling also wrongly blocked the temporary
VocaDB promotion, and a CLI disable did not always beat a CLI enable.

Now: CLI > config.ini > defaults. A CLI -s selection overrides conflicting
config disabling for the selected providers; an explicit CLI disable
(--disable-sources, --provider-opt NAME.enabled=false) wins over a CLI
selection; the config file is never rewritten.

2. match_threshold / title_threshold silently clamped (critical)

threshold_value() used min(1.0, max(0.0, n)), so 1.5, NaN, +inf and
-inf were coerced instead of rejected. Now only finite values in 0.0–1.0
are accepted; everything else fails with a clear error, consistently from CLI,
config and defaults.

3. min_interval accepted non-finite values (critical)

parse_interval() only rejected negatives. nan, inf and -inf reached the
rate limiter. Now they are rejected; 0.0 is still valid.

4. --delay accepted NaN/±inf (critical)

Only delay < 0 was checked, so --delay=nan reached time.sleep and raised
a traceback. Now non-finite delays exit with a clear error.

5. Artwork format did not match the extension or MIME type (critical)

PNG/GIF/WebP signatures were accepted, but downloads were always saved as
cover.jpg and embedded with mime="image/jpeg" (and
MP4Cover.FORMAT_JPEG). Now the format is detected from the image signature
(JPEG/PNG/GIF/WebP), the saved extension and the embedded MIME type match the
actual bytes, and the HTTP Content-Type header is ignored in favour of the
signature. Invalid/empty responses and header-vs-signature mismatches are
rejected. No new dependencies and no image conversion. MP4 cover art only
supports JPEG/PNG, so GIF/WebP are skipped for .m4a instead of being
mislabelled.

6. A worse result could overwrite a better cache entry (high)

MetadataCache.set() stored any dict. An incomplete result (title missing) or
a lower-scored result could replace a usable entry for the same provider. Now
incomplete results are refused and a better entry is not replaced by a worse
one; unrelated cache entries are untouched.

Tests

Added regression tests covering: config-vs-CLI precedence (all combinations),
none, YouTube enabled/disabled via CLI and config, disabled providers never
queried, numeric validation (0.0, 1.0, mid-range, negative, >1.0, NaN, ±inf,
invalid strings, provider intervals, CLI and config), image format detection and
extension/MIME correctness for JPEG/PNG/GIF/WebP (including Content-Type
mismatch and invalid bytes), M4A GIF/WebP handling, cache overwrite protection,
and non-finite --delay.

All network access is mocked; no live APIs and no Spotify credentials required.
.venv/bin/python -m pytest -q → 323 passed (was 232)
.venv/bin/python -m py_compile trackfetch.py → OK
.venv/bin/python trackfetch.py --help → OK
.venv/bin/python trackfetch.py --list-sources → OK
git diff --check → clean

Documentation

README.md, README.ru.md, README.uk.md, docs/tldr/trackfetch.md and
CHANGELOG.md updated to describe CLI precedence, source disabling, numeric
validation, image format handling and the YouTube audio dependency.

Compatibility

Python 3.10+, no new dependencies. The audio pipeline and provider adapters are
unchanged.

Known limitations (unchanged)

  • Disabling YouTube also disables audio downloads: YouTube is the only audio
    source. Splitting audio from artwork fallback would be an architectural change
    and was intentionally left out.
  • .m4a cannot embed GIF/WebP, so such artwork is skipped for that container
    rather than converted.

CLI metadata selections now override conflicting config disabling, while explicit CLI disables still win. Thresholds and provider intervals reject non-finite and out-of-range values instead of clamping them. Downloaded artwork is detected by signature so extensions and embedded MIME types match JPEG, PNG, GIF or WebP bytes. Incomplete or lower-scored cache results no longer replace better entries.
A NaN or infinite --delay now exits with a clear error instead of reaching time.sleep and triggering a traceback.
Name the resolved disable sets explicitly and make the config-vs-CLI precedence readable. Keep download_cover writing to the path it is given and let download_best_cover derive the extension from the bytes on disk.
Remove dead imports and overlong/sorting issues flagged by ruff, and add tests for real error-handling and validation branches (provider malformed responses, cover-art fallbacks, Spotify auth failures, cache corruption, config path errors). No existing assertion is changed.
@ByteMe6
ByteMe6 merged commit fdaca7d into master Nov 15, 2026
9 checks passed
@ByteMe6
ByteMe6 deleted the feature/metadata-review-fixes branch November 15, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant