Tuesday, July 05, 2011

Sync, then add new MP3s from a folder to iTunes

The "Sitch":
Like many "advanced" users, I reluctantly use iTunes because it's the most straightforward way to load my iPod. However, less than 0.01%* of my content was purchased from the iTunes store, and there is absolutely no way that I will ever allow iTunes to organize obliterate my folder and file structure. When I rip a disc, buy a $5 album from Amazon MP3, download free tracks, etc., the files get stored on a NAS, where the collection is archived.

For a while, I've been rsynching the master collection on the NAS to a local folder on the living room PC, because iTunes has exhibited poor behavior with both remote libraries (supported by my NAS) and libraries on network shares -- particularly if said share is accessed from multiple computers. (I won't go into the details, but the past issues in both of these options made a local copy highly desirable... Maybe Apple fixed all the issues I ever encountered. Maybe not. I simply don't feel like finding out.)

The Hitch:
Unlike practically every other media player in the universe, iTunes isn't programmed to fulfill the simple task of identifying that files have been added to a given folder and then importing said files into its precious little library. This meant opening iTunes and running Add to Library from its menu. There were two options: remember what you just rsynched and pick the appropriate sub-folder(s) or re-add the whole top-level folder and trust that duplicates won't be added (which generally worked.) Either way, it was manual and therefore bogus...

The Fix (for this Son of a *itch):
Enter Automator. As you can see in the top part of the (rather wide) screen snippets below, it takes a massive two steps to A.) find brand-spanking new music files in a specified folder structure and then B.) add said files to the iTunes Library. Why this has to be done with an extravagant macro-type concoction is beyond me, but the fact that is literally this trivial to accomplish was refreshing, as I haven't really messed with Automator nearly enough...

Music being synchronized to a local folder, then being added to iTunes automagically. Dogs and cats, living together! The apocalypse is nigh!!! 
After adding those two tasks to a "Workflow" in Automator, I saved it as an Application so that I could just run the bugger without opening Automator every time. The other benefit of saving as an app is that I could just add another line at the end of my rsync script and make it run by itself. That's what that little open command at the end of the script snippet above does. Note that the rsync line excludes the meta-files that are created by various OSes when the master copy on the NAS is accessed directly, and that it doesn't perform any deletions.

_____________
*: This isn't hyperbole! I have over 10k files, and exactly one track in the archived collection was purchased from the iTunes store.