From c9e9cc1fd21c90cfd204efcfcbb4c355d324c89c Mon Sep 17 00:00:00 2001 From: lub Date: Sun, 28 Oct 2018 11:37:10 +0100 Subject: [PATCH] refactor compress-music.sh remove $tmp remove source/tmp/destination copy remove non-opus deletion --- compress-music.sh | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/compress-music.sh b/compress-music.sh index 7933d84..f2276ef 100755 --- a/compress-music.sh +++ b/compress-music.sh @@ -6,33 +6,17 @@ set -e # source="$HOME/kskcloud/Musik/" -tmp="$HOME/Musik.tiny/" -destination="$HOME/kskcloud/Musik.tiny/" -placeholder="$destination/a" - -rm -rf "$tmp" -mkdir "$tmp" +export destination="$HOME/Musik.tiny/" mkdir -p "$destination" -# create a placeholder to prevent * from failing -touch "$placeholder" +cd "$source" -# copy original target files and existing files as cache -echo 'copying . . .' -cp -a --reflink=always "$source/"* "$destination/"* "$tmp" +# create directory structure +find . -type d -exec mkdir -p "$destination/{}" \; -# compress with opus; +e because ffmpeg errors on .jpg, .txt, etc. -echo 'compressing . . .' +# set +e because ffmpeg errors on .jpg, .txt, etc. +# compress with opus set +e -find "$tmp" -type f -not -name '*.opus' | parallel --eta --progress 'ffmpeg -v 0 -n -i ""{}"" -c:a libopus -map_metadata 0 -b:a 128k ""{.}.opus""' -set -e - -# delete all non-opus files -echo 'deleting . . .' -find "$tmp" -type f -not -name '*.opus' -delete - -# copy compressed files to target destination -cp -a --reflink=always "$tmp/"* "$destination" - -rm -r "$tmp" +find . -type f -not -name '*.opus' | parallel --eta --progress 'ffmpeg -v 0 -n -i ""{}"" -c:a libopus -map_metadata 0 -b:a 128k ""$destination/{.}.opus""' +#set -e \ No newline at end of file