dotfiles/.local/bin/music-replaygain-solo

51 lines
928 B
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
# 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:-$PWD})"
cd "$rootdir"
# Pour tous les fichiers
for file in *
do
# Sil sagit daudio
if [[ "$(file --mime-type -b -e ascii -e compress -e tar -e cdf "$file")" =~ audio/ ]]
then
# Parrallélisation des traitements
declare -a running
running=($(jobs -p))
if [[ "${#running[@]}" -ge 12 ]]
then
wait -n
fi
(
# Affichage du fichier en cours de traitement
echo " $file$reset"
# Traitement
loudgain -S -r -k -q -s e "$file" &>/dev/null && \
echo "[${green} OK ${reset}] $file" || \
echo "[${red}FAIL${reset}] $file"
) &
else
# Si rien à faire, on saute.
echo "[${blue}SKIP${reset}] $file"
continue
fi
done
wait