tc-audio-transcode: proper inplace overwriting

master
Pierre Neidhardt 2013-08-03 22:17:26 +02:00
parent 99a0b71e9f
commit 563e38d1c4
1 changed files with 9 additions and 7 deletions

View File

@ -4,16 +4,11 @@
## User options
## You can easily set output folder to current folder with OUTPUT_ROOT=".".
[ -z "$OUTPUT_ROOT" ] && OUTPUT_ROOT="$HOME/musics/"
[ -z "$OUTPUT_ROOT" ] && OUTPUT_ROOT="$HOME/musics"
## End of user options
################################################################################
if [ ! -d "$OUTPUT_ROOT" ]; then
echo "Output folder '$OUTPUT_ROOT' does not exist."
exit
fi
if [ -z "$(command -v ffmpeg)" ]; then
echo "ffmpeg required for transcoding."
exit
@ -24,6 +19,12 @@ if [ -z "$(command -v realpath)" ]; then
exit
fi
OUTPUT_ROOT="$(realpath "$OUTPUT_ROOT")"
if [ ! -d "$OUTPUT_ROOT" ]; then
echo "Output folder '$OUTPUT_ROOT' does not exist."
exit
fi
TITLECASE_SCRIPT="${0%/*}/titlecase.awk"
if [ ! -f "$TITLECASE_SCRIPT" ]; then
echo "AWK titlecase script required."
@ -340,7 +341,8 @@ if [ -e "$OUTPUT_FOLDER/$OUTPUT_FILE.$OUTPUT_EXT" ]; then
OUTPUT_FILE="$OUTPUT_FILE-$(date '+%F-%H%M%S')"
OUTPUT_MSG="$(tput setf 1)$(tput bold)(Warning: destination exists, appending timestamp.)$(tput sgr0)"
else
if [ "$INPUT_FOLDER/$INPUT_FILE" = "$OUTPUT_FOLDER/$OUTPUT_FILE.$OUTPUT_EXT" ]; then
## WARNING: here it is important that no folder are suffixed by slashes.
if [ "$INPUT_FOLDER/$INPUT_FILE.$INPUT_EXT" = "$OUTPUT_FOLDER/$OUTPUT_FILE.$OUTPUT_EXT" ]; then
OUTPUT_FILE_ORIGINAL="$OUTPUT_FILE"
OUTPUT_FILE="$OUTPUT_FILE-$(date '+%F-%H%M%S')"
fi