November 28, 2007

iTunes 7.5 Watched Folders / Folder Sync (That Doesn't Suck)

As a long time WinAmp user and iPod owner, one of the many things that annoys me is its inability to sync to a folder or folders. I only use iTunes for managing my iPods, and a number of other programs for working with my video and music collection. I've tried various utilities in the past, most require a 50mb .NET Framework download and seem to break with every new iTunes version. So after hearing about the iTunes SDK, and that you could work with it via Windows Scripting Host in JavaScript (a language I know very well), I decided to write my own. The nice thing about using the COM interface is you've telling iTunes to work with its database on your behalf, so the script won't break when iTunes 8 is released for example. Oh and my script is only 12KB.

The goals for the my sync script were to: Add any new files that weren't in the iTunes database, remove any that were missing* and check if the MP4 or iD3 tags in the files have been updated (with Tag&Rename or Atomic Parsley for example) and make the necessary updates in iTunes. Some of my media is on external drives, video especially, so if the base folder for a certain media type is offline the script doesn't remove any missing media files of that type. When the drive with these files is reconnected everything will still work correctly in iTunes.

Currently the script has base folders for Music, Films and TV Shows (music videos are treated as normal music files). The script looks for files directly inside these folders and in subfolders one level deep. It checks files of extensions .mp3, .mp4, .m4a and .m4v. If you need something other than this setup, feel free to modify the script as necessary, but please don't ask me to make changes as I really don't have the time and this is how my library is setup. The code is well commented enough to be a good starting point for making your own script though.

When you run it a dialog will appear with your current base folders (these are stored in HKCU in the registry). Clicking YES will proceed with the folders displayed, NO will prompt you for folders and then proceed, and CANCEL will exit without doing anything. The script will start iTunes if it isn't running and start checking, there's no progress display (sorry I don't think this is possible with WSH) and will take about 30 seconds on most libraries (mine has 8000 items and averages about that), it will display a dialog with changes made when complete. If it finds a large number of items to add, it will prompt you with a dialog prior to this with a time estimate and ask whether you wish to proceed with the add operation. The script only modifies the iTunes database, it makes no changes to the actual media files themselves.

Notes: For files were the tags have been updated outside iTunes, things like Play Counts etc are preserved. You can also just press ENTER on the main dialog to proceed.

iTunesFolderSync.wsf (12KB)

Posted by Matt at November 28, 2007 9:58 AM

Fraggle Chitter Chatter

Have Your Say

Remember me?



 (not displayed on site)