gurutech
30-01-2009, 14:10
Ciao,
oggi ho scritto questo, magari serve a qualcuno! si basa su mplayer e lame
e vi permette di salvare una Internet radio su hard disk
#!/bin/bash
# grab-radio - this script will grab an audio stream to your hard disk
#
# Copyright (C) 2009 Gianluca 'gurutech' Mascolo gianluca@gurutech.it
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#Requirements: mplayer, lame, standard GNU/Linux tools (bash, ps, sleep, date, ... and so on)
#when this scripts finish, you will have
#radioXXXX.mp3
#radioYYYY.mp3
#...
#stored in the output directory
MPPID=0
CURDIR="$PWD"
#change to dir where do you want to save streams
cd /home/gmascolo/downloads
RADIOURL="http://67.212.179.138:8300/"
#divide raw streams in 204800Kbytes (200MB) trunks
MAXSTREAMSIZE=204800
spawnmp ()
{
mplayer -really-quiet -ao pcm:waveheader:file=radio.wav -vo null -vc dummy "$RADIOURL" 2> /dev/null &
sleep 1
MPPID=$(jobs -l | grep radio.wav | awk '{print $2}' | grep -v "^$MPPID$" )
return $MPPID
}
STIME=$(date +%s)
ETIME=$STIME
ELAPSED=$((ETIME-STIME))
#Stop after 4000 seconds elapsed
while ( [ $ELAPSED -lt 4000 ] ); do {
clear
MPISDEAD=0
STREAMSIZE=0
OLDSIZE=-1
spawnmp
while ( [ $MPISDEAD -eq 0 ] && [ $STREAMSIZE -lt $MAXSTREAMSIZE ] ); do {
clear
date
echo $ETIME
echo "Mplayer running in background with PID=$MPPID"
sleep 5
STREAMSIZE=$(du -sk radio.wav | awk '{print $1}')
[ $OLDSIZE -lt $STREAMSIZE ] || kill $MPPID
OLDSIZE=$STREAMSIZE
MPISDEAD=0
ps --pid $MPPID h &> /dev/null || MPISDEAD=1
echo $MPISDEAD
}
done
ETIME=$(date +%s)
[ $MPISDEAD -eq 0 ] && kill $MPPID
du -sk radio.wav
rm -f grabbed.wav
mv radio.wav grabbed.wav
lame -S grabbed.wav radio$ETIME.mp3 &
ELAPSED=$((ETIME-STIME))
}
done
rm -f radio.wav
cd "$CURDIR"
oggi ho scritto questo, magari serve a qualcuno! si basa su mplayer e lame
e vi permette di salvare una Internet radio su hard disk
#!/bin/bash
# grab-radio - this script will grab an audio stream to your hard disk
#
# Copyright (C) 2009 Gianluca 'gurutech' Mascolo gianluca@gurutech.it
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#Requirements: mplayer, lame, standard GNU/Linux tools (bash, ps, sleep, date, ... and so on)
#when this scripts finish, you will have
#radioXXXX.mp3
#radioYYYY.mp3
#...
#stored in the output directory
MPPID=0
CURDIR="$PWD"
#change to dir where do you want to save streams
cd /home/gmascolo/downloads
RADIOURL="http://67.212.179.138:8300/"
#divide raw streams in 204800Kbytes (200MB) trunks
MAXSTREAMSIZE=204800
spawnmp ()
{
mplayer -really-quiet -ao pcm:waveheader:file=radio.wav -vo null -vc dummy "$RADIOURL" 2> /dev/null &
sleep 1
MPPID=$(jobs -l | grep radio.wav | awk '{print $2}' | grep -v "^$MPPID$" )
return $MPPID
}
STIME=$(date +%s)
ETIME=$STIME
ELAPSED=$((ETIME-STIME))
#Stop after 4000 seconds elapsed
while ( [ $ELAPSED -lt 4000 ] ); do {
clear
MPISDEAD=0
STREAMSIZE=0
OLDSIZE=-1
spawnmp
while ( [ $MPISDEAD -eq 0 ] && [ $STREAMSIZE -lt $MAXSTREAMSIZE ] ); do {
clear
date
echo $ETIME
echo "Mplayer running in background with PID=$MPPID"
sleep 5
STREAMSIZE=$(du -sk radio.wav | awk '{print $1}')
[ $OLDSIZE -lt $STREAMSIZE ] || kill $MPPID
OLDSIZE=$STREAMSIZE
MPISDEAD=0
ps --pid $MPPID h &> /dev/null || MPISDEAD=1
echo $MPISDEAD
}
done
ETIME=$(date +%s)
[ $MPISDEAD -eq 0 ] && kill $MPPID
du -sk radio.wav
rm -f grabbed.wav
mv radio.wav grabbed.wav
lame -S grabbed.wav radio$ETIME.mp3 &
ELAPSED=$((ETIME-STIME))
}
done
rm -f radio.wav
cd "$CURDIR"