Looking to use applescripts to restore Library information

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

schulermx

New member
Joined
Dec 15, 2005
Messages
4
Points
0
Age
34
Location
Boston
So I've taken the plunge and migrated my main PC to a mac instead of Windows. Unfortunately this means I can't seamlessly move over my iTunes library with some information that I wanted to keep.

With that said, once I get my head around Applescripting I think I can retain the majority of the information I'm interested in. What I'm trying to do is the following:

  1. Retain Playcount
  2. Retain if a song is "Disabled" or not [i.e. Checked or Unchecked box]
  3. Retain the Original "Date Added" field for sorting and history's sake
Now, I've managed to parse through my old iTunes.xml in order to come up with a file that has File_Name|Play_Count|Date_Added|Disabled? that I want to use up against the existing iTunes Library.

So that brings up a few questions I have about Applescript:
  1. Can I reference an outside file from Applescript (to pull in external data)
  2. Can I have an Applescript trigger everytime I add a file to iTunes (i.e. like a database trigger on INSERT)
I've seen scripts online that allow you to change the Play Count, but it's extremely cumbersome to perform that task manually, hence question 1.

I haven't poked around for altering the Disabled flag but I'd imagine that'd could be solved the same way as Play Count.

As for the date added, I've been doing a bit of research and I've determined that, at this time, one cannot alter this but there are some proposed work arounds. I've downloaded the Sundry's info applescript that can append File Creation Date to the Comment field. Unfortunately I've run into the problem where it has the format Day of Week, Month, Day, Time (e.g. Sunday, July 20 5:00PM). This doesn't sort well.

Since this is a text field, is there a way I can parse the creation date field to read YYYYMMDD HH:MM. I think that could preserve the date and be sortable. As I'd like to continue using this field going forward, I'd also like to be able have the comment field populated when I add a file to the library, hence question 2.

Thanks in advance
 

S2_Mac

New member
Joined
Oct 24, 2006
Messages
4,878
Points
0
Location
About 3 feet in front of the monitor
So I've taken the plunge and migrated my main PC to a mac instead of Windows. Unfortunately this means I can't seamlessly move over my iTunes library with some information that I wanted to keep.

