73 lines
1.2 KiB
Text
73 lines
1.2 KiB
Text
|
#!/bin/bash
|
|||
|
|
|||
|
# Sortie à la moindre erreur
|
|||
|
set -e
|
|||
|
|
|||
|
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
|
|||
|
rootdir="$(realpath ${1:-${HOME}/Musique/})"
|
|||
|
|
|||
|
cd "$rootdir"
|
|||
|
|
|||
|
# Pour tous les sous-répertoires, à tous les niveaux
|
|||
|
for dir in **/ .
|
|||
|
do
|
|||
|
# 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
|
|||
|
if [[ "$(file --mime-type -b -e ascii -e compress -e tar -e cdf "$file")" =~ audio/ ]]
|
|||
|
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
|