ITunes

From HerzbubeWiki
Jump to: navigation, search

This page contains various information related to iTunes and how it works on my Mac.

iTunes Music Library

See this knowledge-base article on support.apple.com for official details about the organization of media in different versions of iTunes. The most recent folder layout is the one for iTunes 9, and because it also makes the most sense I have now switched to this layout by running the upgrade function File > Library > Organize Library > Upgrade to iTunes Media organization.


The iTunes Music Library consists of two parts:

  • A number of files in ~/Music/iTunes
  • The actual media files. By default these files are stored in the above folder as well, in a sub-folder named iTunes Media (iTunes Music in older versions of iTunes). In older versions of iTunes, the media folder's location could be changed by creating a symlink that pointed to the real location. In more recent versions of iTunes, though, the user can change this location in the iTunes GUI, by setting a different folder in the iTunes Preferences. In my case, I prefer to store my music files on a file sharing server for convenient backup and access from other machines.


The content of ~/Music/iTunes changes every other version of iTunes. This knowledge base article by Apple has some official information. At the time of writing (with iTunes 11) the relevant files on my computer are these:

caradhras:~/Music/iTunes --> ls -la
total 24216
drwxr-xr-x  9 patrick  staff      306 31 Jan 11:59 .
drwx------+ 4 patrick  staff      136 16 Nov 16:33 ..
drwxr-xr-x  5 patrick  staff      170 14 Dez 13:57 Album Artwork
drwxr-xr-x  4 patrick  staff      136 26 Sep 21:07 Previous iTunes Libraries
-rw-r--r--  1 patrick  staff    16384 31 Jan 11:55 iTunes Library Extras.itdb
-rw-r--r--  1 patrick  staff    32768  5 Jan  2013 iTunes Library Genius.itdb
-rw-r--r--@ 1 patrick  staff  2446425 31 Jan 11:57 iTunes Library.itl
-rw-r--r--@ 1 patrick  staff  9895089 31 Jan 11:57 iTunes Music Library.xml
-rw-r--r--@ 1 patrick  staff        8 31 Jan 11:57 sentinel

A short discussion of the files and folders

  • Album Artwork: Stores album covers downloaded from the iTunes Store.
  • Previous iTunes Libraries: Sometimes when a new version of iTunes is installed, the new version needs to update the data structure of its library file to the new version. A backup copy of the library file is stored in this folder before the update is performed. It is safe to delete this folder.
  • iTunes Library.itl: A binary file that stores all the information about the music files you have in your iTunes Library (including ratings, albums, playlists, etc.).
  • iTunes Music Library.xml: Some (but not all!) of the same information as in the binary library file, but in XML format. This file can be used to import the library into a different instance of iTunes on a different computer (or a different account on the same computer). It is also used by iTunes to recreate the iTunes Library.itl file if that file becomes corrupt for some reason. Information that is known to be missing from iTunes Music Library.xml: Playlists, ratings, comments.
  • iTunes Library Extras.itdb: The purpose of this file is unknown.
  • iTunes Library Genius.itdb: The purpose of this file is unknown.
  • sentinel: The purpose of this file is unknown.

Note the absence of the iTunes Media folder - I manually deleted this folder after changing its location in the iTunes Preferences. iTunes might recreate the folder if, for some reason, it cannot find the folder set in the preferences. If this happens, simply reset the location in the iTunes Preferences, then delete the local folder.


iTunes and iPhone/iPad

Applications

When iTunes synchronizes with an iPhone or iPad, it also retrieves any apps that have been installed via the App Store on the device since the last sync. The apps are stored in

~/Music/iTunes/iTunes Media/Mobile Applications

If the media folder is stored on a file sharing server, apps are therefore automatically also stored on the same server. In older versions of iTunes (versions prior to 9) this was not the case because the "Mobile Applications" folder was stored outside the media folder, directly below the local

~/Music/iTunes

To get the apps to be stored on a file sharing server as well, a symlink had to be created (it was impossible to change the location in the iTunes Preferences):

cd "/Users/patrick/Music/iTunes"
# Copy local files to file sharing server
ditto "Mobile Applications" "/Volumes/media/Mobile Applications"
# !!! STOP iTunes NOW !!!
# Move local files out of the way, not yet deleting them
mv "Mobile Applications" "Mobile Applications.backup"
# Create the symbolic link
ln -s "/Volumes/media/Mobile Applications" "Mobile Applications"
# !!! NOW TEST IF THIS WORKS !!! Install a free app on one of your devices, then launch iTunes and perform a sync
# If everything works fine, delete the local backups
rm -r "Mobile Applications.backup"


Backups

The official references for the stuff in this section are articles in Apple's knowledge base for the iPhone and the iPad.

Existing backups of the content of your iPhone and iPad are visible in iTunes under Preferences->Devices. It is possible to delete backups in this dialog.

Those backups are stored, by default, inside the folder ~/Library/Application Support/MobileSync/Backup. For instance:

