This article originally appeared in TidBITS on 2010-10-14 at 8:23 a.m.
The permanent URL for this article is: http://tidbits.com/article/11627
Include images: Off

In Search of the iTunes Media Server

by Michael E. Cohen and Adam C. Engst

From the beginning, iTunes has been a personal music player and organizer. The "personal" is important here: iTunes seems tuned, as it were, for handling one person's media collection.

By default, iTunes puts your media in your account's Home directory at ~/Music/iTunes. Unlike the myriad Fonts folders in Mac OS X, there is no corresponding Music folder that's available to all users of a particular Mac. Although the iTunes application itself is shared among users on a Mac (or on Windows, for that matter), each user has his or her own iTunes folder in the Music folder of the user's home directory, and each running instance of iTunes looks at only one iTunes folder, and displays the contents of only one media collection, for each user.

For those of us who have spouses, companions, siblings, children, or parents with whom we share both musical tastes and living quarters, the "one person, one media collection" model doesn't work well. Nor does it work well even for one person, if that one person has, for example, a computer in a home office and another in the living room, and wants access to the same iTunes library in both places. What we want is a central iTunes library that everyone on a home network (or using separate user accounts on a single Mac) can share when each of us runs iTunes. But that's not quite what Apple has given us.

Apple's Sharing Solutions -- Over the years, in various versions of iTunes, Apple has attempted to ameliorate the media-sharing problem to some extent, although their attempts have been hobbled by, among other things, their contractual arrangements with, and the influence of, the music publishers who stock the iTunes Music Store (and who, truth be told, would be more than happy if you had to pay for music each and every time you listened to it).

However, if you step away from Apple's supplied solutions, and if your home network is up to the challenge, you may be able to build your own iTunes media server. Some small inconveniences will remain, and some protocols (the human kind, not the computer kind) will have to be observed, but you, and everyone on your local network, will all share a central iTunes media repository. (If it all works, of course: see the conclusion of this article, "What Could Possibly Go Wrong?" for some of the obstacles you can encounter.)

But first, a quick digression. Some non-Apple media syncing solutions do exist, although that's a topic complex enough to deserve its own article. Until we get around to it here at TidBITS, you can take a look at Macworld's "Sync your iTunes libraries [1]" by our own Joe Kissell.

And now, back to the show, which is already in progress...

The iTunes Folder and Its Contents -- iTunes "wants" to find its iTunes Library in ~/Music/iTunes. Note that we said Library not library. The iTunes Library is a file that lives at the top level of ~/Music/iTunes. It contains a database that includes information about all the songs and other media in your iTunes collection, along with playlist information and other bits of housekeeping information.

There are other database files in ~/Music/iTunes as well, such as iTunes Library Genius.itdb, which contains information related to the iTunes Genius feature. iTunes looks for all these database files in ~/Music/iTunes, and if it doesn't find them there, it creates them.

None of these files, though, contains your actual iTunes media collection (what we have been calling your "iTunes library" - small "l"). All of your music, videos, podcasts, books, iOS apps, and other media, at least starting with iTunes collections created by iTunes 9, is in your iTunes Media folder. This is the folder that you want to use as the basis of your homegrown iTunes media server.

Hold Yer Horses! What iTunes Media Folder? -- We're sure that some of you have opened your ~/Music/iTunes folder only to find no iTunes Media folder. Instead you probably saw several folders, including an "iTunes Music" folder. If that's the case, you have almost certainly been using iTunes for a number of years, and the contents of your iTunes folder are arranged in the way that versions of iTunes prior to iTunes 9 required. iTunes 9 and later can still use the older iTunes folder organization, which is why you don't see the iTunes Media folder.

Nonetheless, you'll need to reorganize the iTunes folder to consolidate and to organize properly all of your media in the iTunes Media folder, should you wish to use it for your iTunes media server. (This isn't entirely a required step; if all the copies of iTunes in your family are set up using this old version of the iTunes folder, they can all continue to use the old iTunes folder hierarchy rather than looking for everything inside a new iTunes Media folder. However, this article assumes you are using the new iTunes Media folder hierarchy.) The next section of this article discusses how to reorganize your iTunes folder properly, along with some of the possible consequences of this significant and irreversible act. Those of you who already have properly organized iTunes Media folders can skip the following section.

