Don't know if there's a splitting utility for oggs?
mp3splt can work on mp3 files as well as ogg files.
Option parsing can be done alternatively with the 'getopts' shell builtin or getopt(1).
Using atd may be more convenient (for a non-recurring action) than setting up a cronjob.
Mplayer has an option '-endpos' (not sure if it works on streams):
-endpos <[[hh:]mm:]ss[.ms]|size[b|kb|mb]> (also see -ss and -sb)
Stop at given time or byte position.
NOTE: Byte position may not be accurate, as it can only stop
at a frame boundary. When used in conjunction with -ss option,
-endpos time will shift forward by seconds specified with -ss.
EXAMPLE:
-endpos 56
Stop at 56 seconds.
-endpos 01:10:00
Stop at 1 hour 10 minutes.
-ss 10 -endpos 56
Stop at 1 minute 6 seconds.
-endpos 100mb
Encode only 100 MB.
I have the tendency of missing all my favorite radio shows so I wrote this little script I can now use as a cron job. Basically it uses mplayer to dump the stream, and kills it after desired time. I'm not posting this to community contributions (yet), since it's far from fail safe. I don't have much time to put into it, and it works for me as it it, but if you find it useful and want to help improving it, please do so!! I really could use some help checking the passed command line arguments, I haven't done these before.
My cron job is starting a couple of minutes before the actual broadcast and I set the length so that the recording continues a couple of minutes after the end time. After it's all done, I use mp3splt to cut the extras. ..that's of course if the stream is an mp3.. Don't know if there's a splitting utility for oggs?
And the script:
#!/bin/sh
# usage:
# stream_dump.sh -u URL -l length -d directory -o filename -t filetype -i
# -u stream URL or a path to a playlist file (.pls, m3u..)
# -l lenght in sleep format, see sleep --help (use quotes if more than one arg!)
# -o base name of recorded file
# -d directory to save the file in
# -t filetype (mp3, ogg, wma ..)
# -i ignore postfix, see POSTFIX below
# Set some defaults
DUMPDIR="/path/to/your/dir"
LENGTH=60m
FILE=StreamDump
FILETYPE=mp3
POSTFIX=_`date +%y-%m-%d_%H:%M`
#############################
# Begin script
#####
while [ $# -gt 0 ]; do
case "$1" in
-u)
STREAM="$2"
shift
;;
-l)
LENGTH="$2"
shift
;;
-o)
FILE="$2"
shift
;;
-t)
FILETYPE=".$2"
shift
;;
-d)
DUMPDIR="$2"
shift
;;
-i)
POSTFIX=""
;;
esac
shift
done
[ ! -d "${DUMPDIR}" ] && mkdir -p "${DUMPDIR}"
DUMPFILE="${DUMPDIR}/${FILE}${POSTFIX}${FILETYPE}"
mplayer -quiet -dumpstream -playlist "${STREAM}" \
-dumpfile "${DUMPFILE}" &
PID="$!"
sleep "${LENGTH}"
kill "${PID}"
#####
# End script
################ #### ## #
Comments, improvements and anything else accepted!
]]>