In the
last post, I covered how to use Perl to get podcasts downloaded with
Juice to show up in the "Podcasts" section of iTunes.
The only real problem with that alone is that you still have to manually delete old podcasts from your podcasts directory (either directly, or using Juice's "Cleanup" tab). That's a pain in the ass. What follows is a nice little windows script that you can run to automatically delete podcast files that you have listened to and deleted in iTunes.
What follows is the content of my PodcastDirCleanup.js file:
var PodcastPath = 'D:\\Podcasts\\';
var iTunesApp = WScript.CreateObject('iTunes.Application');
var mainLibrary = iTunesApp.LibraryPlaylist;
var tracks = mainLibrary.Tracks;
var numTracks = tracks.Count;
var count = 0;
var podcasts = new Object();
while (numTracks != 0){
var currTrack = tracks.Item(numTracks);
if (currTrack.Kind == 1 && currTrack.Genre == 'Podcast'){
podcasts[currTrack.Location] = 1;
}
numTracks--;
}
var fso = new ActiveXObject('Scripting.FileSystemObject');
var pfolder = fso.GetFolder(PodcastPath);
var sf = new Enumerator(pfolder.SubFolders);
for(; !sf.atEnd(); sf.moveNext()){
var ff = new Enumerator(sf.item().Files);
for(; !ff.atEnd(); ff.moveNext()){
var fpath = ff.item().Path;
if(podcasts[fpath] != 1){
//WScript.Echo(ff.item().Path);
fso.DeleteFile(fpath);
count++;
}
}
}
//WScript.Echo(count + ' deletions performed.');
What this does is access your iTunes library and record the file locations of all your podcasts, then loops through your podcasts directory (specified on the first line) and checks the podcast files against the list it got from itunes. If it finds any files that aren't in the iTunes library (presumably because you have already listened to and deleted the episode in iTunes), it deletes the file.
Unfortunately, you can't simply execute the script from the perl script that Juice automatically runs after each download—if you did that it would always delete the file that was just downloaded (because it hasn't been added to the iTunes library until after the script runs). Personally, I have the last line uncommented and run the script manually when I feel like it's been a while since I've cleaned out old episodes, but you could also schedule it to run automatically with the windows scheduler.
I seriously doubt any of this is actually useful to anyone but me, but there you go!