Very basic synchronization of podcasts between iTunes and my Palm
By some unfortunate turn of events, I find myself without an iPod and wanting to listen to some podcasts. But as I have something that should be able to play mp3 and aac files (namely a Palm T|T3), I decided to use it to listen to them.
Now everything works well, with one glaring exception: there is no automatic way to tell iTunes that I listened to a podcast, hence removing it from my (very small) playlist that has to fit on a small SD card. The crux of the issue is that I could not find a player that recorded the played count and could update it on iTunes.
So I decided to take another route: podcasts are just files, so they are synchronized using the Missing Sync file synchronization conduit. When I listen to them on iTunes, they get removed from the smart playlist I use (when their played count is greater than 0), so by getting the files out of iTunes to some folder on my laptop, I could get a one way synchronization.
To have a two way synchronization (files listened on the palm gets removed from the playlist), I decided to do the following simple approach: when I have listened to a podcast on the palm, I delete it from the card, and upon next Missing Sync synchronization, it gets removed from the corresponding laptop folder.
So now I have to tie all this together, by remembering which files went on the palm. The idea is fairly simple (and shamelessly steals from the archive idea of Unison).
- For every track in the iTunes playlist that is not present in the folder
- if it not mentioned in the archive, it is new, so it is copied to the folder, and an empty file is created in the archive with the same name and its comment sets to the track name;
- if it is mentioned in the archive, it was deleted (hence listened on the palm), so the track gets a played count of 1 (which removes it from the smart play list).
- For every file in the archive, if its comment is not the title of a track in the iTunes smart playlist, it was listened in iTunes, so the archive file and the track file are deleted (and will be removed from the Palm).
I'm using the fact that files will never be added on the Palm side, which make the previous algorithm a bit better.
Now for the implementation: - the script run on my home machine (that has the iTunes library); - the folder with the songs is synchronized to the laptop using Unison; - the folder on the laptop is synchronized with the Palm using Missing Sync.
And the script. Have fun ;-)
-- the root directory
set palmtunes to alias ((path to desktop folder as text) & "PalmTunes")
-- the directory to synchronize with the Palm
set filetunes to alias ((palmtunes as text) & "Files")
-- the directory to hold the archives (to remember what was synchronized
set archtunes to alias ((palmtunes as text) & "archive")
tell application "iTunes"
-- the following playlist should be a smart playlist that only contain
-- songs with a play count of 0
set smartlist to user playlist "AB Palm"
set palmtracks to a reference to file tracks of smartlist
-- We first synchronize songs that are present in iTunes
repeat with aTrack in palmtracks
set trackfile to location of aTrack
set trackname to name of aTrack
set filename to name of (info for trackfile)
tell application "Finder"
if not (exists file filename of filetunes) then
-- was it synchronized?
if (exists file filename of archtunes) then
-- it was synchronized and has been deleted on the palm, then
-- remove it from iTunes
tell application "iTunes"
set (played count of aTrack) to 1
end tell
set theFile to alias ((archtunes as text) & filename)
delete theFile
else
duplicate trackfile to filetunes
make new file at archtunes with properties {name:filename, comment:trackname}
end if
end if
end tell
end repeat
-- We now remove songs that are present in the archive but not in the
-- playlist anymore
tell application "Finder"
set archfiles to items of folder archtunes
repeat with aFile in archfiles
set trackname to the comment of aFile
-- search if the track is in the playlist
tell application "iTunes"
set mytrack to (every track of smartlist whose name is trackname)
end tell
if (length of mytrack is 0) then
-- This track was removed from iTunes, we need to remove it
set aFileName to name of aFile
delete aFile
delete (alias ((filetunes as text) & aFileName))
end if
end repeat
end tell
end tell
4 comments were on Haloscan
Sigh I wish I was more familiar with AppleScript. How should I modify this script to use with a Finder folder of files, instead of an iTunes playlist, but still updating the iTunes playcount?
Jim A Syler | Homepage | 05.01.07 - 18:52
I'm really no expert at AppleScript either (I believe it's a read-only language). The tricky part is figuring out which files correspond to which iTunes entry. To do so, you can look at the last part of the script, where I look at every file present in the folder, get the track name from the spotlight comments (where I first set them), and search for it in iTunes. (You can specify the whole Library as the playlist, if I remember correctly.)
Good luck.
Alan Schmitt | Homepage | 05.01.07 - 19:34
Haha! I did it! I'll post the result on my blog and trackback it to here. Thanks for your wonderful script; it wouldn't have been possible without it!
Jim A Syler | Homepage | 08.01.07 - 23:32
Cool. I could not find your post on your blog though (the last one is from mid-december).
Alan Schmitt | Homepage | 09.01.07 - 10:07
0 TrackBacks
Listed below are links to blogs that reference this entry: Very basic synchronization of podcasts between iTunes and my Palm.
TrackBack URL for this entry: http://alan.petitepomme.net/cgi-bin/mt/mt-tb.cgi/39
Leave a comment