Fix character escaping in file paths

Files are now quoted with ' instead of " now as to avoid more edge cases
that come from using quotation marks. Now only ' have to be escaped in
the item paths.
This commit is contained in:
caem 2024-05-14 12:26:00 +02:00
parent 91a94bd0fb
commit a08ffe34ce
No known key found for this signature in database
GPG key ID: 3BCEDBB0C38805DA

View file

@ -153,15 +153,15 @@ iterate_dirs() {
local total_count="$3" local total_count="$3"
count="$ref_count" count="$ref_count"
for item in "$dir"/*; do for item in "$dir"/*; do
item="${item/\$/"\\$"}" local item="$(echo "$item" | sed "s/'/'\\\\'/g")"
if [ -f "$item" ]; then if [ -f "$item" ]; then
new_file="${item/"$INPUT_DIR"/"$OUTPUT_DIR"}" new_file="${item/"$INPUT_DIR"/"$OUTPUT_DIR"}"
new_file="${new_file/".flac"/".ogg"}"
if [ ! -f "$new_file" ]; then if [ ! -f "$new_file" ]; then
if [[ "$item" == *".flac" ]]; then if [[ "$item" == *".flac" ]]; then
((count+=1)) ((count+=1))
new_file="${new_file/".flac"/".ogg"}"
conversions+=("printf '[%s/%s] \e[92m%s\e[0m -> \e[93m%s\e[0m\n' $count $total_count \ conversions+=("printf '[%s/%s] \e[92m%s\e[0m -> \e[93m%s\e[0m\n' $count $total_count \
\"$item\" \"$new_file\" && ffmpeg -hide_banner -loglevel error -i \"$item\" -c:a libopus -vbr \"$VBR\" -b:a \"$BITRATE\" \"$new_file\" > /dev/null") '$item' '$new_file' && ffmpeg -hide_banner -loglevel error -i '$item' -c:a libopus -vbr \"$VBR\" -b:a \"$BITRATE\" '$new_file' > /dev/null")
else else
new_dir=$(dirname "${item/"$INPUT_DIR"/"$OUTPUT_DIR"}") new_dir=$(dirname "${item/"$INPUT_DIR"/"$OUTPUT_DIR"}")
if [ ! -d "$new_dir" ]; then if [ ! -d "$new_dir" ]; then
@ -194,6 +194,6 @@ main () {
iterate_dirs "$INPUT_DIR" "count" "$total_count" iterate_dirs "$INPUT_DIR" "count" "$total_count"
} }
set -e # set -e
main "$@" main "$@"