#!/usr/bin/perl use LWP::Simple; # some paths and executables we'll need my $out_dir = '/home/tom/echoradio/'; my $wcat = '/usr/local/bin/wcat'; my $sox = '/usr/bin/sox'; my $text2wave = '/usr/bin/text2wave'; # erase *.gsm (we could try to conserve pre-generated ones, but it's more # work than it's worth) opendir(DIR, $out_dir); @files = grep(/\.gsm$/i,readdir(DIR)); closedir(DIR); foreach $file (@files) { print "deleting " . $out_dir . $file . "\n"; unlink($out_dir . $file); } # retrieve the RSS feed my $rss_content = get('http://feeds.feedburner.com/Echoradio-Echoditto'); # loop through the tags we find my $i = 0; while(($i<10) && ($rss_content =~ m/(\.*?\<\/item\>)/isg)) { # grab the title my ($title, $enclosure) = ''; my $item = $1; if($item =~ /\(.*?)\<\/title\>/isg) { $title = $1; } # look for an echoradio mp3 URL #if($item =~ /\]*url=['"]([^'"]*)['"]/isg) if($item =~ /(http:\/\/radio\.echoditto\.com[^'"]+\.mp3)['"]/isg) { $enclosure = $1; } # convert the filename into something friendlier my $filename = $enclosure; $filename =~ s/^.*\///igx; $filename =~ s/\s/_/igx; # if it's an mp3, download it if($filename =~ /\.mp3$/ig) { # but only if we haven't already if(!(-e ($out_dir . $filename))) { print "retrieving $filename..."; getstore($enclosure,($out_dir . $filename)); print "done\n"; } # put the title in a text file print "writing title to text file..."; open(TITLE, ('>' . $out_dir . 'title.tmp.txt')); print TITLE $title; close(TITLE); print "done\n"; # generate a wav of the title text file print "generating wav of title..."; my $execf = $text2wave . " " . $out_dir . "title.tmp.txt -F 8000 -o " . $out_dir . "title.tmp.txt.wav"; system($execf); print "done\n"; # combine that wav with "for the entry titled..." and "press " print "combining wavs..."; $execf = $wcat . " " . $out_dir . "lib/tolisten.wav " . $out_dir . "title.tmp.txt.wav " . $out_dir . "lib/press" . $i . ".wav -o " . $out_dir . "wholething.tmp.wav"; system($execf); print "done\n"; # use sox to turn that wav into a .gsm file print "converting wav to gsm..."; $execf = $sox . " " . $out_dir . "wholething.tmp.wav -r 8000 " . $out_dir . sprintf("%02d",int($i)) . "-" . $filename . ".gsm"; system($execf); print "done\n"; # remove the temp files print "removing temp files..."; unlink($out_dir . "title.tmp.txt"); unlink($out_dir . "title.tmp.txt.wav"); unlink($out_dir . "wholething.tmp.wav"); print "done\n"; # iterate $i = $i + 1; } print "\n"; }