tharbad:~/Library/Application Support/MobileSync/Backup --> ls -la
total 0
drwxr-xr-x     5 patrick  staff    170  6 Nov 18:16 .
drwxr-xr-x     3 patrick  staff    102 17 Aug  2009 ..
drwxr-xr-x  2741 patrick  staff  93194  6 Nov 10:13 927e15d622daae24ec6833c4cbb5899178cd85b8
drwxr-xr-x  2741 patrick  staff  93194  6 Nov 18:17 927e15d622daae24ec6833c4cbb5899178cd85b8-20101106-181617
drwxr-xr-x  1589 patrick  staff  54026 18 Okt 00:34 e96c1c4453f72e73715c221ee1ab9026e027b64b

In the example above, the folder with the suffix 20101106-181617 marks a backup that was used to restore my iPhone. Every time the user tells iTunes to perform such a restore, iTunes creates a copy of the backup used for the restore and appends date/time information to the backup copy so that afterwards one can tell when the restore was made. Subsequent backups will then be made again to the backup folder without the suffix.


As in the previous chapter with the app sync folder, I prefer to store backups on my file sharing server, for the same reasons. Again, I use a symbolic link to solve this:

cd "/Users/patrick/Library/Application Support"
# Copy local backups to file sharing server
ditto MobileSync /Volumes/media/MobileSync
# !!! STOP iTunes NOW !!!
# Move local backups out of the way, not yet deleting them
mv MobileSync MobileSync.backup
# Create the symbolic link
ln -s /Volumes/media/MobileSync MobileSync
# !!! NOW TEST IF THIS WORKS !!! Launch iTunes, check if backups are recognized in the Preferences dialog, then make a backup (and, if you can, a restore).
# If everything works fine, delete the local backups
rm -r MobileSync.backup


Mirroring the iTunes library on a laptop

Pre-conditions:

  • the iTunes library is maintained on my PowerMac (= the master)
  • the laptop is the slave that receives all updates made on the master
  • any changes made on the slave are lost when the libraries are sync'ed
  • the master keeps its audio files on a file server
  • the slave has a copy of all audio files
  • iTunes on the slave is configured like this:
    • Keep iTunes Music folder organized = false
    • Copy files to iTunes Music folder when adding to library = false

The following instructions have been verified to work for iTunes 8. With older versions of iTunes you export and import "the iTunes Library", whereas nowadays on my machines it is called "Mediathek" (I don't know the English term for that). The basic procedure is the same, though.

Things that will be synchronized:

  • music files, including at least the following attributes: date last played, ratings, genre, mp3 tags
  • podcasts
  • possibly other media types (movies, tv shows, radios, ring tones) work too, but I have not tested this
  • folder structures
  • smart and regular playlists

Things that will not be synchronized

  • the following music file attributes: date added (this is of course set to now)
  • the shopping cart
  • list with items that have been bought in the iTunes Store (although the actual items appear in the Mediathek and in playlists)


Step 1: Synchronize audio files

The slave needs to get new audio files, update changed files and delete old files no longer present on the master. This task is done by rsync.

For every directory that needs to be synchronized, the following cmdline can be issued:

rsync -azvE --exclude '.DS_Store' --delete-after "/Volumes/DATEN/mp3/" "/Users/Shared/osgiliath-mp3/"

Discussion:

  • -a = archive mode, i.e. keep as many file properties as possible
  • -z = compress files
  • -v = verbose, i.e. display the files being copied and deleted; in a cron environment, this option should be replaced by -q
  • -E = copy extended attributes and resource forks; this option is an extension of rsync by Apple and is only available if the system version of rsync is used (/usr/bin/rsync)
    • if -E is used, it is not possible to synchronize by contacting an rsync daemon, the synchronization must be done on the file system level
    • reason: the rsync daemon does not understand -E
  • --delete-after = delete files that don't exist on the sender; delete them after everything else has been done
  • source and target paths possibly need to be quoted if there are spaces in the path
  • the source directory needs a trailing slash, otherwise a sub-directory is created within the target directory


Step 2: Clean iTunes library on slave

Open iTunes on the slave and remove all audio files and play lists from the library.


Step 3: Export iTunes library on master

Open iTunes on the master and choose "Ablage->Mediathek->Mediathek exportieren..." (names given in German because I have a German installation). The export is made into a file nam

Mediathek.xml

Copy the XML file to the slave.


Step 4: Modify paths inside XML file

On the slave, open the XML file in an editor and change all audio file paths so that they match the path structure on the slave. As an alternative, the following example awk script can be used to automate this task. Again, for every directory that contains audio files, the script needs an additional line.

nargothrond:~/Desktop --> cat itunes.awk
{
  gsub(/\/Volumes\/DATEN\/mp3\//, "/Users/Shared/osgiliath-mp3/", $0)
  print $0
}

Execute the script like this:

nargothrond:~/Desktop --> awk -f itunes.awk Mediathek.xml >Mediathek-changed.xml


Step 5: Import modified XML file

Open iTunes on the slave and choose "Ablage->Mediathek->Wiedergabeliste importieren..." (names given in German because I have a German installation), then select the modified XML file from step 4 and import it.

All you need to do now is wait until everything has been imported.