Skip to content

Remove dead code and trim over-built helpers - #132

Merged
zfleeman merged 3 commits into
mainfrom
zf/trim-helpers-129
Oct 22, 2026
Merged

zfleeman merged 3 commits into
mainfrom
zf/trim-helpers-129

Conversation

@zfleeman

@zfleeman zfleeman commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Closes #129.

A cleanup pass that makes the code shorter and easier to follow. The only change users will notice is that a bad --astreams value now stops the run with an error, instead of being logged and ignored. That matches how #121 handles other bad settings.

What changed

  • --astreams parsing (arguments.py): _parse_astreams went from about 50 lines to about 10. It still accepts a comma-separated string or a JSON list from a config file and removes duplicates. Negative, decimal, blank, or non-numeric values now raise a ValueError, and main() shows the message and exits with code 1 (no traceback).
  • CODEC_OVERRIDES (twopass.py): now a flat {codec: {second-pass options}} table. No codec used the "both" or "pass1" sections, so the loop is one update() call, and the test that only patched in a fake "both" entry is gone.
  • versioning.py: rewritten down to what the update notice needs. The pyproject.toml fallback and the unused package_name= and timeout_s= parameters are gone. Versions are compared by their leading numbers (so 0.4.10 is newer than 0.4.9), replacing a helper that also compared the raw strings. A missing install now catches only PackageNotFoundError, and the comment in main() no longer claims the check never delays startup (it waits up to the 1.5 second timeout).
  • Module docstrings: replaced the out-of-date "Functions:" / "Classes:" lists with a one-line summary.
  • red(text) helper (twopass.py): replaces the repeated "\033[31m" + dedent(...).strip() + "\033[0m" pattern in twopass.py and __main__.py. windows.py is left alone, since it must not import other modules.
  • parse_time(value, duration): replaces timestamp_from_percentage. It returns seconds directly, so clip_times no longer turns a percentage into a timestamp string and parses it back.
  • run_pass reuses command_for_display for the failed command, so the error shows a command you can paste into a terminal.
  • Smaller items: FILE_SIZE_MULT = 1 / 1024**2; _normalize_amix_args is inlined in get_args; logging.getLogger().setLevel(logging.INFO) moved from import time into main(); the -a default now comes from FALLBACK_AUDIO_BR so the two 96 kbps values can't drift apart.

Testing

  • uv run pytest --cov: 296 passed, 99.34% coverage.
  • uv run ruff format . && uv run ruff check .: clean.
  • Real encode: ff4d bikes.mp4 --from 10% --to 00:00:15 -s 2 produced a 1.98 MB file.
  • ff4d bikes.mp4 --astreams "0,-1" --dry-run exits with code 1 and prints Invalid --astreams value '0,-1'. ....

@zfleeman
zfleeman merged commit 9c1fa18 into main Oct 22, 2026
11 of 12 checks passed
@zfleeman
zfleeman deleted the zf/trim-helpers-129 branch October 22, 2026 21:15
@zfleeman zfleeman mentioned this pull request Oct 22, 2026
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.

Remove dead code and trim over-built helpers

1 participant