Donnerstag, 16. Oktober 2014

Moving iTunes media


Moving iTunes media


Moving your iTunes library is easy when iTunes manages it, but can be a tricky task if it doesn't.

An easy way obviously would be to just build a new iTunes library, or: remove everything, then again add everything. However, all playlists and ratings will then be lost. Since I put a lot of effort into my playlists (playlists and ratings both, actually), I needed to find another solution.

Footnote: Track rating is a meta datum that (sadly?) isn't written to the MP3 file. I wrote an AppleScript that puts the rating into a field that I never used: BPM, and another that restores the rating by reading that field. So if ratings are your only concern, you could use these scripts (copy them to /Users/yourusername/Library/iTunes/Scripts; in iTunes you can then find them under the black scroll of parchment):

[code]

tell application "iTunes"
if selection is not {} then
display dialog "This will copy the user ratings (0 to 100) of the selected tracks into their bpm fields."
set fi to fixed indexing
set fixed indexing to true
set sel to a reference to selection
repeat with theTrack in sel
set r_kind to rating kind of theTrack
set r_rating to (a reference to rating of theTrack) as integer
if r_kind is user then
set bpm of theTrack to r_rating
end if
end repeat
set fixed indexing to fi
end if
end tell

[code]

tell application "iTunes"
if selection is not {} then
display dialog "This will copy the values ≤ 100 of the bpm fields of the selected tracks into their rating fields."
set fi to fixed indexing
set fixed indexing to true
set sel to a reference to selection
repeat with theTrack in sel
set r_bpm to (a reference to bpm of theTrack) as integer
if (r_bpm > 0) and (r_bpm ≤ 100) then
set rating of theTrack to r_bpm
end if
end repeat
set fixed indexing to fi
end if
end tell


Part 1: Move a managed by iTunes library


This one is quick and easy. Close iTunes, move the folder that contains the library and media to wherever you want, then open iTunes holding the alt key, and select/open the library folder in the new location. That's it, you're good to go.

Part 2: How to move your media files if you manage your iTunes library manually


These instructions allow you to keep your playlists and ratings. They also keep your file dates intact, but not your added dates in iTunes and some other meta data. Following these steps, you can also change the location of your library, if you wanted too.

The only alternative I could think of at the time of writing would be to just move your media files, and whenever you want to play something iTunes can't find any more, search it manually. For me that approach wasn't practical.

Note that on my Mac, I was always able to move around my media anywhere within my drive when iTunes was running. It always found the media in its new location right out of the box. Then I needed space on my internal hard drive ...

For some time then I moved albums that weren't in any of my playlists manually by removing them from iTunes, relocating the files, then adding them to iTunes again, which was a pain in the ... In order to identify such albums, I wrote an AppleScript that moved all files that are not in any playlist to a new playlist. Then I manually looked for complete albums within that list, since I didn't proceed a step further and automated this, too. If you like this approach, feel free to adapt my script to your needs:

[code]

tell application "iTunes"
if selection is not {} then
set fi to fixed indexing
set fixed indexing to true
set sel to a reference to selection
-- Music in the classical folder
if not (user playlist "1. Local Music" exists) then
make new user playlist with properties {name:"1. Local Music"}
end if
-- Music in the classical folder that is not contained in any playlist except "1. Local Music"
if not (user playlist "2. Expendable Music" exists) then
make new user playlist with properties {name:"2. Expendable Music"}
else
delete tracks of playlist "2. Expendable Music"
end if
repeat with theTrack in sel
set loc to location of theTrack
if loc is not equal to missing value then
if ("" & loc) starts with "Macintosh HD:Users:cojabo:Desktop:Classical:" then
if {some playlist whose name is "1. Local Music"} is not in playlists of theTrack then duplicate theTrack to playlist "1. Local Music"
set theTracks_Playlists to (every user playlist of theTrack whose special kind is none)
if (length of theTracks_Playlists) is 1 then
duplicate theTrack to playlist "2. Expendable Music"
end if
end if
end if
end repeat
set fixed indexing to fi
display dialog "Done!" buttons "OK" default button "OK"
end if
end tell


Now here's your step by step instructions (these steps worked fine for me in iTunes 10.6.3 on Mac OS X 10.6.8):

1. Make sure your library is clean and doesn't contain dead links:

