Repository navigation
Feature/metadata review fixes - #14
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 offeature/free-metadata-sources)Defects fixed
1. CLI selection could not override configuration (critical)
build_source_config()mergeddisable_sourcesfrom the config file with CLIvalues into one set and always subtracted it, so
-s deezercould not enableDeezer when the config had
disable_sources = deezerordeezer_enabled = false. Config disabling also wrongly blocked the temporaryVocaDB promotion, and a CLI disable did not always beat a CLI enable.
Now:
CLI > config.ini > defaults. A CLI-sselection overrides conflictingconfig disabling for the selected providers; an explicit CLI disable
(
--disable-sources,--provider-opt NAME.enabled=false) wins over a CLIselection; the config file is never rewritten.
2.
match_threshold/title_thresholdsilently clamped (critical)threshold_value()usedmin(1.0, max(0.0, n)), so1.5,NaN,+infand-infwere coerced instead of rejected. Now only finite values in0.0–1.0are accepted; everything else fails with a clear error, consistently from CLI,
config and defaults.
3.
min_intervalaccepted non-finite values (critical)parse_interval()only rejected negatives.nan,infand-infreached therate limiter. Now they are rejected;
0.0is still valid.4.
--delayacceptedNaN/±inf(critical)Only
delay < 0was checked, so--delay=nanreachedtime.sleepand raiseda 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.jpgand embedded withmime="image/jpeg"(andMP4Cover.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-Typeheader is ignored in favour of thesignature. 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
.m4ainstead of beingmislabelled.
6. A worse result could overwrite a better cache entry (high)
MetadataCache.set()stored any dict. An incomplete result (titlemissing) ora 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 neverqueried, 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.mdandCHANGELOG.mdupdated to describe CLI precedence, source disabling, numericvalidation, 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)
source. Splitting audio from artwork fallback would be an architectural change
and was intentionally left out.
.m4acannot embed GIF/WebP, so such artwork is skipped for that containerrather than converted.