dotfiles/.local/bin/music-convert

62 lines
1 KiB
Bash
Executable file

#!/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$ ]] || [[ "${dir}" == "Vidéos/" && "$(file --mime-type -b -e ascii -e compress -e tar -e cdf "$file")" =~ video/ ]]
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" "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