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"
|
|
|
|
|
2021-07-02 14:32:14 +02:00
|
|
|
for dir in **/ .
|
2021-07-02 14:00:50 +02:00
|
|
|
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
|
|
|
|
|
2021-07-02 14:26:57 +02:00
|
|
|
if [[ "${file}" =~ .flac$ ]] || [[ "${dir}" == "Vidéos/" && "$(file --mime-type -b -e ascii -e compress -e tar -e cdf "$file")" =~ video/ ]]
|
2021-07-02 14:00:50 +02:00
|
|
|
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"
|
2021-09-09 01:46:43 +02:00
|
|
|
ffmpeg -n -loglevel error -i "file:$file" -c:a libopus -b:a 256K "file:${dstdir}${dstfile}"
|
2021-07-02 14:00:50 +02:00
|
|
|
echo "[${green} OK ${reset}] $file"
|
|
|
|
) &
|
|
|
|
else
|
|
|
|
echo "[${green}COPY${reset}] $file"
|
|
|
|
cp -n --reflink=auto "${file}" "${dstdir}/"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
wait
|
|
|
|
done
|
|
|
|
wait
|