Refonte des scripts music-convert
This commit is contained in:
parent
f7a7007435
commit
8f2b940c97
2 changed files with 110 additions and 7 deletions
|
@ -13,7 +13,7 @@ reset=$(tput sgr0)
|
|||
bold=$(tput bold)
|
||||
|
||||
# Répertoire source
|
||||
rootdir="${HOME}/Vidéos/Musique"
|
||||
rootdir="${HOME}/Musique"
|
||||
|
||||
cd "$rootdir"
|
||||
|
||||
|
@ -27,7 +27,7 @@ do
|
|||
fi
|
||||
|
||||
# Répertoire de destination
|
||||
dstdir="${HOME}/Musique/Vidéos/${dir}"
|
||||
dstdir="/mnt/data/breizh/Musique.opus/${dir}"
|
||||
|
||||
# Création du répertoire de destination
|
||||
mkdir -p "${dstdir}"
|
||||
|
@ -35,6 +35,8 @@ do
|
|||
# On entre dans le répertoire à traiter
|
||||
cd "${rootdir}/${dir}"
|
||||
|
||||
togain=false
|
||||
|
||||
# Pour chaque fichier
|
||||
for file in *
|
||||
do
|
||||
|
@ -48,20 +50,22 @@ do
|
|||
dstfile="${file%.*}.opus"
|
||||
|
||||
# Passe les fichiers déjà traités
|
||||
if [[ "${dstdir}${dstfile}" -nt "${file}" ]]
|
||||
if [[ "${dstdir}${dstfile}" -nt "${file}" || "${dstdir}${file}" -nt "${file}" ]]
|
||||
then
|
||||
echo "[${blue}SKIP${reset}] ${dir#./}$file"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Converti uniquement les vidéos
|
||||
if [[ "$(file --mime-type -b -e ascii -e compress -e tar -e cdf "$file")" =~ video/ ]]
|
||||
# Converti uniquement les flacs
|
||||
if [[ "$file" =~ \.flac$ ]]
|
||||
then
|
||||
togain=true
|
||||
|
||||
# Parallélisation des conversions
|
||||
declare -a running
|
||||
|
||||
mapfile -t running < <(jobs -p)
|
||||
if [[ "${#running[@]}" -ge 12 ]]
|
||||
if [[ "${#running[@]}" -ge 6 ]]
|
||||
then
|
||||
wait -n
|
||||
fi
|
||||
|
@ -69,7 +73,6 @@ do
|
|||
(
|
||||
echo " ${dir#./}$file"
|
||||
ffmpeg -n -loglevel error -i "file:$file" -c:a libopus -b:a 128K "file:${dstdir}${dstfile}" && \
|
||||
loudgain -S -r -k -q -s e "${dstdir}${dstfile}" &>/dev/null && \
|
||||
echo "[${green} OK ${reset}] ${dir#./}$file" || \
|
||||
echo "[${red}FAIL${reset}] ${dir#./}$file"
|
||||
) &
|
||||
|
@ -79,5 +82,22 @@ do
|
|||
cp -n --reflink=auto "${file}" "${dstdir}/" || true
|
||||
fi
|
||||
done
|
||||
wait
|
||||
|
||||
if ${togain}
|
||||
then
|
||||
(
|
||||
cd "${dstdir}"
|
||||
shopt -s nullglob
|
||||
echo "[${blue}GAIN${reset}] $dir"
|
||||
loudgain -q -S -a -k -s e -- *.opus &>/dev/null && \
|
||||
echo "[${green}GAIN${reset}] $dir" || \
|
||||
echo "[${red}GAIN${reset}] $dir"
|
||||
shopt -u nullglob
|
||||
) & disown $!
|
||||
|
||||
# Réinitialise le tag togain
|
||||
togain="false"
|
||||
fi
|
||||
done
|
||||
wait
|
||||
|
|
83
.local/bin/music-video-convert
Executable file
83
.local/bin/music-video-convert
Executable file
|
@ -0,0 +1,83 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Sortie à la moindre erreur
|
||||
set -e
|
||||
|
||||
shopt -s globstar
|
||||
|
||||
# Initialisation de la mise en forme
|
||||
blue=$(tput setaf 4)
|
||||
green=$(tput setaf 2)
|
||||
red=$(tput setaf 1)
|
||||
reset=$(tput sgr0)
|
||||
bold=$(tput bold)
|
||||
|
||||
# Répertoire source
|
||||
rootdir="${HOME}/Vidéos/Musique"
|
||||
|
||||
cd "$rootdir"
|
||||
|
||||
# Pour tous les sous-répertoires, à tous les niveaux
|
||||
for dir in **/ ./
|
||||
do
|
||||
# Ignorer les liens symboliques
|
||||
if [[ -h "${rootdir}/${dir::-1}" ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Répertoire de destination
|
||||
dstdir="${HOME}/Musique/Vidéos/${dir}"
|
||||
|
||||
# Création du répertoire de destination
|
||||
mkdir -p "${dstdir}"
|
||||
|
||||
# On entre dans le répertoire à traiter
|
||||
cd "${rootdir}/${dir}"
|
||||
|
||||
# Pour chaque fichier
|
||||
for file in *
|
||||
do
|
||||
# On ignore les dossiers
|
||||
if [[ -d "${file}" ]]
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Définition du fichier de destination
|
||||
dstfile="${file%.*}.opus"
|
||||
|
||||
# Passe les fichiers déjà traités
|
||||
if [[ "${dstdir}${dstfile}" -nt "${file}" ]]
|
||||
then
|
||||
echo "[${blue}SKIP${reset}] ${dir#./}$file"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Converti uniquement les vidéos
|
||||
if [[ "$(file --mime-type -b -e ascii -e compress -e tar -e cdf "$file")" =~ video/ ]]
|
||||
then
|
||||
# Parallélisation des conversions
|
||||
declare -a running
|
||||
|
||||
mapfile -t running < <(jobs -p)
|
||||
if [[ "${#running[@]}" -ge 12 ]]
|
||||
then
|
||||
wait -n
|
||||
fi
|
||||
|
||||
(
|
||||
echo " ${dir#./}$file"
|
||||
ffmpeg -n -loglevel error -i "file:$file" -c:a libopus -b:a 128K "file:${dstdir}${dstfile}" && \
|
||||
loudgain -S -r -k -q -s e "${dstdir}${dstfile}" &>/dev/null && \
|
||||
echo "[${green} OK ${reset}] ${dir#./}$file" || \
|
||||
echo "[${red}FAIL${reset}] ${dir#./}$file"
|
||||
) &
|
||||
else
|
||||
# Copie les autres types de fichiers
|
||||
echo "[${green}COPY${reset}] ${dir#./}$file"
|
||||
cp -n --reflink=auto "${file}" "${dstdir}/" || true
|
||||
fi
|
||||
done
|
||||
done
|
||||
wait
|
Loading…
Reference in a new issue