2021-01-19 21:28:37 +01:00
|
|
|
#!/bin/bash
|
|
|
|
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"
|
|
|
|
|
|
|
|
# get directories
|
|
|
|
ls -d */ > directories
|
|
|
|
|
|
|
|
while read -r dir; do
|
2021-01-22 14:46:39 +01:00
|
|
|
# change into directory
|
|
|
|
cd "$dir"
|
|
|
|
# create directory in music
|
|
|
|
mkdir -p "$HOME/Musik/$dir"
|
|
|
|
|
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
|
|
|
|
|
|
|
# check if any flac files exist. cancle if that is not the case
|
|
|
|
if ls *.flac > /dev/null 2>&1; then
|
|
|
|
# get flac files
|
|
|
|
ls -f *.flac > "$HOME/MusikRaw/$dir/flaclist"
|
|
|
|
|
|
|
|
# create transcode directory
|
|
|
|
mkdir -p "$HOME/MusikRaw/$dir/transcode"
|
|
|
|
|
|
|
|
|
|
|
|
# convert flac files to opus
|
|
|
|
while read -r file; do
|
|
|
|
# strip extension
|
|
|
|
noextfile="${file%.*}"
|
|
|
|
# add opus extension
|
|
|
|
opusfile="${noextfile}.opus"
|
2021-01-26 12:51:25 +01:00
|
|
|
# encode to 192k bit opus
|
|
|
|
# TODO include cover picture (prefer picture named same as audio, cover at second place)
|
|
|
|
ffmpeg -nostdin -i "$HOME/MusikRaw/$dir/$file" -b:a 192k "$HOME/MusikRaw/$dir/transcode/$opusfile" &
|
2021-01-26 09:49:33 +01:00
|
|
|
done < flaclist
|
|
|
|
|
|
|
|
# remove list
|
|
|
|
rm "$HOME/MusikRaw/$dir/flaclist"
|
|
|
|
fi
|
|
|
|
|
2021-01-19 21:28:37 +01:00
|
|
|
# convert m4a
|
|
|
|
if [[ $(ls | grep ".m4a") ]]; then
|
2021-01-26 12:51:25 +01:00
|
|
|
ffmpeg-normalize *.m4a -v -pr -c:a libopus -b:a 128k -ext opus &
|
2021-01-19 21:28:37 +01:00
|
|
|
fi
|
2021-01-26 09:49:33 +01:00
|
|
|
|
2021-01-19 21:28:37 +01:00
|
|
|
# convert flac
|
2021-01-26 12:51:25 +01:00
|
|
|
#if [[ $(ls | grep ".flac") ]]; then
|
|
|
|
# ffmpeg-normalize *.flac -v -pr -c:a flac -ext flac &
|
|
|
|
#fi
|
|
|
|
|
|
|
|
# convert transcoded files
|
|
|
|
if [[ -d "$HOME/MusikRaw/$dir/transcode" ]]; then
|
|
|
|
ffmpeg-normalize transcode/*.opus -v -pr -c:a libopus -b:a 192k -ext opus &
|
2021-01-19 21:28:37 +01:00
|
|
|
fi
|
2021-01-26 09:49:33 +01:00
|
|
|
|
2021-01-19 21:28:37 +01:00
|
|
|
# convert opus
|
|
|
|
if [[ $(ls | grep ".opus") ]]; then
|
2021-01-26 12:51:25 +01:00
|
|
|
ffmpeg-normalize *.opus -v -pr -c:a libopus -b:a 128k -ext opus &
|
2021-01-19 21:28:37 +01:00
|
|
|
fi
|
2021-01-26 09:49:33 +01:00
|
|
|
|
2021-01-21 19:23:43 +01:00
|
|
|
# link cover.jpg
|
|
|
|
if [[ -f cover.jpg ]]; then
|
|
|
|
ln -vf "$HOME/MusikRaw/$dir/cover.jpg" "$HOME/Musik/$dir/"
|
|
|
|
fi
|
2021-01-22 14:46:39 +01:00
|
|
|
|
2021-01-19 21:28:37 +01:00
|
|
|
# make symbolic link to music
|
2021-01-26 08:43:04 +01:00
|
|
|
# if the "normalized" directory exists, links are created
|
|
|
|
if [[ -d "normalized" ]]; then
|
|
|
|
ln -svf "$HOME/MusikRaw/$dir/normalized/"* "$HOME/Musik/$dir/"
|
|
|
|
fi
|
|
|
|
|
2021-01-22 14:46:39 +01:00
|
|
|
# go back to music raw
|
|
|
|
cd "$HOME/MusikRaw"
|
2021-01-19 21:28:37 +01:00
|
|
|
done < directories
|
|
|
|
|
|
|
|
# remove directories file
|
|
|
|
rm directories
|
|
|
|
|
2021-01-19 21:29:58 +01:00
|
|
|
echo Finished!
|
|
|
|
|
2021-01-19 21:28:37 +01:00
|
|
|
exit
|