Repository navigation
Closed
Labels
optimizationFix bad/weird codeFix bad/weird code
Description
A read-through of the whole package found a few spots that do more than they need to. Each one makes the code shorter and easier to follow. Only the _parse_astreams change affects users: a bad --astreams value will stop the run instead of being ignored.
Worth doing
- Flatten
CODEC_OVERRIDES(intwopass.py, used in_generate_params). No codec uses the"both"or"pass1"sections. The comment says the table is module-level so a test can patch in a fake"both"entry, which means the code exists only to serve its own test. Make it{codec: {pass 2 extras}}, replace the loop with oneparams["pass2"].update(...), and delete the patching test. - Rewrite
_parse_astreams(inarguments.py). It's 50 lines that accept a list or a string, remove duplicates, skip negative numbers, and log and ignore bad input. Show TwoPass setting errors on the CLI without a traceback #121 made bad settings stop the run with an error, so this should too. About 10 lines can split on commas, convert toint, reject bad or negative values with an error, and remove duplicates withlist(dict.fromkeys(...)). Keep list support, because config files can pass a JSON list. - Shrink
versioning.py. Thepyproject.tomlfallback (_get_version_from_pyproject) never runs, becauseuv runinstalls the package, sometadata.version()always works. Thepackage_name=parameters are never passed. Remove both, along with their tests. - Remove the "Functions:" / "Classes:" lists from module docstrings. They're already out of date (the one in
__main__.pyis missingEncodeJob,progress_seconds, andexit_on_setting_error), and nothing keeps them current. Keep a one-line summary of each module.
Small, optional
FILE_SIZE_MULT = 0.00000095367432can be1 / 1024**2, which makes its 4-line comment unnecessary.clip_timesconverts a percentage to a timestamp string, then parses it back into seconds. Oneparse_time(value, duration) -> floatwould avoid the round trip.run_passbuilds its own command string when it could reusecommand_for_display._normalize_amix_argsis a one-liner, and its docstring describes behavior ("unless amix was explicitly set false") that the code doesn't have. Inline it inget_args.logging.getLogger().setLevel(logging.INFO)runs whentwopass.pyis imported. Move it tomain().- Add a small
red(text)helper for the"\033[31m" + dedent(...).strip() + "\033[0m"pattern. It appears 6 times intwopass.py, once inarguments.py, and once in__main__.py, and saves about 20 lines. Leavewindows.pyalone, since it must not import other modules' setup. - The 96 kbps audio default is written twice:
default=96on the-aflag inarguments.py, andFALLBACK_AUDIO_BR = 96_000intwopass.py(added in Fix MKV crash and read the source audio bitrate from the first track #130). Have the flag use the constant (default=FALLBACK_AUDIO_BR / 1000) so the two can't drift apart.arguments.pyalready imports fromtwopass.py.
Leave as is
- The Flask app defined inside
main(). It reads top to bottom, and pulling it out would be churn. - The same form checks in the browser, Flask, and
TwoPass. Each layer catches a different case (Web UI: check the form in the browser before submitting #102). - The Windows-specific code in
remove_temp_folderandcommand_for_display. Both handle real Windows behavior.
Metadata
Metadata
Assignees
Labels
optimizationFix bad/weird codeFix bad/weird code
Activity