# ----------------------------------------------------------------------------------------------- # Author: Dean Stringer # Original Release Date: 14/2/2007 # Description/Purpose: # Builds RSS file of new files found in local iTunes MP3 folders # ----------------------------------------------------------------------------------------------- use MP3::Info; use File::stat; use Digest::MD5 qw(md5_hex); my $rootDir = 'C:\\Documents and Settings\\me\\My Documents\\My Music\\iTunes\\iTunes Music\\Podcasts\\'; my @dirs = ( 'IT Conversations', 'Perlcast', 'Jon Udell' ); my $daysToCheck = 7; my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @days = qw(Mon Tue Wed Thu Fri Sat Sun); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $thisRenderTime = sprintf("%s, %02d %s %u %02d:%02d:%02d +1200", $days[$wday-1],$mday,$months[$mon],($year + 1900),$hour,$min,$sec); my $timeNow = time; my @newFiles; # check each of our podcast folders for files modified in the last 'n' days foreach my $subDir (@dirs) { opendir DIR, $rootDir . $subDir; while ( $filename = readdir(DIR) ) { if ($filename =~ /\.mp3$/) { my $st = stat($rootDir . $subDir . '\\' . $filename) or die "No $filename: $!"; $minTime = 60 * 60 * 24 * $daysToCheck; # only want files < 1 day old if (($timeNow - $st->mtime) < $minTime) { my %fileDetails = ( path => $subDir . '\\' . $filename, url => $subDir . '/' . $filename, size => $st->size, ); push @newFiles, { %fileDetails }; } } } closedir DIR; } # create an RSS 2.0 file use XML::RSS; my $rss = new XML::RSS (version => '2.0'); $rss->channel(title => 'My podcast aggregator', link => 'http://mysite.com', language => 'en', description => 'archive of web related podcasts downloaded from the web over the last ' . $daysToCheck . ' days for local on-campus distribution', pubDate => "$thisRenderTime", lastBuildDate => "$thisRenderTime", managingEditor => 'me@mysite.com', webMaster => 'me@mysite.com' ); $rss->image(title => 'Web Team', url => 'http://mysite.com/images/logo.gif', link => 'http://mysite.com', width => 150, height => 200, description => '' ); # add an RSS item for each entry if (@newFiles) { foreach my $fileDetailsArr (@newFiles) { my %fileDetails = %{$fileDetailsArr}; my $info = get_mp3info($rootDir . $fileDetails{path} ); my $tags = get_mp3tag($rootDir . $fileDetails{path}) or die "No TAG info"; my $comments = join (' ', @{$tags->{COMMENT}}); $comments =~ s/[^a-z\s\d:\-,\.\/]//gi; $comments =~ s/iTunPGAP 0//; my $digest = md5_hex($fileDetails{path}); $rss->add_item( title => $tags->{TITLE}, permaLink => "http://mysite.com/podcasts/" . $fileDetails{url}, enclosure => { url => "http://mysite.com/podcasts/" . $fileDetails{url}, type=>"audio\/mpeg", length => $fileDetails{size} }, description => "$comments", ); } } # dump out the RSS, even if no entries print $rss->as_string;