Random Acts of Coding: Creating a Podcast Playlist

by Erica Sadun

This one is for Randy, who would like to sync his shuffle with a playlist. I went ahead and chose audio-only unplayed podcasts, but feel free to modify as needed. The script includes some oddball uses that work but look ugly. Like the conversion of "none" to string and the use of the floc local variable. Got a better way? See some obviously bad coding here? Let me know in the comments. Thanks go to Mark Hunte for several improvements.

tell application "iTunes"

-- Create playlist if it does not already exist
set podString to "Podcast Playlist"
if not (exists playlist podString) then
make new playlist with properties {name:podString}
-- Remove all existing podcasts in playlist
delete every file track of playlist podString
end if

-- Collect every track that has downloaded
set tracklist to every file track of playlist "Podcasts"

-- Add audio-only items that are still unplayed
repeat with eachItem in tracklist
if ((video kind of eachItem) as string is "none") and ((played count of eachItem) is 0) then
set floc to location of eachItem
add floc to playlist podString
end if
end repeat

end tell


Randal L. Schwartz
2007-06-04 11:09:52
Eh? why not just use a smart playlist for this? I have a number of smart playlists that give me audio podcasts, video podcasts, and pull out the ones that I'm keeping semi-permanently rather than listening in sequence.

For example, my "Audio Podcasts" playlist is:
"match all of" "podcast is true" "playcount is 0" "playlist is not in video podcasts"
and my "video podcasts" playlist is:
"match all of" "podcast is true" "kind does not contain audio" "playcount is zero".

It's simple. No need for applescript.

Erica Sadun
2007-06-04 11:19:38
Nice! However, I couldn't figure out how to do the "playlist is not in video podcasts". Here is my best attempt:


2007-06-04 12:30:29
for the smart playlist, just add the rule:

Kind contains audio

and you wont get the video podcasts

I also have the rules:

Genre is Podcast
Play Count is 0

Randy Smith
2007-06-04 13:08:08
Wow, so much help! It really helps that I use iClip and always keep a copy of Devon Notes active all the time.

I don't mind spaghetti code.....you should see some of my basic and assembly language programs ;-)

I think I will try the smart playlist method first. If it works for me then I won't have to worry about updating the podcast playlist as iTunes will do it for me!

Thanks everyone for all the help!

Randal L. Schwartz
2007-06-04 14:20:03
Sorry. I created the video playlist first, so the audio playlist could reference it.
2007-06-04 16:21:53
The suggestions for smart playlists are great, except that what I would like is for only the oldest unplayed episode of each podcast to get copied to my iPod. Because my Shuffle plays podcasts in reverse chronological order, if I don't copy just one episode per podcasts, I will hear them in the wrong order. That doesn't matter for some podcasts, but does for others.

I've been trying to modify this script to do that, but I can't find any way to get the podcast's 'Release Date'. Sorting on the modification date doesn't seem to work reliably.

It may also be that there's some setting I'm overlooking that would change the order the podcasts are played.

2007-06-05 10:10:25
I'm still in search of a way to get only 'new' podcasts in a playlist. Most of the podcasts that I listen to never actually get a play count above zero because I skip past final bits. iTunes knows when a podcast is new... it puts a little dot beside it. Grrr... why isn't that attribute exposed for end users to take advantage of :)
Erica Sadun
2007-06-06 15:11:19
Josh and Andrew: After playing around for a couple of days, the best I can offer you is to try approaching this with shell scripts rather than iTunes. Sorry!