From 6fde82167f20bb45e1a23acc5e3243272b49e4a1 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Tue, 6 Apr 2021 22:55:30 +0200 Subject: [PATCH] fixes invalid "/" in filenames, fixes handling of filenames with spaces. --- get-tracks.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/get-tracks.sh b/get-tracks.sh index 8695602..53c20f9 100755 --- a/get-tracks.sh +++ b/get-tracks.sh @@ -33,6 +33,11 @@ simple_quote(){ sed "s/e2 80 99/27/g" } +# From / to ' - ' +replace_slashes(){ + sed "s/2f/20 2d 20/g" +} + remove_multibyte_characters(){ sed "s/e2 80 .. //g" } @@ -47,11 +52,12 @@ from_hex(){ xxd -p -r } -# Remove non ascii characters, convert "’" to "'". +# Remove non ascii characters, convert "’" to "'", or remove invalid filename characters. to_ascii(){ to_hex_one_column | # Convert input into hexadecimal and a single byte per line. regroup_lines | # Required to easily match multi-byte characters. simple_quote | # Convert "’" to "'". + replace_slashes | # Replaces / by ' - ', since it isn't a valid filename character. remove_multibyte_characters | # Remove non ascii values. from_hex # Convert back from hex. } @@ -133,7 +139,7 @@ run_ffmpeg(){ if [ "$to" != "" ]; then TO="-to $to" fi - INPUT_FILE="-i $file" + INPUT_FILE="$file" OUTPUT_FILE="$final_title" case "v$VERBOSITY" in @@ -143,7 +149,7 @@ run_ffmpeg(){ echo "extracting '$final_title'" ;; v2) - echo "ffmpeg $LOG_LEVEL $FROM $TO $INPUT_FILE '$OUTPUT_FILE'" + echo "ffmpeg $LOG_LEVEL $FROM $TO -i $INPUT_FILE '$OUTPUT_FILE'" ;; *) echo "verbosity is not set properly" >&2 @@ -152,7 +158,7 @@ run_ffmpeg(){ esac if [ "$SIMULATION" = "" ]; then - $(< /dev/null ffmpeg $LOG_LEVEL $FROM $TO $INPUT_FILE "$OUTPUT_FILE") + $(< /dev/null ffmpeg $LOG_LEVEL $FROM $TO -i "$INPUT_FILE" "$OUTPUT_FILE") fi }