xwang
08-08-2008, 10:57
Ciao a tutti,
negli ultimi giorni ho creato questo script che permette di registrare le radio internet (anche quelle che non si trovano su shoutcast e simili tipo le radio rai, la bbc, radio deejey) in mp3.
Mi sono basato in parte su quanto esposto qui:
http://walkingtowel.org/2006/03/03/record-streaming-audio-with-linux-part-ii/
modificandolo in modo da avere una sorta di interfaccia grafica (ho usato kdialog per cui penso sia utile solo per gli utenti kde) che permettesse di selezionare i vari parametri e di iniziare e terminare la registrazione.
Che ne pensate?
Come faccio a pubblicarlo per renderlo disponibile a tutti?
Se vedete lo script ho usato xterm perchè mplayer una volta che si è connesso alla radio si duplica diventando due processi.
Se faccio partire mplayer dentro xterm, uccidendo xterm uccido tutti i processi figli. Se lo avviao senza xterm conosco il pin solo del primo processo mplayer e il secondo rimane vivo.
Per me va anche bene così solo che se l'utente chiude la finestra di xterm non è previsto alcun controllo nel programma.
Insomma mancano ancora alcune cose da fare, ma gradirei un vostro aiuto e vostri pareri.
Grazie,
Xwang
#!/bin/bash
# radioRecoder.sh
# v0.3.0 - 20080814
# Xwang <[email protected]>
# Released under GPL 2.0 and following (can you help me and tell if it is GPL3 compliant?)
# This script acts as a wizard enabling the user to select the URL to listen and eventually rip it after having specified
# the directory and the file name
# The cancel button is used to go to the previous page
# To exit the program press cancel in the URL page and follow the instruction
# TBD
# store inserted URL in external file and use them in a combobox
# check if parameter is passed or not
# modify parameters so that recording can be done without user iteration
# capture Ctrl-C in order to clean all temporary files and kill opened processes before closing
# give some indication on recording time and if possible file dimension
# put confirmation on registration stop
# open the directory where last file has been saved (maybe asking for it) at the end of the recording
# translate messanges
#
# assign as default stream value the one passed ad first parameters if any (check TBD)
STREAM=$1
TEMPDIR=/tmp
# inizialize variables
LISTENERmode=0 # if 0 listener in separate window with xterm
# if 1 listener without separate window
EXIT=1
STATE=1
if [ $LISTENERmode -eq 1 ]
then
PIDlistener2=""
fi
PIDrecorder2=""
while [ $EXIT -eq 1 ]
do
case $STATE in
0)
kdialog --title "RadioRecorder" --yesno "Do you want to exit the program?"
EXIT=$?
if [ $EXIT -eq 1 ]
then
STATE=1
fi
;;
1)
# ask radio stream URL
STREAM=`kdialog --title "RadioRecorder" --inputbox "Insert the radio stream url" $1 `
STREAMBUTTON=$?
if [ $STREAMBUTTON -eq 1 ]
then
STATE=0
else
# start mplayer in background to listen to the radio only if the ok button has been selected else exit
if [ $LISTENERmode -eq 1 ]
then
mplayer -vo null -vc null -cache 512 $STREAM&
else
xterm -e mplayer -vo null -vc null -cache 512 $STREAM&
fi
PIDlistener=$! # listener PID
if [ $LISTENERmode -eq 1 ]
then
while [ -z $PIDlistener2 ]
do
#repeat the check till PIDlistener2 is correctly detected
PIDlistener2=`ps -ef| awk '$3 == '$PIDlistener' { print $2 }'`
done
fi
STATE=2
fi
;;
2)
# select action to do
ACTION=`kdialog --title "RadioRecorder" --menu "Select an action:" 1 "Change URL" 2 "Record stream"`
ACTIONBUTTON=$?
if [ $ACTIONBUTTON -eq 1 ]
then
ACTION=$ACTIONBUTTON # if cancel is selected go back to url dialog
fi
if [ $ACTION -eq 1 ]
then
#if Change URL or Cancel has been selected kill listener and go back to URL page
#kill listener processes
if [ $LISTENERmode -eq 1 ]
then
kill -9 $PIDlistener2
fi
kill -9 $PIDlistener
# reinitialize PID variables
PIDlistener=""
if [ $LISTENERmode -eq 1 ]
then
PIDlistener2=""
fi
STATE=1
else
STATE=3
fi
;;
3)
# ask destination directory -- default home
DIR=$HOME
DIR=`kdialog --title "RadioRecorder - Select destination directory" --getexistingdirectory $DIR` #default destination directory is the user home
DIRBUTTON=$?
if [ $DIRBUTTON -eq 1 ]
then
#if Cancel has been selected go back to action page
STATE=2
else
STATE=4
fi
;;
4)
# ask file name at which will be added the date and eventually record stream
FILENAME="radio"
FILENAME=`kdialog --title "RadioRecorder - Save as" --inputbox "Insert the file name (date will be automatically added)" $FILENAME`
FILENAMEBUTTON=$?
if [ $FILENAMEBUTTON -eq 1 ]
then
#if Cancel has been selected go back to action page
STATE=3
else
#capture stream
DATE=`date +%Y_%m_%d_%H%M%S`
TEMPFILE=$TEMPDIR/$FILENAME-$DATE
FILE=$DIR/$FILENAME-$DATE
mkfifo $TEMPFILE.wav
lame $TEMPFILE.wav $FILE.mp3>/dev/null&
PIDconverter=$! #converter PIN
mplayer -cache 512 -vo null -vc null -ao pcm:fast:file="$TEMPFILE.wav" $STREAM>/dev/null&
PIDrecorder=$! #recorder PIN
while [ -z $PIDrecorder2 ]
do
#repeat the check till PIDrecorder2 is correctly detected
PIDrecorder2=`ps -ef| awk '$3 == '$PIDrecorder' { print $2 }'`
done
kdialog --msgbox "Press OK button to stop recording"
#stop recording
#kill converter
kill -9 $PIDconverter
#kill recorder processes
kill -9 $PIDrecorder2
kill -9 $PIDrecorder
# reinitialize PID variables
PIDconverter=""
PIDrecorder=""
PIDrecorder2=""
#removing temporary file
rm $TEMPFILE.wav
#go back to action page
STATE=2
fi
;;
esac
done
kdialog --title "RadioRecorder" --msgbox "Thank you for using radioRecorder"
echo "Bye Bye"
exit
negli ultimi giorni ho creato questo script che permette di registrare le radio internet (anche quelle che non si trovano su shoutcast e simili tipo le radio rai, la bbc, radio deejey) in mp3.
Mi sono basato in parte su quanto esposto qui:
http://walkingtowel.org/2006/03/03/record-streaming-audio-with-linux-part-ii/
modificandolo in modo da avere una sorta di interfaccia grafica (ho usato kdialog per cui penso sia utile solo per gli utenti kde) che permettesse di selezionare i vari parametri e di iniziare e terminare la registrazione.
Che ne pensate?
Come faccio a pubblicarlo per renderlo disponibile a tutti?
Se vedete lo script ho usato xterm perchè mplayer una volta che si è connesso alla radio si duplica diventando due processi.
Se faccio partire mplayer dentro xterm, uccidendo xterm uccido tutti i processi figli. Se lo avviao senza xterm conosco il pin solo del primo processo mplayer e il secondo rimane vivo.
Per me va anche bene così solo che se l'utente chiude la finestra di xterm non è previsto alcun controllo nel programma.
Insomma mancano ancora alcune cose da fare, ma gradirei un vostro aiuto e vostri pareri.
Grazie,
Xwang
#!/bin/bash
# radioRecoder.sh
# v0.3.0 - 20080814
# Xwang <[email protected]>
# Released under GPL 2.0 and following (can you help me and tell if it is GPL3 compliant?)
# This script acts as a wizard enabling the user to select the URL to listen and eventually rip it after having specified
# the directory and the file name
# The cancel button is used to go to the previous page
# To exit the program press cancel in the URL page and follow the instruction
# TBD
# store inserted URL in external file and use them in a combobox
# check if parameter is passed or not
# modify parameters so that recording can be done without user iteration
# capture Ctrl-C in order to clean all temporary files and kill opened processes before closing
# give some indication on recording time and if possible file dimension
# put confirmation on registration stop
# open the directory where last file has been saved (maybe asking for it) at the end of the recording
# translate messanges
#
# assign as default stream value the one passed ad first parameters if any (check TBD)
STREAM=$1
TEMPDIR=/tmp
# inizialize variables
LISTENERmode=0 # if 0 listener in separate window with xterm
# if 1 listener without separate window
EXIT=1
STATE=1
if [ $LISTENERmode -eq 1 ]
then
PIDlistener2=""
fi
PIDrecorder2=""
while [ $EXIT -eq 1 ]
do
case $STATE in
0)
kdialog --title "RadioRecorder" --yesno "Do you want to exit the program?"
EXIT=$?
if [ $EXIT -eq 1 ]
then
STATE=1
fi
;;
1)
# ask radio stream URL
STREAM=`kdialog --title "RadioRecorder" --inputbox "Insert the radio stream url" $1 `
STREAMBUTTON=$?
if [ $STREAMBUTTON -eq 1 ]
then
STATE=0
else
# start mplayer in background to listen to the radio only if the ok button has been selected else exit
if [ $LISTENERmode -eq 1 ]
then
mplayer -vo null -vc null -cache 512 $STREAM&
else
xterm -e mplayer -vo null -vc null -cache 512 $STREAM&
fi
PIDlistener=$! # listener PID
if [ $LISTENERmode -eq 1 ]
then
while [ -z $PIDlistener2 ]
do
#repeat the check till PIDlistener2 is correctly detected
PIDlistener2=`ps -ef| awk '$3 == '$PIDlistener' { print $2 }'`
done
fi
STATE=2
fi
;;
2)
# select action to do
ACTION=`kdialog --title "RadioRecorder" --menu "Select an action:" 1 "Change URL" 2 "Record stream"`
ACTIONBUTTON=$?
if [ $ACTIONBUTTON -eq 1 ]
then
ACTION=$ACTIONBUTTON # if cancel is selected go back to url dialog
fi
if [ $ACTION -eq 1 ]
then
#if Change URL or Cancel has been selected kill listener and go back to URL page
#kill listener processes
if [ $LISTENERmode -eq 1 ]
then
kill -9 $PIDlistener2
fi
kill -9 $PIDlistener
# reinitialize PID variables
PIDlistener=""
if [ $LISTENERmode -eq 1 ]
then
PIDlistener2=""
fi
STATE=1
else
STATE=3
fi
;;
3)
# ask destination directory -- default home
DIR=$HOME
DIR=`kdialog --title "RadioRecorder - Select destination directory" --getexistingdirectory $DIR` #default destination directory is the user home
DIRBUTTON=$?
if [ $DIRBUTTON -eq 1 ]
then
#if Cancel has been selected go back to action page
STATE=2
else
STATE=4
fi
;;
4)
# ask file name at which will be added the date and eventually record stream
FILENAME="radio"
FILENAME=`kdialog --title "RadioRecorder - Save as" --inputbox "Insert the file name (date will be automatically added)" $FILENAME`
FILENAMEBUTTON=$?
if [ $FILENAMEBUTTON -eq 1 ]
then
#if Cancel has been selected go back to action page
STATE=3
else
#capture stream
DATE=`date +%Y_%m_%d_%H%M%S`
TEMPFILE=$TEMPDIR/$FILENAME-$DATE
FILE=$DIR/$FILENAME-$DATE
mkfifo $TEMPFILE.wav
lame $TEMPFILE.wav $FILE.mp3>/dev/null&
PIDconverter=$! #converter PIN
mplayer -cache 512 -vo null -vc null -ao pcm:fast:file="$TEMPFILE.wav" $STREAM>/dev/null&
PIDrecorder=$! #recorder PIN
while [ -z $PIDrecorder2 ]
do
#repeat the check till PIDrecorder2 is correctly detected
PIDrecorder2=`ps -ef| awk '$3 == '$PIDrecorder' { print $2 }'`
done
kdialog --msgbox "Press OK button to stop recording"
#stop recording
#kill converter
kill -9 $PIDconverter
#kill recorder processes
kill -9 $PIDrecorder2
kill -9 $PIDrecorder
# reinitialize PID variables
PIDconverter=""
PIDrecorder=""
PIDrecorder2=""
#removing temporary file
rm $TEMPFILE.wav
#go back to action page
STATE=2
fi
;;
esac
done
kdialog --title "RadioRecorder" --msgbox "Thank you for using radioRecorder"
echo "Bye Bye"
exit