summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2026-02-25 09:13:36 +0100
committerDennis Fink2026-02-25 09:13:36 +0100
commitfa3530b214b63701dda5fd8b53aefeb0f0d776c3 (patch)
treeb7a767c629a7258838f727a4592b6d2d4d86be39
parentf2019d0aac71739d3ea6e780a501cd0be9af6b4a (diff)
downloadtranscode.sh-fa3530b214b63701dda5fd8b53aefeb0f0d776c3.tar.gz
transcode.sh-fa3530b214b63701dda5fd8b53aefeb0f0d776c3.zip
fix(cli): validate empty option values and improve --saving-file handling
Reject empty values for --encodefile, --saving-file, and --preset in both the space-separated and equals forms (e.g. --preset= now exits with a clear error instead of failing later with a confusing message from the allowlist check). Track whether --saving-file was set explicitly via SAVING_FILE_EXPLICIT. Warn when --saving-file is used without --saving, but do not exit, to allow the combination in aliases and wrapper scripts. Change the savings log format from space-separated to TSV and write a header line on first creation, making the file easier to parse both by eye and programmatically.
Diffstat (limited to '')
-rwxr-xr-xtranscode.sh37
1 files changed, 36 insertions, 1 deletions
diff --git a/transcode.sh b/transcode.sh
index a74b6c3..2866e97 100755
--- a/transcode.sh
+++ b/transcode.sh
@@ -122,6 +122,7 @@ ONLY_IF_SMALLER=0
PRESET_NAME="default"
SAVING=0
SAVING_FILE="transcode_savings"
+SAVING_FILE_EXPLICIT=0
declare -A SKIP_CODECS
REMAINING_ARGS=()
@@ -439,10 +440,18 @@ while [[ $# -gt 0 ]]; do
error "Missing value for $1"
exit $EXIT_USAGE_ERROR
}
+ [[ -n "$2" ]] || {
+ error "Value for $1 must not be empty"
+ exit $EXIT_USAGE_ERROR
+ }
ENCODE_FILE="$2"
shift 2
;;
--encodefile=*)
+ [[ -n "${1#*=}" ]] || {
+ error "Value for --encodefile must not be empty"
+ exit $EXIT_USAGE_ERROR
+ }
ENCODE_FILE="${1#*=}"
shift
;;
@@ -471,11 +480,21 @@ while [[ $# -gt 0 ]]; do
error "Missing value for $1"
exit $EXIT_USAGE_ERROR
}
+ [[ -n "$2" ]] || {
+ error "Value for $1 must not be empty"
+ exit $EXIT_USAGE_ERROR
+ }
SAVING_FILE="$2"
+ SAVING_FILE_EXPLICIT=1
shift 2
;;
--saving-file=*)
+ [[ -n "${1#*=}" ]] || {
+ error "Value for --saving-file must not be empty"
+ exit $EXIT_USAGE_ERROR
+ }
SAVING_FILE="${1#*=}"
+ SAVING_FILE_EXPLICIT=1
shift
;;
-S | --skip-codec)
@@ -499,10 +518,18 @@ while [[ $# -gt 0 ]]; do
error "Missing value for $1"
exit $EXIT_USAGE_ERROR
}
+ [[ -n "$2" ]] || {
+ error "Value for $1 must not be empty"
+ exit $EXIT_USAGE_ERROR
+ }
PRESET_NAME="$2"
shift 2
;;
--preset=*)
+ [[ -n "${1#*=}" ]] || {
+ error "Value for --preset must not be empty"
+ exit $EXIT_USAGE_ERROR
+ }
PRESET_NAME="${1#*=}"
shift
;;
@@ -543,6 +570,10 @@ if [[ $SAVING -eq 1 ]]; then
}
fi
+if [[ $SAVING_FILE_EXPLICIT -eq 1 && $SAVING -eq 0 ]]; then
+ error "--saving-file has no effect without --saving"
+fi
+
if [[ ! "$NICE_VALUE" =~ ^-?[0-9]+$ ]] || ((NICE_VALUE < -20 || NICE_VALUE > 19)); then
error "Invalid nice value (must be an integer between -20 and 19):" "$NICE_VALUE"
exit $EXIT_USAGE_ERROR
@@ -724,7 +755,11 @@ encode_one() {
else
pct=0
fi
- printf "%s %s %s %s%%\n" "$filename" "$original_filesize" "$new_filesize" "$pct" >>"$SAVING_FILE"
+ # Write a header line if the savings file does not yet exist.
+ if [[ ! -f "$SAVING_FILE" ]]; then
+ printf "filename\toriginal_bytes\tnew_bytes\tsaved_pct\n" >"$SAVING_FILE"
+ fi
+ printf "%s\t%s\t%s\t%s%%\n" "$filename" "$original_filesize" "$new_filesize" "$pct" >>"$SAVING_FILE"
fi
mv -f -- "$tmp" "$file"