1.1. Drag all your files to a single new playlist. I had to do this in portions of about 300 albums at a time. (You could also write a small AppleScript that creates the playlist.)

1.2. Create a new intelligent playlist with the single rule: Playlist is not the one you just created. Background: iTunes doesn't add dead links to normal playlists. They do however show up in the intelligent playlist.

1.3. Perform your cleaning.

2. Make sure your iTunes Library.xml is up to date:

In my iTunes Library.xml I found some old path not existent any more. This is because I often move music around within my music folder, but haven't played some of it since then.

Background: If you just delete your XML, iTunes will create the same as was from its library. Paths won't be updated. Note that iTunes doesn't depend on the XML, but on its database file which is iTunes Library.itl or just iTunes Library.

2.1. If you skipped step 1, do now drag all your files to a single new playlist as described there.

2.2. Save that playlist somewhere (right-click/export). That file isn't needed afterwards, but your XML is up to date now.

3. Close iTunes and copy your music folder to the new location, e. g. to your new external drive. In Terminal, you could use rsync as in this example:

rsync -avhW --delete-before --exclude=".*" /Users/cojabo/Desktop/Music /Volumes/NewLocation

(This command includes some unnecessary options that allow you to use it as your backup command, by just adapting the two paths accordingly. To learn more about rsync, type man rsync in your Terminal window. You can scroll up and down with your arrow keys, and leave with 'q'.)

4. Copy the iTunes Library.xml file from your existing library somewhere, and edit the copy by replacing path information. Be sure you don't run into encoding issues. If your file is big, you want to use something like vi.

4.1. In Terminal, open the XML in vi (if you don't know what a cd command is, just type vi and drag the file into the Terminal window, then press enter):

vi iTunes\ Library.xml

4.2. In vi, update (search and replace) your path information. Example:

:%s/localhost\/Users\/cojabo\/Desktop\/Music\//localhost\/Volumes\/NewLocation\/Music\//g

4.3. Save and quit (:q).

5. Create a new library:

5.1. Start iTunes holding down the "alt" button, and create a new library.

I found it useful to still have my library locally available, even without the actual media. You may not. Think about it now. Some points you may want to consider include:

- Safety. I don't like the newer versions of iTunes, so I don't update it since version 10.6.3. Actually I did update to 11 and at the time it was some Google pain in the ... to go back to the old version. If you connect your external drive to another computer and open your library in a newer iTunes, it will be meddled with and you cannot open it in your old iTunes any more.

- Read access anywhere. I can open iTunes to browse though or search my library without the need to connect the external drive.

- All in one place. If you like me manage more than one iTunes Library, you'll have them all in one place.

5.2. Go to "Preferences/Advanced" ("Preferences/Erweitert") and remove all checks (just as you have done in your old library a long time ago). Uncheck "Keep iTunes media folder organized" ("iTunes-Medienordner automatisch verwalten") and "Copy files to iTunes media folder when adding to library" ("Beim Hinzufügen zur Mediathek Dateien in den iTunes-Medienordner kopieren").

6. Import your edited iTunes Library.xml: Navigate to "File/Library/Import Playlists" ("Ablage/Mediathek/Wiedergabeliste importieren") and select the XML file. Wait for a long time. 

That's all. If something went wrong you can always start over again, since your original library and media are still where they have been, entirely unchanged.


Part 3: Move your manually managed iTunes library's media folder - The easy way



(The following steps worked fine for me in iTunes 10.6.3 on Mac OS X 10.6.8.)

1. Make a copy of your library folder. (You don't need to do this, but I guess it's a good idea. In case something goes wrong, you'll be able to start over again).

2. Rsync your media folder to your external drive or wherever your new location may be. (Note that as mentioned above, you don't need to do anything, if you just want to move your media on the drive it already resides in.)

3. Open iTunes, and try to play the first missing track; iTunes will then ask you to provide its location manually. Provide it.

4. When playback starts, iTunes asks if you want it to search for more missing tracks in the selected destination. You want it to.

5. Now wait several hours during which progress won't be shown. In the end there will be a dialog that says something like this: "iTunes has found 157699 of 157699 missing tracks".

6. If everything went fine, delete the copy of your library that you've created in the first step, and your original media folder.

That's all. Never forget to backup your library, and media folder.

Keine Kommentare:

Kommentar veröffentlichen