Bonjour,
une coquile c'est glissé dans le script et que je n'avais pas remarqué.
C'était au niveau de la suppression de la programmation encore valide et le choix de ne pas la garder. C'était fonctionnel mais pas beau. Donc, il ma fallu recommencer tout refaire le boulot ( trop fastidieux à corriger pour ma petite tête )
Donc là, je me suis consacré qu'a une option : la partie programmation de l'enregistrement. C'est la plus chiante en faite
Donc dans ce test, il faut lancement du script, faire une programmation à environ 2 minutes du départ puis, on ferme le terminal vite fait. On relance avant les 2 minutes et on voit si ça part. Ensuite on peut aussi relancer le script dans les 2 minutes, mais cette fois, quand il le propose, dire non je garde pas cette programmation et voir, une fois supprimer, la suite du job.
#!/bin/bash
WAVE () {
filename_cue=$(find -type f -name "*.cue" | xargs --null basename)
filename=$(find -type f \( -name "*.mp3" -o -name "*.ogg" -o -name "*.flac" \) -print0 | xargs --null basename)
lame --decode "$filename"
rm -f "$filename"
wav_filename=$(find -type f -name "*.wav" -print0 | xargs --null basename)
wav_name=$( echo "${wav_filename%.*}")
tr -d '\0' < "$filename_cue" > data.cue
rm -f "$filename_cue"
mv data.cue "$wav_name".cue
sed -i -e '1 s/^.*$/FILE "'$wav_filename'" WAVE/' "$wav_name".cue
}
TITLE_TXT () {
grep -e 'TITLE' -e 'PERFORMER' "$wav_name".cue | \
awk '{for(x=1;x<=NF;x++)if($x~/TITLE/){sub(/TITLE/,++i)}}1' | \
sed '0~2G' \
>> "$wav_name".txt
}
FADE_IN_OUT_WAVE () {
data_wav_duration=$(ffmpeg -i "$wav_filename" 2>&1 | awk '/^ Duration/ { split($2, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1]}')
times=()
_t=$(ffmpeg -i "$wav_filename" 2>&1 | awk '/^ Duration/ { split($2, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] - 5 }')
times+=("$_t")
echo "${times[@]}" | sed 's/ /+/g' | bc
if [[ "$data_wav_duration" -gt 15 ]]; then
# "Guessed Channel Layout for Input Stream #0.0 : stereo" : ffmpeg -guess_layout_max 0
ffmpeg -guess_layout_max 0 -i "$wav_filename" \
-acodec pcm_s16le -ar 44100 \
-af "afade=t=in:ss=0:d=3,afade=t=out:st=${times[*]} :d=3" \
"FADE_$wav_filename"
rm -f "$wav_filename"
mv "FADE_$wav_filename" "$wav_filename"
fi
}
menage () {
rm -f stream.txt
rm -f url.txt
rm -f out.txt
rm -f command_diff
rm -f length.txt
rm -f file_saves_station_folder_date.txt
}
FIND=$( find . -name stream.txt)
COUNT_PROG_FIND=$( find . -name stream.txt | wc -l )
if [ $COUNT_PROG_FIND == 1 ]; then
#not_keep=$(find "$(cd ..; pwd)" -name stream.txt -printf '%h\n')
compare=$( cat $FIND )
date=$(( $compare - `date +%s`))
echo "Une écoute est déjà programmée pour le :"
date -d @"$compare"
read -r -p "Garder cette programmation ? [Y/n] " keep
case $keep in
[nN][oO]|[nN])
echo "Non, on supprime et on continue ..."
not_keep=$(find "$(cd ..; pwd)" -name stream.txt -printf '%h\n')
rm -r "$keep"
;;
[yY][eE][sS]|[yY])
echo ""
echo "On garde et on continue le décompte ..."
echo ""
while [ "$compare" -ne `date +%s` ]; do
echo -ne " $(date -u --date @$(($compare - `date +%s`)) +%d_%H:%M:%S)\r";
sleep 1
done
echo "C'est parti !!!!!!!!!!!!!"
dir_command_diff=$( find . -name command_diff -printf '%h\n' )
( cd "$dir_command_diff"
./command_diff
WAVE
TITLE_TXT
FADE_IN_OUT_WAVE
menage
)
exit 0
;;
esac
fi
#### Radios.
echo "Mes radios:"
echo -e "\e[3;32m1. \033[m \e[3;94mOldies_but_goldies\033[m"
echo -e "\e[3;32m2. \033[m \e[3;94mRadio_Italo4You\033[m"
echo
echo -n "Entrer un choix, 0 pour quitter: "
read -r choice
echo
#### le nombre doit correspondre au nombre de radios ci-dessus.
if [[ "$choice" -gt 2 ]]; then
echo "Il n'y a pas autant de radios."
echo "Quit"
exit 1
fi
if [[ "$choice" == 1 ]]; then
stream="http://orion.shoutca.st:8248/stream"
station=Oldies_but_goldies
fi
if [[ "$choice" == 2 ]]; then
stream="http://s0.radiohost.pl:8018/stream"
station=Radio_Italo4You
fi
if [[ "$choice" == 0 ]]; then
echo "OK, see you!"
exit 1
fi
if [[ "$choice" == "" ]]; then
echo "Invalid input..."
echo "Quit"
exit 1
fi
echo "Play/Play+Record or Play Diff/Play Diff+Record"
echo -e "\e[3;32m1. \033[m \e[3;94mProgrammer un enregistrement\033[m"
echo -n "Programmer un enregistrement(1), 0 for exit: "
read -r choice_of_use
echo
if [[ "$choice" != 0 || "$choice" != "" ]] && [[ "$choice_of_use" == "1" ]]; then
#### Création de commande différée dans le script command_diff
echo -e "\e[3;32mProgramation de l'écoute + enregistrement:\033[m"
read -p "Entrer la date dans le format: +J (un nombre) days HH:MM:SS " replay
folder_deferred=$(date "+%s" -d "$replay")
mkdir -p "$station/$folder_deferred"
readlink -m "$station/$folder_deferred" > "$station/$folder_deferred/file_saves_station_folder_date.txt"
deferred_program_dir=$(cat "$station/$folder_deferred/file_saves_station_folder_date.txt")
echo ""
echo -e "\e[32m 900 = \e[0m 0 heures 15 minutes"
echo -e "\e[32m 1800 = \e[0m 0 heures 30 minutes"
echo -e "\e[32m 2700 = \e[0m 0 heures 45 minutes"
echo -e "\e[32m 3600 = \e[0m 1 heures 00 minutes"
echo -e "\e[32m 4500 = \e[0m 1 heures 15 minutes"
echo -e "\e[32m 5400 = \e[0m 1 heures 30 minutes"
echo -e "\e[32m 6300 = \e[0m 1 heures 45 minutes"
echo -e "\e[32m 7200 = \e[0m 2 heures 00 minutes"
echo -e "\e[32m 8100 = \e[0m 2 heures 15 minutes"
echo -e "\e[32m 9000 = \e[0m 2 heures 30 minutes"
echo -e "\e[32m 9900 = \e[0m 2 heures 45 minutes"
echo -e "\e[32m 10800 = \e[0m 3 heures 00 minutes"
echo -e "\e[32m 11700 = \e[0m 3 heures 15 minutes"
echo -e "\e[32m 12600 = \e[0m 3 heures 30 minutes"
read -p "Pour une durée n(s): " out
echo ""
echo -e "\e[32m$out\e[0m secondes"
{ echo '#!/bin/bash';
echo '';
echo 'diff=$(sed -n 1p "stream.txt")';
echo 'url_diff=$(sed -n 1p "url.txt")';
echo 'out_diff=$(sed -n 1p "out.txt")';
echo 'length=$(sed -n 1p "length.txt")';
echo 'date=$(( $diff - `date +%s`))';
echo '';
echo 'timeout $out_diff streamripper $url_diff -a -A -s \';
echo ' --codeset-filesys=UTF-8 \';
echo ' --codeset-id3=UTF-8 \';
echo ' --codeset-metadata=UTF-8 \';
echo ' --codeset-relay=UTF-8 \';
echo ' -u FreeAmp/2.x | \';
echo ' mpv --length=$length $url_diff --no-resume-playback --no-save-position-on-quit ';
} >> "$deferred_program_dir/command_diff"
chmod u+x "$deferred_program_dir/command_diff"
diff=$(date "+%s" -d "$replay")
echo $diff > "$deferred_program_dir/stream.txt"
echo $stream > "$deferred_program_dir/url.txt"
url_diff=$(sed -n 1p "$deferred_program_dir/url.txt")
echo $out > "$deferred_program_dir/out.txt"
out_diff=$(sed -n 1p "$deferred_program_dir/out.txt")
length=$(awk '{print $0}' "$deferred_program_dir/out.txt" | sed 's/[^0-9]*//g')
echo $length > "$deferred_program_dir/length.txt"
date=$(( $diff - `date +%s`))
while [ "$diff" -ne `date +%s` ]; do
echo -ne " $(date -u --date @$(($diff - `date +%s`)) +%d_%H:%M:%S)\r";
sleep 1
done
echo "C'est parti !!!"
timeout $out_diff streamripper $stream -a -A -s -d "$deferred_program_dir" \
--codeset-filesys=UTF-8 \
--codeset-id3=UTF-8 \
--codeset-metadata=UTF-8 \
--codeset-relay=UTF-8 \
-u FreeAmp/2.x | \
mpv --length=$length $stream --no-resume-playback --no-save-position-on-quit
(cd "$deferred_program_dir" || exit
WAVE
TITLE_TXT
FADE_IN_OUT_WAVE
menage
)
fi
Dernière modification par Anonyme (28-11-2020 17:24:36)