Organizing the iTunes Media Folder -- Although organizing your iTunes collection can be a massive undertaking as far as the amounts of material to be rearranged are concerned, there's not much work for you to do, since iTunes does all of the heavy lifting:

  1. Choose File > Library > Organize Library.

  2. In the Organize Library dialog, make sure that both Consolidate Files and Upgrade to iTunes Media Organization are checked, and then click OK.

  3. [image link] [2]

iTunes proceeds to move all of the media files in your ~/Music/iTunes folder into their proper places in the iTunes Media folder, and to copy any media files that you had stored elsewhere on your Mac but had included in your library (you did know you could do that, don't you?) into the iTunes Media folder. Even for a media collection of 100 GB, this process usually only takes a few minutes.

There are some consequences from running this command:

See the Apple support note, "iTunes 9: Understanding iTunes Media Organization [3]," for more information about what will be put where.

Set Up a Shared Media Folder -- Here's the key to making your own iTunes media server: iTunes doesn't care where the iTunes Media folder is stored or what its name is. As long as you set iTunes' preferences (stored in ~/Library/Preferences/com.apple.itunes.plist, if you care) so that iTunes looks for the media folder where you have placed it, iTunes will use that folder. The database files - which, as we've said, contain things like your playlists - still remain in ~/Music/iTunes no matter where your music and other media resides. Thus, if you put the iTunes Media folder on a shared volume or on a file server on your network, several people can use it and still have their own personal playlists and all the other information that is unique to their view of the iTunes library. (Although you can merely move or copy the iTunes Media folder manually in the Finder, Apple describes a more-involved way to move an iTunes Media folder in the support note, "iTunes for Mac: Moving your iTunes Media folder [4].")

In the following scenario, we assume you have copied your iTunes Media folder to a file server on your home network and have set the folder's permissions so that other users on the network can read from and write to that folder. One user (probably you) will be the main person who should add media to the iTunes Media folder. Think of this user as the designated Media Librarian. It's not a major problem if other users have read and write privileges and add media, but using and maintaining the media server will be less confusing if one person does most of the work.

You may have noticed that we've been rather vague about the "file server on your home network" and how to set permissions on it. That is, unfortunately, intentional: we don't know the equipment that you own and so we can't say exactly what this device might be, nor how you should set it up. It could be an older Mac that you have sitting around that you've pressed into service as a file server. It could be an external USB drive attached to an AirPort Extreme base station. It could be a NAS (network-attached storage) device of some sort. All of these could work (though nothing is guaranteed: see below, "What Could Possibly Go Wrong?"), but the details of installing the server and setting the appropriate permissions on it vary.

If, instead, you share the iTunes Media folder from your Mac, you need to make it a Shared Folder using the Info window for that folder:

  1. Move the iTunes Media folder to your account's Public folder. (This isn't absolutely necessary, but putting it there both makes it accessible to other accounts on your Mac and serves as a reminder to you that the iTunes Media folder is publicly available.)

  2. Select the folder, and then choose File > Get Info.

  3. Click Shared Folder in the General section of the Info window.

  4. At the bottom of the Get Info window, click the lock icon to authenticate, and then give everyone Read & Write permissions. That's necessary so users can subscribe to podcasts and other subscriptions (but this sort of data opens another can of wriggly annelids, as described below in "Podcasts and other subscriptions").

  5. From the action menu (the gear icon) at the bottom of the Info window, choose Apply To Enclosed Items, and then, in the confirmation dialog, click OK. Other users can now connect to your Public folder as Guest to see the folder and its contents.

If you're sharing the iTunes Media folder from your Mac, there are two things to keep in mind. First, your Mac must remain on and awake, so that other users on the network can access the folder. Your Mac is a file server now. Second, you, of course, are the Media Librarian we mentioned above. Feel free to don a mask and cape.

