diff --git a/encode_all b/encode_all index 75dbd0f..7f490ed 100755 --- a/encode_all +++ b/encode_all @@ -8,8 +8,8 @@ function ts() { date '+%Y-%m-%d_%H:%M' } -overwrite_all=true -# overwrite_all=false +# overwrite_all=true +overwrite_all=false debug_only=false # debug_only=true @@ -20,12 +20,12 @@ logdir="${HOME}/encoding_logs" start_ts="$(ts)" log="${logdir}/${start_ts}_encoding_log" fixes="${logdir}/${start_ts}_fixes.sh" +temp_dir="$(mktemp -d)" printf '#!/bin/bash\n# FIXES generated by library_works/encode_all\n\n' > "$fixes" function encode() { file="$1" - # file is full original path + filename src_dir="$(dirname "$file")" file_name="$(basename "$file")" @@ -34,6 +34,8 @@ function encode() { -e 's/\.flac$/.opus/' \ -e "s_${HOME}/flac_${HOME}/opus_" <<< "$file")" + sum="$(sha256sum <<< "$final_opus" | cut -d\ -f1)" + printf '%s\n' "$final_opus" > "$temp_dir/$sum" if [[ -f "$final_opus" && "$overwrite_all" == 'false' ]]; then printf '%s exists, not reencoding\n' >> "$log" return @@ -146,4 +148,12 @@ function encode() { fi } +echo going to process find "$src_library" -type f -name '*.flac' -print0 | env_parallel -P 0 -0 --bar encode {} +echo done processing + +diff -d --suppress-common-lines <(cat "$temp_dir"/* | sort -V) <(find "$output_dir" -type f | sort -V) | grep -E '^>' | sed 's/^> //' | while read old_opus; do + rm -f "$old_opus" +done + +find "$output_dir" -empty -type d -delete diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..6b9dc2a --- /dev/null +++ b/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +unset a +declare -a a +c=0 +function t() { + c+=1 + a+=(bly $c) +} + + +for i in {1..10}; do + t +done + +for i in "${a[@]}"; do + echo $i +done