2021-12-11 21:37:40 +01:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
shopt -s globstar
|
|
|
|
|
|
|
|
|
|
# Initialisation de la mise en forme
|
|
|
|
|
blue=$(tput setaf 4)
|
|
|
|
|
red=$(tput setaf 1)
|
|
|
|
|
green=$(tput setaf 2)
|
|
|
|
|
reset=$(tput sgr0)
|
|
|
|
|
bold=$(tput bold)
|
|
|
|
|
|
|
|
|
|
# Répertoire source
|
2022-01-10 19:37:13 +01:00
|
|
|
|
rootdir="$(realpath "${1:-${HOME}/Musique/}")"
|
2021-12-11 21:37:40 +01:00
|
|
|
|
|
|
|
|
|
cd "$rootdir"
|
|
|
|
|
|
|
|
|
|
# Pour tous les sous-répertoires, à tous les niveaux
|
|
|
|
|
for dir in **/ .
|
|
|
|
|
do
|
2022-01-10 19:37:13 +01:00
|
|
|
|
# Vérifie que le répertoire existe, sinon on le saute.
|
|
|
|
|
[[ -d "${rootdir}/${dir}" ]] || continue
|
|
|
|
|
|
2021-12-11 21:37:40 +01:00
|
|
|
|
# On entre dans le répertoire à traiter
|
|
|
|
|
cd "${rootdir}/${dir}"
|
|
|
|
|
|
|
|
|
|
# Liste des fichiers à traiter
|
|
|
|
|
unset todo
|
|
|
|
|
declare -a todo
|
|
|
|
|
|
|
|
|
|
# Pour chaque fichier
|
|
|
|
|
for file in *
|
|
|
|
|
do
|
|
|
|
|
# On ignore les dossiers
|
|
|
|
|
if [[ -d "${file}" ]]
|
|
|
|
|
then
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# S’il s’agit d’audio
|
2022-01-10 19:37:13 +01:00
|
|
|
|
if [[ "$file" =~ .mp3$ || "$file" =~ .m4a$ || "$(file --mime-type -b -e ascii -e compress -e tar -e cdf "$file")" =~ audio/ ]]
|
2021-12-11 21:37:40 +01:00
|
|
|
|
then
|
|
|
|
|
todo+=("$file")
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Si rien à faire, on saute.
|
|
|
|
|
if [[ "${#todo}" -eq 0 ]]
|
|
|
|
|
then
|
|
|
|
|
echo "[${blue}SKIP${reset}] $dir"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Parrallélisation des traitements
|
|
|
|
|
declare -a running
|
|
|
|
|
|
|
|
|
|
running=($(jobs -p))
|
|
|
|
|
if [[ "${#running[@]}" -ge 12 ]]
|
|
|
|
|
then
|
|
|
|
|
wait -n
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
(
|
|
|
|
|
# Affichage du répertoire en cours de traitement
|
|
|
|
|
echo " $dir$reset"
|
|
|
|
|
|
|
|
|
|
# Traitement
|
|
|
|
|
loudgain -S -a -k -q -s e "${todo[@]}" &>/dev/null && \
|
|
|
|
|
echo "[${green} OK ${reset}] $dir" || \
|
|
|
|
|
echo "[${red}FAIL${reset}] $dir"
|
|
|
|
|
) &
|
|
|
|
|
done
|
|
|
|
|
wait
|