You're making this way harder than it needs to be; it's easy to completely transfer from a PC to a Mac. You'll have every bit of metadata that's on your PC, from playlists to counts to ratings to volume adjustments to Date Added. (And, just so you know, there's no way to programatically change Date Added, no matter what tools you use; unless you transfer your iTunes install to the Mac, your original Date Added info will be lost.)

If you have enough room on your boot drive, simply consolidate your content files into the "iTunes Media" folder inside the "iTunes" folder in your PC user account's Music folder. Then it's just a matter of copying the "iTunes" folder onto the right spot on the Mac.

If the PC's boot drive doesn't have enough room to consolidate, it's a 2-step process to consolidate to an external hard drive: first, create an "iTunes" folder on the external, and copy your current "iTunes Library.itl" file into that folder; then Shift-launch iTunes into that library and consolidate content files into an iTunes Media folder inside the external's "iTunes" folder. Once that's done, it's just a matter of copying that folder onto the Mac.

(Well, small lie; there is one more step in PC-to-Mac transfers -- at some point you'll have to remove the file extension from the "iTunes Library.itl" file, but that's not much of a hardship ;-)

Just for the sake of completeness -- with the exception of Date Added, you can certainly use AppleScript to bring in metadata from the PC's iTunes library and apply it to the Mac's iTunes. But for a library of any good size, it will be a somewhat cumbersome project; you'll want to use a little Perl to make things go faster. (AppleScript isn't really intended for heavy lifting; it's really just a glue language for passing a few commands back and forth between applications.) Yes, Applescript can read a data file, but Perl would be (much) faster on all but the simplest of data structures. (Perl to parse the info you want from the PC's iTunes Library.xml file; then Applescript commands to update the data in the Mac's iTunes library.) The easiest, simplest, and least hair-pulling approach by far would be to simply do a proper PC-to-Mac transfer.

You can get a general idea of how to transfer by reading the iLounge tutorial on Transferring Your iTunes Library. Or, for speficic instructions, just post again here; include details on where your music files are currently stored on the PC -- drive and folder location(s).
 

schulermx

New member
Joined
Dec 15, 2005
Messages
4
Points
0
Age
34
Location
Boston
You're making this way harder than it needs to be; it's easy to completely transfer from a PC to a Mac. You'll have every bit of metadata that's on your PC, from playlists to counts to ratings to volume adjustments to Date Added. (And, just so you know, there's no way to programatically change Date Added, no matter what tools you use; unless you transfer your iTunes install to the Mac, your original Date Added info will be lost.)
Yup, looks like iTunes like to be annoying with that. That's why I was looking to execute the work-around.

If the PC's boot drive doesn't have enough room to consolidate, it's a 2-step process to consolidate to an external hard drive: first, create an "iTunes" folder on the external, and copy your current "iTunes Library.itl" file into that folder; then Shift-launch iTunes into that library and consolidate content files into an iTunes Media folder inside the external's "iTunes" folder. Once that's done, it's just a matter of copying that folder onto the Mac.
I'll have to do that option since my main PC is fried anyway (hence the new one). I have my work computer with Windows that I use to muck around with. I'm assuming I'd need to make sure the filepath on my external is exactly the same as it exists in the library which might require some drive remapping. My two music directories were:
D:\My Music\Albums
D:\My Music\Random Tracks

I never used the iTunes management but I guess I'll have to in order to transfer the items over properly.


Just for the sake of completeness -- with the exception of Date Added, you can certainly use AppleScript to bring in metadata from the PC's iTunes library and apply it to the Mac's iTunes. But for a library of any good size, it will be a somewhat cumbersome project; you'll want to use a little Perl to make things go faster. (AppleScript isn't really intended for heavy lifting; it's really just a glue language for passing a few commands back and forth between applications.) Yes, Applescript can read a data file, but Perl would be (much) faster on all but the simplest of data structures. (Perl to parse the info you want from the PC's iTunes Library.xml file; then Applescript commands to update the data in the Mac's iTunes library.)
That's good to know. Sometimes it's worth a bit of headache to learn something new anyway. I already put together a python script to give me a file with "File_Name|Play_Count|Date_Added|Disabled" which I guess, AppleScript would be able to use if needed. I understand that a proper port would alleviate dealing with these issues but I'd still like to explore more about this. I guess I'll have to go hunting around for some solid documentation around AppleScript.

I'm currently traveling for work but I'll start mucking around with this when I get back later this week.
 

S2_Mac

New member
Joined
Oct 24, 2006
Messages
4,878
Points
0
Location
About 3 feet in front of the monitor
::sigh:: Got it -- you had no backup of the PC that "fried". Maybe next time... ;-)

When you say,
Yup, looks like iTunes like to be annoying with that. That's why I was looking to execute the work-around,
I'm guessing the annoyance is iTunes refusing to allow Applescript to fudge the Date Added info. For me, that's a plus -- if you could modify that data, it wouldn't really be the date added (i.e. the field name might as well be Arbitrary Date You Can Change At Will ;-)

Here's another solution: if the old PC's hard drive is still usable, pop it into an external case and copy the "iTunes Library.itl" file to the root level of your music-containing drive. Due to some mojo with the iTunes Library file and "relative" paths, that library will now work just fine, regardless of the drive letter assigned to the music-containing external. On your new PC, quit iTunes and then connect the external; launch iTunes with the Shift key held down; in the dialog box that pops up, click the "Choose Library" button and navigate the File dialog to the "iTunes Library.itl" file at the external's root. iTunes will open to your old library, and paths will be valid. This is a solid basis for restoring the library on the root drive of the new PC while still maintaining your personalized folder structure on the external. HOWEVER, don't try this without posting again -- if prefs aren't set up correctly before you try this approach, your folder stucture will be irretrievably lost. (I'm kinda lazy; just don't want to type out every step for every option I float ;-)
 

schulermx

New member
Joined
Dec 15, 2005
Messages
4
Points
0
Age
34
Location
Boston
Oh good news actually, I did have the iTunes.itl file backed up. I have that sitting on an external (along with the xml file that I was so insistent on parsing on). I can mirror my normal file structure on multiple HDDs to ensure random backups all over the place.

But either way, I won't have physical access until Friday again, so I'll have to play the waiting game! I'll keep this post updated before I go ahead and try anything stupid.
 
Top