Import Podcasts into iTunes
Use Perl scripts and iTunes’ COM interface to automate MP3 importing on Windows; on the Mac, it’s even easier.
iTunes for Windows supports a powerful scripting layer using Windows COM interfaces. ActiveState Perl (http://activestate.com/) complements thisby making it easy to automate COM objects. I merged these two together to build a Perl script that complements the command-line podcatcher [Hack #3] .
The podcatcher downloaded all the enclosure files into an enclosures directory that was organized by show. This means that the script in this hack needs to crawl the directory structure to find the MP3s to import them, and then update your iPod. This is not a problem, though, since the
File::Find module
[Hack #7]
makes searching through a tree of directories a snap.
With the problem of finding the files out of the way, the script uses the
Win32::OLEmodule to tell iTunes to import the files.
The Code
Save this code to a file named addtoitunes.pl:
#!perl -wuse Win32::OLE;use File::Find;use strict; # iTunes refers to importing as 'converting' in its COM interface. # So we convert each path. sub convert($$) { my ( $itunes, $path ) = @_; # Make sure it's an MP3 file return unless ( $path =~ /[.]mp3$/ ); print "Converting $path\n"; # Start the conversionmy $progress = $itunes->ConvertFile2( $path );# Monitor the SLOW progress my $done = 0; my $lp = -100; while( !$done ) {my $p = int( $progress->ProgressValue() );my $m = int( $progress->MaxProgressValue() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access