#!/usr/bin/perl -w # $Id: streamrip,v 1.7 2004/10/08 19:56:11 dean Exp $ # crude script for recording streaming audio shows with mplayer. # here's an example from my crontab -- which uses the shoutcast-search # script to find the current stream url (kcrw shoutcast urls seem to # change every couple of months -- and even though there are .pls entries # on kcrw.org i find those tend not to always work). # # RIP=streamrip # KCRW_DIR=/music/music/radio/kcrw # 29 19 * * 1,3,4,5 $RIP $KCRW_DIR/metropolis/ mp3 152 "`shoutcast-search 'kcrw simulcast'`" # 59 21 * * 1,3,4,5 $RIP $KCRW_DIR/nocturna/ mp3 122 "`shoutcast-search 'kcrw simulcast'`" # # and an ogg example: # # KPFA_DIR=/music/music/radio/kpfa # KPFA_STREAM='http://aud-one.kpfa.org:8090/kpfa.ogg' # 59 21 * * 1 $RIP $KPFA_DIR/off_the_beaten_path/ ogg 122 "$KPFA_STREAM" # 59 19 * * 1 $RIP $KPFA_DIR/transitions_on_traditions/ ogg 122 "$KPFA_STREAM" use strict; use POSIX; sub usage { die "usage: $0 outputbasename extension length_in_minutes url\n"; } my $basename = shift or usage(); my $ext = shift or usage(); my $length = shift or usage(); my $url = shift or usage(); my $d = strftime("%Y%m%d-%H%M",localtime); my $child = fork; defined($child) or die "$0: error forking: $!\n"; if ($child == 0) { # mplayer -quiet still spews 2MB of "Cache fill" crap open(STDOUT, "|grep -v 'Cache fill:'") or die "unable to reopen STDOUT: $!\n"; open(STDERR, ">&STDOUT") or die "unable to reopen STDERR: $!\n"; # we use -dumpstream to support ogg streams -- for whatever reason # -dumpaudio creates unusable output for ogg exec('mplayer', '-quiet', '-dumpstream', '-dumpfile', "$basename$d.$ext", "-playlist", "$url"); die "$0: unable to exec mplayer: $!\n"; } $SIG{ALRM} = sub { kill 15, $child; exit; }; alarm($length * 60); wait; # # Copyright (c) 2004 Dean Gaudet # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE.