I said I was looking into getting FIFOs working so that the filesize requirements would be reduced. It’s also more efficient this way. I was heavily influenced by the two scripts created by Daniel Howard.
So here’s how it works. You get to create two scripts. The first one is for recording. It’s an all-purpose script that I called record.sh. Here is the code:
[bash]#!/bin/bash
#
# record.sh
#
# Use mplayer to capture the stream
# at $STREAM to the file $FILE
#
# example: record.sh my_radio_show 60 mms://someserver.com/stream
DIR=/home/shawn/PodCasts #directory where to save the file
TEMPDIR=/tmp
# Don’t edit anything below this line
#######################################################
DATE=`date +%d-%b-%Y` # Save the date as DD-Mmm-YYYY
YEAR=`date +%Y` # Save just the year as YYYY
NAME=$1
DURATION=$2 # enough to catch the show, plus a bit
STREAM=$3
TEMPFILE=$TEMPDIR/$NAME-$DATE
FILE=$DIR/$NAME-$DATE # Where to save it
# Capture Stream
mkfifo $TEMPFILE.wav
mkfifo $TEMPFILE-silenced.wav
# The lame settings below are optimized for voice encoding
# The sox command below strips out any silent portions
lame -S -a -m m –ty “$YEAR” –vbr-new -V 9 –lowpass 13.4 –athaa-sensitivity 1 \
–resample 32 $TEMPFILE-silenced.wav $FILE.mp3 >/dev/null &
sox $TEMPFILE.wav -c 1 $TEMPFILE-silenced.wav \
silence 1 0.2 0.5% -1 0.2 0.5% >/dev/null&
/usr/bin/mplayer -quiet -cache 500 \
-ao pcm:file=”$TEMPFILE.wav” -vc dummy -vo null \
-noframedrop $STREAM >/dev/null&
sleep 5
# get the pid of all processes started in this script.
PIDS=`ps auxww | grep $TEMPFILE | awk ‘{print $2}’`
# the & turns the capture into a background job
sleep `echo ${DURATION}*60 | bc` # wait for the show to be over
kill $PIDS # kill the stream capture
rm $TEMPFILE.wav
rm $TEMPFILE-silenced.wav[/bash]
This script takes three args:
- the name of the show you’re recording. This will be used in the final filename with the current date appended.
- the length of the show in minutes
- the URI of the stream (often
mms:// or http://)
This integrates very well with another script that will hold all the data for the shows we want to record and automatically set the start times for us. Here is my script that I called today.sh
[bash]#!/bin/sh
#
# today.sh — schedule what programs you want to rip today using the
# recorder script.
# Non-obvious paths
RECORDER=$HOME/bin/record.sh
RECORDER_HI=$HOME/bin/record-hi.sh
# Set up stations
KFI=”http://a814.l1977144512.c19771.g.lm.akamaistream.net/D/814/19771/v0001/reflector:44512?MSWMExt=.asf”
WXNT=mms://wmc1.liquidviewer.net/WXNT
WPGB=”http://84.53.144.36:80/D/1046/20063/v0001/reflector:43803?MSWMExt=.asf”
KOZZ=mms://lotusradio-kozz.wm.llnwd.net/lotusradio_kozz
# What day is it?
TODAY=`date +%a`
# EVERY DAY
#everyday() {}
# WEEKDAYS
weekday() {
# “Record John_Ziegler for three hours, starting at 7:00pm.”
echo $RECORDER John_Ziegler 180 $KFI | at 7:00pm
echo $RECORDER Glenn_Beck 180 $WPGB | at 6:00am
}
# MONDAY
if [ $TODAY = "Mon" ]; then
# everyday
weekday
fi
# TUESDAY
if [ $TODAY = "Tue" ]; then
# everyday
weekday
fi
# WEDNESDAY
if [ $TODAY = "Wed" ]; then
# everyday
weekday
fi
# THURSDAY
if [ $TODAY = "Thu" ]; then
# everyday
weekday
fi
# FRIDAY
if [ $TODAY = "Fri" ]; then
# everyday
weekday
fi
# SATURDAY
if [ $TODAY = "Sat" ]; then
# everyday
echo $RECORDER Handel_On_The_Law 300 $KFI | at 6:00am
echo $RECORDER Dr_Dean_Edell 60 $KFI | at 2:00pm
fi
# SUNDAY
if [ $TODAY = "Sun" ]; then
# everyday
echo $RECORDER Jesus_Christ_Show 180 $KFI | at 6:00am
echo $RECORDER Glenn_Beck 180 $WPGB | at 10:00am
echo $RECORDER_HI Dr_Demento 120 $KOZZ | at 10:00pm
fi[/bash]
Using this as a template you might notice another script being referred to. record.sh has audio processing optimized for talk radio. For higher quality and stereo, you need to change a few things. You can download all of the scripts mentioned here at the bottom of this post.
To finish off this solution you need to run today.sh at some point after 12:00am and before the start of the earliest program you wish to record. I set mine to run daily at 1:00am.
[code]# Schedule recordings for today from radio streams
0 1 * * * /home/shawn/bin/today.sh >& /dev/null[/code]
Downloads:
Recent Comments