Use find instead of changing into directories.
This commit is contained in:
parent
9c6008e7f1
commit
13ac2f5b32
@ -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
|
||||||
# strip extension
|
|
||||||
noextfile="${file%.*}"
|
|
||||||
# add opus extension
|
|
||||||
opusfile="${noextfile}.opus"
|
|
||||||
# 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" &
|
|
||||||
done < flaclist
|
|
||||||
|
|
||||||
# remove list
|
while read -r m4a; do
|
||||||
rm "$HOME/MusikRaw/$dir/flaclist"
|
# if there are $numjobs or more, dont spawn any new processes
|
||||||
fi
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
||||||
|
|
||||||
# convert m4a
|
# get directory path
|
||||||
if [[ $(ls | grep ".m4a") ]]; then
|
pathname="$(dirname "$m4a")"
|
||||||
ffmpeg-normalize *.m4a -v -pr -c:a libopus -b:a 128k -ext opus &
|
# go to that path for proper output location
|
||||||
fi
|
cd "$pathname"
|
||||||
|
# convert file
|
||||||
|
ffmpeg-normalize "$m4a" -v -pr -c:a libopus -b:a 128k -ext opus &
|
||||||
|
done < m4afiles
|
||||||
|
|
||||||
# convert flac
|
# go to musik raw folder
|
||||||
#if [[ $(ls | grep ".flac") ]]; then
|
cd "$HOME/MusikRaw"
|
||||||
# ffmpeg-normalize *.flac -v -pr -c:a flac -ext flac &
|
|
||||||
#fi
|
|
||||||
|
|
||||||
# convert transcoded files
|
# cleanup
|
||||||
if [[ -d "$HOME/MusikRaw/$dir/transcode" ]]; then
|
rm m4afiles
|
||||||
ffmpeg-normalize transcode/*.opus -v -pr -c:a libopus -b:a 192k -ext opus &
|
|
||||||
fi
|
|
||||||
|
|
||||||
# convert opus
|
# find flac files, ignore "normalized" or "transcode" folders
|
||||||
if [[ $(ls | grep ".opus") ]]; then
|
find "$HOME/MusikRaw/" -name "*\.flac" | grep -v "\/normalized\/" | grep -v "\/transcode\/" > flacfiles
|
||||||
ffmpeg-normalize *.opus -v -pr -c:a libopus -b:a 128k -ext opus &
|
|
||||||
fi
|
|
||||||
|
|
||||||
# use music-create-links instead
|
while read -r flac; do
|
||||||
: '
|
# if there are $numjobs or more, dont spawn any new processes
|
||||||
# link cover.jpg
|
while [[ $(jobs | wc -l) -gt $numjobs ]] ; do sleep 1 ; done
|
||||||
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
|
# get directory path
|
||||||
cd "$HOME/MusikRaw"
|
pathname="$(dirname "$flac")"
|
||||||
done < directories
|
# 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"
|
||||||
|
# convert to opus in transcode directory
|
||||||
|
# TODO include cover picture (prefer file picture, cover.jpg second preference)
|
||||||
|
ffmpeg -nostdin -i "$flac" -b:a 256k "${pathname}/transcode/$opusfile" &
|
||||||
|
# convert opus in transcode to normalized
|
||||||
|
ffmpeg-normalize "transcode/$opusfile" -v -pr -c:a libopus -b:a 256k -ext opus &
|
||||||
|
done < flacfiles
|
||||||
|
|
||||||
# remove directories file
|
# go to musik raw folder
|
||||||
rm directories
|
cd "$HOME/MusikRaw"
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm flacfiles
|
||||||
|
|
||||||
echo Finished!
|
echo Finished!
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user