2021-06-03 19:43:50 +02:00
|
|
|
#!/usr/bin/env bash
|
2021-01-19 21:28:37 +01:00
|
|
|
set -euo pipefail
|
|
|
|
|
2021-01-20 20:53:32 +01:00
|
|
|
# change into music raw folder
|
2021-01-19 21:28:37 +01:00
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
2021-01-19 21:29:58 +01:00
|
|
|
# number of parallel jobs can be set on as an argument
|
2021-01-19 21:28:37 +01:00
|
|
|
numjobs="$1"
|
|
|
|
|
2021-02-21 15:02:57 +01:00
|
|
|
##############################
|
|
|
|
##### OPUS #####
|
|
|
|
##############################
|
|
|
|
|
2021-04-25 17:02:00 +02:00
|
|
|
# array of opus with find
|
|
|
|
readarray -d '' opusfiles < <(find "$HOME/MusikRaw/" -not \( -path *"\/normalized\/"* -prune \) -not \( -path *"\/transcode\/"* -prune \) -name "*\.opus" -print0)
|
|
|
|
|
|
|
|
for opus in "${opusfiles[@]}"; do
|
2021-01-19 21:28:37 +01:00
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
2021-01-26 09:49:33 +01:00
|
|
|
|
2021-02-12 14:30:30 +01:00
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$opus")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# convert file
|
|
|
|
ffmpeg-normalize "$opus" -v -pr -c:a libopus -b:a 128k -ext opus &
|
2021-04-25 17:02:00 +02:00
|
|
|
done
|
2021-02-12 14:30:30 +01:00
|
|
|
|
|
|
|
# go to musik raw folder
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
2021-02-21 15:02:57 +01:00
|
|
|
##############################
|
|
|
|
##### M4A #####
|
|
|
|
##############################
|
|
|
|
|
2021-04-25 17:02:00 +02:00
|
|
|
# array of m4a with find
|
|
|
|
readarray -d '' m4afiles < <(find "$HOME/MusikRaw/" -not \( -path *"\/normalized\/"* -prune \) -not \( -path *"\/transcode\/"* -prune \) -name "*\.m4a" -print0)
|
2021-02-12 14:30:30 +01:00
|
|
|
|
2021-04-25 17:02:00 +02:00
|
|
|
for m4a in "${m4afiles[@]}"; do
|
2021-02-12 14:30:30 +01:00
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$m4a")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# convert file
|
|
|
|
ffmpeg-normalize "$m4a" -v -pr -c:a libopus -b:a 128k -ext opus &
|
2021-04-25 17:02:00 +02:00
|
|
|
done
|
2021-02-12 14:30:30 +01:00
|
|
|
|
|
|
|
# go to musik raw folder
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
2021-02-21 15:02:57 +01:00
|
|
|
##############################
|
|
|
|
##### FLAC #####
|
|
|
|
##############################
|
|
|
|
|
2021-04-25 17:02:00 +02:00
|
|
|
# array of flac with find
|
|
|
|
readarray -d '' flacfiles < <(find "$HOME/MusikRaw/" -not \( -path *"\/normalized\/"* -prune \) -not \( -path *"\/transcode\/"* -prune \) -name "*\.flac" -print0)
|
|
|
|
|
|
|
|
for flac in "${flacfiles[@]}"; do
|
2021-02-12 14:30:30 +01:00
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$flac")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# create directory for transcodes
|
|
|
|
mkdir -p "$pathname/transcode"
|
|
|
|
# get name of file
|
|
|
|
file="$(basename "$flac")"
|
|
|
|
# strip extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# add opus extension
|
|
|
|
opusfile="${noextfile}.opus"
|
2021-02-21 15:02:57 +01:00
|
|
|
|
2021-02-12 14:30:30 +01:00
|
|
|
# convert to opus in transcode directory
|
2022-07-11 08:45:00 +02:00
|
|
|
if [ -f "${pathname}/cover.jpg"]; then
|
|
|
|
ffmpeg -nostdin -i "$flac" -i "${pathname}/cover.jpg" -c:a libopus -b:a 384k "${pathname}/transcode/$opusfile" &
|
|
|
|
else
|
|
|
|
ffmpeg -nostdin -i "$flac" -c:a libopus -b:a 384k "${pathname}/transcode/$opusfile" &
|
|
|
|
fi
|
2021-04-25 17:02:00 +02:00
|
|
|
done
|
2021-02-21 15:02:57 +01:00
|
|
|
|
|
|
|
# wait for previous jobs to finish
|
|
|
|
while [[ $(jobs | wc -l) -gt 1 ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
|
|
|
# convert previously transcoded flacs
|
2021-04-25 17:02:00 +02:00
|
|
|
for flac in "${flacfiles[@]}"; do
|
2021-02-21 15:02:57 +01:00
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$flac")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# get name of file
|
|
|
|
file="$(basename "$flac")"
|
|
|
|
# strip extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# add opus extension
|
|
|
|
opusfile="${noextfile}.opus"
|
|
|
|
|
2021-02-12 14:30:30 +01:00
|
|
|
# convert opus in transcode to normalized
|
2021-06-03 19:36:10 +02:00
|
|
|
ffmpeg-normalize "transcode/$opusfile" -v -pr -c:a libopus -b:a 384k -ext opus &
|
2021-04-25 17:02:00 +02:00
|
|
|
done
|
2021-02-12 14:30:30 +01:00
|
|
|
|
|
|
|
# go to musik raw folder
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
2021-03-10 15:22:49 +01:00
|
|
|
##############################
|
|
|
|
##### MP3 #####
|
|
|
|
##############################
|
|
|
|
|
2021-04-25 17:02:00 +02:00
|
|
|
# array of mp3 with find
|
|
|
|
readarray -d '' mp3files < <(find "$HOME/MusikRaw/" -not \( -path *"\/normalized\/"* -prune \) -not \( -path *"\/transcode\/"* -prune \) -name "*\.mp3" -print0)
|
2021-03-10 15:22:49 +01:00
|
|
|
|
2021-04-25 17:02:00 +02:00
|
|
|
for mp3 in "${mp3files[@]}"; do
|
2021-03-10 15:22:49 +01:00
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$mp3")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# create directory for transcodes
|
|
|
|
mkdir -p "$pathname/transcode"
|
|
|
|
# get name of file
|
|
|
|
file="$(basename "$mp3")"
|
|
|
|
# strip extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# add opus extension
|
|
|
|
opusfile="${noextfile}.opus"
|
|
|
|
|
|
|
|
# convert to opus in transcode directory
|
2022-07-11 08:45:00 +02:00
|
|
|
if [ -f "${pathname}/cover.jpg"]; then
|
|
|
|
ffmpeg -nostdin -i "$mp3" -i "${pathname}/cover.jpg" -c:a libopus -b:a 192k "${pathname}/transcode/$opusfile" &
|
|
|
|
else
|
|
|
|
ffmpeg -nostdin -i "$mp3" -c:a libopus -b:a 192k "${pathname}/transcode/$opusfile" &
|
|
|
|
fi
|
2021-04-25 17:02:00 +02:00
|
|
|
done
|
2021-03-10 15:22:49 +01:00
|
|
|
|
|
|
|
# wait for previous jobs to finish
|
|
|
|
while [[ $(jobs | wc -l) -gt 1 ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
|
|
|
# convert previously transcoded mp3s
|
2021-04-25 17:02:00 +02:00
|
|
|
for mp3 in "${mp3files[@]}"; do
|
2021-03-10 15:22:49 +01:00
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$mp3")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# get name of file
|
|
|
|
file="$(basename "$mp3")"
|
|
|
|
# strip extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# add opus extension
|
|
|
|
opusfile="${noextfile}.opus"
|
|
|
|
|
|
|
|
# convert opus in transcode to normalized
|
2021-03-15 08:08:31 +01:00
|
|
|
ffmpeg-normalize "transcode/$opusfile" -v -pr -c:a libopus -b:a 192k -ext opus &
|
2021-04-25 17:02:00 +02:00
|
|
|
done
|
2021-03-10 15:22:49 +01:00
|
|
|
|
|
|
|
# go to musik raw folder
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
2022-01-02 13:28:37 +01:00
|
|
|
##############################
|
|
|
|
##### WAV #####
|
|
|
|
##############################
|
|
|
|
|
|
|
|
# array of wav with find
|
|
|
|
readarray -d '' wavfiles < <(find "$HOME/MusikRaw/" -not \( -path *"\/normalized\/"* -prune \) -not \( -path *"\/transcode\/"* -prune \) -name "*\.wav" -print0)
|
|
|
|
|
|
|
|
for wav in "${wavfiles[@]}"; do
|
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$wav")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# create directory for transcodes
|
|
|
|
mkdir -p "$pathname/transcode"
|
|
|
|
# get name of file
|
|
|
|
file="$(basename "$wav")"
|
|
|
|
# strip extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# add opus extension
|
|
|
|
opusfile="${noextfile}.opus"
|
|
|
|
|
|
|
|
# convert to opus in transcode directory
|
2022-07-11 08:45:00 +02:00
|
|
|
if [ -f "${pathname}/cover.jpg"]; then
|
|
|
|
ffmpeg -nostdin -i "$wav" -i "${pathname}/cover.jpg" -c:a libopus -b:a 384k "${pathname}/transcode/$opusfile" &
|
|
|
|
else
|
|
|
|
ffmpeg -nostdin -i "$wav" -c:a libopus -b:a 384k "${pathname}/transcode/$opusfile" &
|
|
|
|
fi
|
2022-01-02 13:28:37 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# wait for previous jobs to finish
|
|
|
|
while [[ $(jobs | wc -l) -gt 1 ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
|
|
|
# convert previously transcoded wavs
|
|
|
|
for wav in "${wavfiles[@]}"; do
|
|
|
|
# if there are $numjobs or more, dont spawn any new processes
|
|
|
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
|
|
|
|
|
|
|
# get directory path
|
|
|
|
pathname="$(dirname "$wav")"
|
|
|
|
# go to that path for proper output location
|
|
|
|
cd "$pathname"
|
|
|
|
# get name of file
|
|
|
|
file="$(basename "$wav")"
|
|
|
|
# strip extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# add opus extension
|
|
|
|
opusfile="${noextfile}.opus"
|
|
|
|
|
|
|
|
# convert opus in transcode to normalized
|
|
|
|
ffmpeg-normalize "transcode/$opusfile" -v -pr -c:a libopus -b:a 384k -ext opus &
|
|
|
|
done
|
|
|
|
|
|
|
|
# go to musik raw folder
|
|
|
|
cd "$HOME/MusikRaw"
|
|
|
|
|
|
|
|
while [[ $(jobs | wc -l) -gt 1 ]] ; do sleep 1 ; done
|
|
|
|
|
2021-01-19 21:29:58 +01:00
|
|
|
echo Finished!
|
|
|
|
|
2021-04-25 17:02:00 +02:00
|
|
|
$(exit 0); echo "$?"
|