scripts-bash/run_music_background

64 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Intercepte le ^C
trap 'exit 130' INT
## Read config file or create/update
config_filename=~/.config/$(basename ${0})
test -f ${config_filename} && . ${config_filename} || echo "# Fichier de configuration créé $(date +%c)" | tee ${config_filename}
### edit directory path music background
if [[ -z "${path_music_files+set}" ]]; then
path_music_files=$(xdg-user-dir MUSIC)
echo "path_music_files=${path_music_files}" | tee -a ${config_filename}
fi
if [[ -z "${path_music_files+set}" ]]; then
path_music_files=~
echo "path_music_files=${path_music_files}" | tee -a ${config_filename}
fi
### edit volume
if [[ -z "${volume+set}" ]]; then
volume=0.06
echo "volume=${volume}" | tee -a ${config_filename}
fi
## Init var
files=($path_music_files/*)
## execute
echo Process number $$
echo Path files : $path_music_files
echo Number of files in the path : ${#files[@]}
run_play=0
while [ ${run_play} -eq 0 ];do
clear
file=${files["$[RANDOM % ${#files[@]}]"]}
# suppresion du fichier en cours de lecture
new_files=()
for file_keep in "${files[@]}"; do
[[ "$file_keep" != "$file" ]] && new_files+=("$file_keep")
done
files=("${new_files[@]}")
unset new_files
# Nombre d'éléments dans le tableau
elements_in_files=${#files[@]}
echo -e "\n => Now playing $file"
echo -e "\n => ${elements_in_files} files left"
play -S -v $volume "$file"
run_play=$(echo $?)
if [ ${elements_in_files} -eq 0 ]; then
run_play=2
fi
done