Use find instead of changing into directories.

This commit is contained in:
RealStickman 2021-02-12 14:30:30 +01:00
parent 9c6008e7f1
commit 13ac2f5b32

View File

@ -7,83 +7,81 @@ cd "$HOME/MusikRaw"
# number of parallel jobs can be set on as an argument # number of parallel jobs can be set on as an argument
numjobs="$1" numjobs="$1"
# get directories # using find to get music that has to be transcoded
ls -d */ > directories
while read -r dir; do # find opus, ignore anything in "normalized" or "transcode" folders
# change into directory find "$HOME/MusikRaw/" -name "*\.opus" | grep -v "\/normalized\/" | grep -v "\/transcode\/" > opusfiles
cd "$dir"
# create directory in music
#mkdir -p "$HOME/Musik/$dir"
while read -r opus; do
# if there are $numjobs or more, dont spawn any new processes # if there are $numjobs or more, dont spawn any new processes
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
# check if any flac files exist. cancle if that is not the case # get directory path
if ls *.flac > /dev/null 2>&1; then pathname="$(dirname "$opus")"
# get flac files # go to that path for proper output location
ls -f *.flac > "$HOME/MusikRaw/$dir/flaclist" cd "$pathname"
# convert file
ffmpeg-normalize "$opus" -v -pr -c:a libopus -b:a 128k -ext opus &
done < opusfiles
# create transcode directory # go to musik raw folder
mkdir -p "$HOME/MusikRaw/$dir/transcode" cd "$HOME/MusikRaw"
# cleanup
rm opusfiles
# convert flac files to opus # find m4a files, ignore "normalized" or "transcode" folders
while read -r file; do find "$HOME/MusikRaw/" -name "*\.m4a" | grep -v "\/normalized\/" | grep -v "\/transcode\/" > m4afiles
while read -r m4a; 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 "$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 &
done < m4afiles
# go to musik raw folder
cd "$HOME/MusikRaw"
# cleanup
rm m4afiles
# find flac files, ignore "normalized" or "transcode" folders
find "$HOME/MusikRaw/" -name "*\.flac" | grep -v "\/normalized\/" | grep -v "\/transcode\/" > flacfiles
while read -r flac; 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 "$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 # strip extension
noextfile="${file%.*}" noextfile="${file%.*}"
# add opus extension # add opus extension
opusfile="${noextfile}.opus" opusfile="${noextfile}.opus"
# encode to 192k bit opus # convert to opus in transcode directory
# TODO include cover picture (prefer picture named same as audio, cover at second place) # TODO include cover picture (prefer file picture, cover.jpg second preference)
ffmpeg -nostdin -i "$HOME/MusikRaw/$dir/$file" -b:a 192k "$HOME/MusikRaw/$dir/transcode/$opusfile" & ffmpeg -nostdin -i "$flac" -b:a 256k "${pathname}/transcode/$opusfile" &
done < flaclist # convert opus in transcode to normalized
ffmpeg-normalize "transcode/$opusfile" -v -pr -c:a libopus -b:a 256k -ext opus &
done < flacfiles
# remove list # go to musik raw folder
rm "$HOME/MusikRaw/$dir/flaclist" cd "$HOME/MusikRaw"
fi
# convert m4a # cleanup
if [[ $(ls | grep ".m4a") ]]; then rm flacfiles
ffmpeg-normalize *.m4a -v -pr -c:a libopus -b:a 128k -ext opus &
fi
# convert flac
#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 &
fi
# convert opus
if [[ $(ls | grep ".opus") ]]; then
ffmpeg-normalize *.opus -v -pr -c:a libopus -b:a 128k -ext opus &
fi
# use music-create-links instead
: '
# link cover.jpg
if [[ -f cover.jpg ]]; then
ln -vf "$HOME/MusikRaw/$dir/cover.jpg" "$HOME/Musik/$dir/"
fi
'
: '
# make symbolic link to music
# if the "normalized" directory exists, links are created
if [[ -d "normalized" ]]; then
ln -svf "$HOME/MusikRaw/$dir/normalized/"* "$HOME/Musik/$dir/"
fi
'
# go back to music raw
cd "$HOME/MusikRaw"
done < directories
# remove directories file
rm directories
echo Finished! echo Finished!