dotfiles/.local/bin/music-replaygain
2022-01-10 19:37:13 +01:00

72 lines
1.3 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
rootdir="$(realpath "${1:-${HOME}/Musique/}")"
cd "$rootdir"
# Pour tous les sous-répertoires, à tous les niveaux
for dir in **/ .
do
# Vérifie que le répertoire existe, sinon on le saute.
[[ -d "${rootdir}/${dir}" ]] || continue
# 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
# Sil sagit daudio
if [[ "$file" =~ .mp3$ || "$file" =~ .m4a$ || "$(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