#!/usr/bin/perl -W use strict; # AUTHOR: Joshua V. Dillon # DATE: May 11, 2005 # DESCRIPTION: # This script downloads NPR Morning Edition RealAudio streams, # converts them to wave, then re-encodes them to MP3. It is # done in parallel, as much as possible. There is no checking # to verify that the show is there. If it isn't, things will # get a bit messy. Make sure to update '$mplayer', '$lame', # and '$savepath'. # INPUT 1: # YEARMONTHDAYSHOW # For example: 20050509ME # would refer to: Morning Edition of May 5, 2005 # INPUT 2: # dayminusDAYSHOW # For example: dayminus5TOTN # would refer to: Talk of the Nation from 5 days ago # INPUT 3: # Invalid input will download today's Morning Edition # npr.org show codes: # ME Morning Edition # ATC All Things Considered # DAY Day to Day # TOTN Talk of the Nation # FA Fresh Air # WESAT Weekend Edition Saturday # WESUN Weekend Edition Sunday # FOOL Motley Fool Radio # jvd: the following binaries (and their paths) are required my $mplayer = '/usr/bin/mplayer'; my $lame = '/usr/bin/lame'; my $urlbase = 'http://www.npr.org'; my $savepath = $ARGV[1]; # jvd: if you get an error, try: # perl -MCPAN -e "shell" # "install LWP" use LWP::UserAgent; use File::Copy; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my $show; # jvd: matching input of the following form: 20050509show if($ARGV[0]=~/(\d{4})(\d{2})(\d{2})(\w+)/g){ $year = $1; $mon = $2-1; $mday = $3; $show = uc($4); } elsif ($ARGV[0]=~/dayminus(\d+)(\w+)/g){ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time - ($1 * 24 * 60 * 60); $year += 1900; $show = uc($2); } else { # jvd: get today's Morning Edition ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time; $year += 1900; $show = 'ME'; } # jvd: construct date specific strings #print STDERR "$months[$mon] $mday, $year $show\n"; my $savedir = sprintf("%d%02d%02d%s",$year,$mon+1,$mday,$show); mkdir("$savepath/$savedir",0755);# or die "couldn't \"mkdir $savepath/$savedir\": $!"; my $url = sprintf("%s/dmg/dmg.php?prgCode=%s&showDate=%02d-%s-%d&segNum=&NPRMediaPref=RM",$urlbase,$show,$mday,$months[$mon],$year); my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/1.0"); my $response = $ua->request(HTTP::Request->new(GET =>$url)); $response->is_success or die "ERROR: " . $response->status_line; my $page = $response->content; #print STDERR $page; # jvd: data collected from May 9, 2005 Morning Edition # real 25169.920 KB -> 339.1 KB/min # wav 787415.832 KB -> 10609.7 KB/min # mp3 71448.364 KB -> 962.7 KB/min @128kbps # time 74.2167 min # jvd: initialize signaling parameters my $parent = $$; my $numchildren = 0; my $signaled = 0; $SIG{CHLD} = "signal_parent"; while($page=~/