There's one more step before others can connect to the shared iTunes Media folder: "stamping" the media with the names of the users who will share it. Why? Because this will help identify new media later on. To "stamp" all of the types of media you want to share (that is, the music, movies, TV shows, and EPUB-based books - this step doesn't work for PDFs or apps), select all the items with Command-A, press Command-I to display a Multiple Item Information dialog, and, in the Comments field, put the name of each person who will share the folder, separated by spaces (as in "Adam Tonya Tristan").

Now, to use the shared folder, each user on each Mac should perform the following steps:

  1. In the Finder, under Shared in any Finder window sidebar, select the server that contains the iTunes Media folder. If you can't see the server in the sidebar, use Go > Connect to Server. (If you have shared the folder from your Public folder, you can skip this step for yourself.)

  2. Connect to the server, using an appropriate account. (If you have shared the folder from your Public folder, other users can connect as Guest; you won't need to connect at all.)

  3. In iTunes, choose iTunes > Preferences and click Advanced.

  4. [image link] [5]

  5. To the right of the iTunes Media Folder Location panel, click the Change button, and then navigate to and choose the shared iTunes Media folder within the volume from the server you just mounted. (If you are sharing your own folder, just navigate to it on your own Mac.)

  6. Select both Keep iTunes Media Folder Organized and Copy Files To iTunes Media Folder When Adding To The Library. This ensures that everything gets added to the shared iTunes Media folder.

  7. In the Finder, open the shared iTunes Media folder, select all the media folders inside it that don't contain subscription-based content (most notably, podcasts, although possibly TV shows as well), and drag them into the iTunes window to import them. This won't import PDFs in the Books folder for some reason; they must be selected as files and dragged in separately. (If you are sharing your own iTunes Media folder, skip this step, because iTunes already knows the files are part of your iTunes [big "L"] Library.)

Note that the above steps assume each user other than the Media Librarian has an empty iTunes library. If that's not true, and it likely won't be, the Media Librarian will have to work with each user to gather and add the media from each user's personal media collection for storage in the shared iTunes Media folder. Home Sharing would likely be the most effective way to see and merge multiple libraries.

(By the way: With recent versions of iTunes, if you launch iTunes while pressing the Option key, a dialog appears that you can use either to create a new, empty iTunes Library or to switch to an existing one. This is how you'd switch back and forth between two different iTunes libraries if necessary.)

[image link] [6]

At this point each person has the shared media in his or her iTunes library. Yay! There's one major downside to sharing an iTunes Media folder this way: every time someone adds new media - by, for instance, ripping a new CD, or purchasing something from the iTunes Store - each other user must import the files manually by dragging them into iTunes. However, that's not true of things that you subscribe to, such as podcasts; see below, "What Could Possibly Go Wrong?" for tips.

It's up to the Media Librarian to let everyone know when new media has been added to the shared iTunes Media folder so that other users can import it by dragging it to iTunes on their computers. This is, unfortunately, easier said than done, especially if quite a few pieces of media have been imported by the Media Librarian since the last addition.

How do you identify newly added media? You could try to match dates, but that doesn't work well, since Date Modified can change and Date Created isn't always representative, depending on the source of the file. There are two ways, an easy one suggested by a commenter that seems to work well, but which we haven't had a chance to test thoroughly, and a harder one that requires some manual effort.

For the easy approach, download the Music Folder Files Not Added [7] AppleScript application from Doug's AppleScripts for iTunes. Launch it and click the Find button to look for files that exist in the iTunes Media folder that aren't in the current iTunes Library. The first time you run it, you may discover some oddities caused by tracks that have lost their links to the associated file (just delete them from iTunes and let the utility add them back) and by duplicates (you'll have to reconcile these manually). If this works for you, you don't have to worry about the "stamping" step above or the alternative approach below.

[image link] [8]

If you don't wish to use the Music Folder Files Not Added utility, or it doesn't work for you for some reason, here's another, harder approach (it's why you went through the media "stamping" exercise above). Whenever anyone adds media (songs, movies, TV shows, or EPUB books; it won't work with apps) to the shared iTunes Media folder, that person should follow these steps:

  1. Select all newly added items, and type Command-I to open a Multiple Item Information dialog.

  2. In the Comments field, type the name of the person who has added the media. For example, typing Adam indicates that Adam's iTunes Library file (note the large "L") "knows" about the added media.

  3. For each other Mac, open the shared iTunes Media folder in the Finder and in the Finder window's Search field, type "comment:" followed by the name of the person who added the media, followed by a hyphen and the name of the person whose Mac it is, as in "comment:Adam -Tonya" (also, make sure to select the iTunes Media button in the Search toolbar; searching This Mac will skew the results). This search finds all items in the shared iTunes Media folder that were imported by one person, but which haven't been added to other libraries. In this example, it would find items imported by Adam, but not yet imported by Tonya.

  4. Drag any or all of the found items to the iTunes window to add them to the iTunes Library for that Mac.

  5. Sort the iTunes window by either the Comments column or the Date Added column, select the newly added items, and then press Command-I to open the Multiple Item Information dialog.

  6. Change the Comments field to include (don't replace) the name of the person who has added the media; for example, changing the comments field to "Adam Tonya" indicates that these files have been added to Tonya's iTunes Library.

Unfortunately, although the Comments metadata for each file will now contain "Adam Tonya" in this scenario, the iTunes Library of the Adam user (who imported the music to start with) won't display that change until Adam plays a song or changes other metadata. There seems to be no way to force iTunes to refresh the metadata contained within media files.

It's worth noting that each user of the media server can choose which of the shared media files to import, so if you don't want your daughter's Justin Bieber songs appearing in your iTunes Library, you can ignore them. Also, consider what this distinction between the iTunes media and the iTunes Library means for user-specific metadata like playlists, ratings, and play counts. Since iTunes tracks that information within each user's iTunes Library file, every user will have their own metadata even though they share the media. Generally speaking, that's good, since you probably don't want your daughter's playlists, nor do you want her play counts to migrate to your iTunes Library, because your smart playlists that relied on play count might have unintended contents.

However, if you're sharing your content among your own machines - you have a Mac in your basement office and a Mac mini that plays music through your stereo system upstairs - not having the same playlists might be annoying. In this situation, you might be better off moving your entire iTunes folder to the server and selecting it with an Option-launch of iTunes. You must also make sure that each copy of iTunes looks for the iTunes Media folder itself in the proper location. The downsides there include contention for the iTunes Library file - only one copy of iTunes could be running at any given time - and performance problems if the iTunes Library file is large.

What Could Possibly Go Wrong? -- The answer to that question is "lots of stuff." Keep in mind that over the past decade Apple has had to tap-dance faster than a caffeinated hummingbird just to make sure that iTunes and its complicated ecosystem remain compatible with all the devices and the user scenarios that Apple supports. A roll-your-own iTunes media server is not something that Apple prohibits, but neither is it something that they support.

Here are a few of the pain points that might keep you from implementing an iTunes media server and instead could send you back to the supported solutions we described in "Apple's Sharing Solutions," above:

But, if none of the issues mentioned above are too troublesome, you can enjoy a shared iTunes media server right now, and not have to wait until that glorious day in the far future when Apple, and all the media companies with whom it partners, finally allow the development of a true Apple-supported iTunes Media Server. For more on what that would require, see Kirk McElhearn's thoughts at Macworld in "Opinion: Apple needs an iTunes Server version [9]."

[1]: http://www.macworld.com/article/133881/2008/07/syncitunes.html
[2]: http://db.tidbits.com/resources/2010-10/organize-library-dialog.png
[3]: http://support.apple.com/kb/HT3847
[4]: https://support.apple.com/kb/HT1449
[5]: http://db.tidbits.com/resources/2010-10/iTunes-Advanced-preferences.png
[6]: http://db.tidbits.com/resources/2010-10/Choose-iTunes-Library-dialog.png
[7]: http://dougscripts.com/466
[8]: http://db.tidbits.com/resources/2010-10/MFFNA-window.png
[9]: http://www.macworld.com/article/154570/2010/10/itunes_server.html