Use the ogg container instead and fix an edge case

Using the ogg container allows to also embed cover images while still
using the opus codec.

Also fixed an edge case that would make the script fail if the first
thing it iterated on was a regular file which didn't require conversion
if the parent directory wasn't already created.
This commit is contained in:
caem 2024-05-06 18:31:43 +02:00
parent 7228b78447
commit 39a5c0ca67
No known key found for this signature in database
GPG key ID: 3BCEDBB0C38805DA

View file

@ -125,7 +125,7 @@ get_total_count() {
for item in "$dir"/*; do for item in "$dir"/*; do
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"/".opus"}" new_file="${new_file/".flac"/".ogg"}"
if [ ! -f "$new_file" ] && [[ "$item" == *".flac" ]]; then if [ ! -f "$new_file" ] && [[ "$item" == *".flac" ]]; then
((total_count+=1)) ((total_count+=1))
elif [[ "$item" == *".flac" ]]; then elif [[ "$item" == *".flac" ]]; then
@ -156,13 +156,17 @@ iterate_dirs() {
item="${item/\$/"\\$"}" item="${item/\$/"\\$"}"
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"/".opus"}" 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))
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\" -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"}")
if [ ! -d "$new_dir" ]; then
mkdir -p "$new_dir"
fi
echo "Copied $(basename "$item")" echo "Copied $(basename "$item")"
cp -f "$item" "$new_file" cp -f "$item" "$new_file"
fi fi