dotfiles/.local/bin/music-convert

63 lines
937 B
Text
Raw Normal View History

2021-07-02 14:00:50 +02:00
#!/bin/bash
set -e
shopt -s globstar
blue=$(tput setaf 4)
green=$(tput setaf 2)
reset=$(tput sgr0)
bold=$(tput bold)
rootdir="${HOME}/Musique/"
cd "$rootdir"
for dir in **/ $rootdir
do
echo "$bold$dir$reset"
dstdir="${HOME}/Musique.opus/${dir}"
mkdir -p "${dstdir}"
cd "${rootdir}/${dir}"
for file in *
do
if [[ -d "${file}" ]]
then
continue
fi
if [[ "${file}" =~ .flac$ ]]
then
dstfile="$(basename -s .flac "$file").opus"
if [[ -f "${dstdir}${dstfile}" ]]
then
echo "[${blue}SKIP${reset}] $file"
continue
fi
declare -a running
running=($(jobs -p))
if [[ "${#running[@]}" -ge 12 ]]
then
wait -n
fi
(
echo " $file"
ffmpeg -n -loglevel error -i "$file" "file:${dstdir}${dstfile}"
echo "[${green} OK ${reset}] $file"
) &
else
echo "[${green}COPY${reset}] $file"
cp -n --reflink=auto "${file}" "${dstdir}/"
fi
done
wait
done
wait