Cleaning iTunes
Pages: 1, 2
A Little AppleScript to the Rescue
I wrote a little AppleScript to grab the selected tracks in the playlist, grab the "name" of the first track in the selection, and use that for the name of the remaining tracks. I need to be careful here -- depending on which way I have the playlist ordered (ascending or descending in a certain column), the first track may be different than what I see as the first track in the window.
This is a quick script to prove to myself that this idea will work. I do not want to get too deep into a problem before I find out if it is not going to work.
tell application "iTunes"
set myWindow to browser window 1
set mySelection to selection of myWindow
set myNewName to name of first item in (get the selection of browser window 1)
repeat with myTrack in (get the selection of browser window 1)
set name of myTrack to myNewName
end repeat
end tell
I used this little script for a couple of CDs, and messed up a couple of times because the right name did not end up in myNewName. I added a dialog to allow me to choose the correct track name from all of the selected tracks, and another dialog to confirm the selection and give me a chance to edit it.
tell application "iTunes"
set myNames to name of selection of browser window 1
set myNewName to choose from list myNames with prompt "Which name?" multiple selections allowed 0
if myNewName is false then --nothing selected, just stop
return
end if
display dialog "Use this name?" default answer myNewName buttons {"Cancel", "Ok"} default button 1 with icon 1 giving up after 5
if the button returned of the result is "Cancel" then
return
end if
repeat with myTrack in (get the selection of browser window 1)
set name of myTrack to myNewName
end repeat
end tell
After I use this script, the track names should be half-right. I still need to combine them with the string in the artist portion. I do this a bit differently, so I do not need to select tracks, since I want to change all tracks in the playlist at the same time -- I easily create temporary playlists by dragging a group of selected tracks into the playlist window. Once I have those tracks isolated in their own playlist, I have an easier time working with them, even if I de-select them. I tell iTunes to cycle through all of the tracks, join the name and artist strings with a ", ", then set the name to the combined string. Once the string in the artist section is safely in the track name, I set the artist string to the real artist, which for me means the performer (iTunes has a separate column for Composer -- see the "Edit -> View Options..." menu item to see how you can change the columns in iTunes).
|
|
tell application "iTunes"
set myPlaylist to playlist "To Do"
repeat with i from 1 to count of tracks of myPlaylist
set myTrack to track i of myPlaylist
set myArtist to artist of myTrack
set myName to name of myTrack
set myNewName to myName & ", " & myArtist
set name of myTrack to myArtist
set artist of myTrack to "Glenn Gould"
end repeat
end tell
Once I have the basic idea of the script to combine the artist and track names, I fill out the script with dialogs to select the playlist and the artist name so I do not have to change the script for every group of changes that I want to make.
|
|
tell application "iTunes"
set allPlaylists to name of user playlists
set myPlaylist to choose from list allPlaylists with prompt
"Which playlist?" multiple selections allowed 0
if myPlaylist is false then --nothing selected, just stop
return
end if
display dialog "What is the new artist name?" default answer "Glenn Gould" buttons {"Cancel", "Ok"} default button 1 with icon 1 giving up after 5
if the button returned of the result is "Cancel" then
return
end if
repeat with i from 1 to count of tracks of myPlaylist
set myTrack to track i of myPlaylist
set myArtist to artist of myTrack
set myName to name of myTrack
set myNewName to myName & ", " & myArtist
set name of myTrack to myArtist
set artist of myTrack to "Glenn Gould"
end repeat
end tell
Once I get the scripts just how I like them, I add them to the iTunes Scripts directory (/Users/user-name/Library/iTunes/Scripts), which I had to create myself since it did not exist. When iTunes recognizes the directory, an AppleScript icon shows up to the left of the Help menu, and the names of the scripts in the directory show up in the Scripts menu, ready for use.
|
|
Wrapping Up
In a short time, I created two scripts that clean up quite a bit of classical music information in my iTunes Music Library. AppleScript gives me easy access to almost everything that iTunes knows, and lets me automate repetitive tasks. Other problems that I need to fix are special cases or different situations, so I create other scripts for them, first trying very small scripts to make sure the idea works, then adapting the small script for general use. Very quickly I have a powerful set of tools to fix most of the problems I find in my MP3 files without having to do a lot of typing. Now I can spend time listening to my music rather than categorizing it.
brian d foy is a Perl trainer for Stonehenge Consulting Services and is the publisher of The Perl Review.
Return to the Mac DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 14 of 14.
-
multiple artists or composers
2003-02-24 09:15:12 anonymous2 [Reply | View]
I noticed that iTunes seems to treat a track with multiple composers (say Lennon/McCartney) as a "unique name" no matter how I separate the names, comman, space, slash, etc. Is there a "correct" to enter multiple performers or composers into iTunes?
(In particular, I like letting iTunes complete the name, to ensure I always enter it the same way.)
Tom
mschaub728@earthlink.net
-
Filing under composer rather than artist
2003-01-23 06:23:20 anonymous2 [Reply | View]
I enjoyed the article, but following some of the suggestions has created a small problem. When you "correctly" use the "Artist" and "Composer" fields, iTunes creates a folder in the iTunes folder with the name of the Artist, not the Composer. However, in my CD collection (and I bet most peoples), I would file "Goldberg Variations" first under "Bach", and not under "Gould, Glenn". Is there a way to get iTunes to do this?
Thanks -
Filing under composer rather than artist
2003-01-23 09:16:38 brian d foy |
[Reply | View]
You do not have to keep your MP3 directories "organized"---see the "Advanced" tab under "iTunes>Preferences". iTunes should not move files around, and you can put things whereever you want them.
In the past, I have also created a bunch of alias. Since everything under "Glenn Gould" is still a bunch of directories representing albums, I make aliases of those directories and put them under "Johann Sebastian Bach" so I have it both ways.
-
No Dropshadows!
2003-01-22 11:56:17 anonymous2 [Reply | View]
Hmm.. I noticed you've killed your dropshadows, see above screenshots.
Is it really worth the kill? Do you notice that much speed-up / improvement? -
No Dropshadows!
2003-01-22 12:54:35 brian d foy |
[Reply | View]
Is it worth it to kill drop shadows? That's a subjective measure. For me it is---I do not like drop shadows.
I do not know about the performance---I would still kill them if my Mac would be a little bit shorter.
-
getting cd track names?
2003-01-20 14:50:55 anonymous2 [Reply | View]
thank you brian, and you also doug (mentioned in this article) for providing useful information and scripts to take advantage of all that itunes has to offer.
i was wondering if there's a way to insert a cd, have the cddb retrieve the cd info, and export the cd's info as text to an appleworks, filemaker pro, or mysql database? i would like to keep a database record of the cds i already have, but don't want to have to import all my cds to the itunes library just to export a song list. is there a solution that anyone can think of?
thanks,
pip -
getting cd track names?
2003-01-20 17:25:26 dougadams [Reply | View]
We have some AppleScripts that can export track data to AppleWorks and FMP. They are located on this page: <http://www.malcolmadams.com/itunes/scripts/scripts03.shtml> -
getting cd track names?
2003-01-20 15:01:01 brian d foy |
[Reply | View]
Inserting the CD and retrieving the track information is pretty easy already, although you can get hung up if the CDDB returns more than one match.
Once you see the CD in iTunes (not importing it, just playing), you should be able to go through the tracks and grab the information that you need. You could use AppleScript or Perl's Mac::iTunes.
Once you can access the playlist, just dump the information to a tab-delimited file (since most things can read tab delimited text easily).
Once you have that file, you can use Filemaker's "File>Import...", or mysqlimport. I am not sure about the database facilities in AppleSccript, but you could leave off the intermediate file with Perl and connect directly to mysql (or most other databases).
All you have to do is turn that description into a script of some sort. Good luck! -
getting cd track names?
2003-01-26 05:35:08 anonymous2 [Reply | View]
I'm sorry but I just can't figure out how to access and/or change the data for a CD that has not been imported into the library. The CD that is inserted does not show up in the Applescript's list of user playlists, and if I try to use audio CD playlist, it gives me a not very helpful error, like it can't get the name of the audio CD or it can't get the track of the audio CD.
I'd really appreciate it someone could post just a fragment of a script that shows how to grab and modify the CD track info.
-
ID3.org site has changed
2003-01-20 04:03:36 dougadams [Reply | View]
Great article. Thanks for mentioning my AppleScript site. And sorry for having this posted twice!
The new location for the ID3.org pages (such as they are) is:
http://id3lib.sourceforge.net/id3/
Cheers,
Doug
Doug's AppleScripts
malcolmadams.com/itunes/
-
ID3.org site
2003-01-20 04:00:46 anonymous2 [Reply | View]
Great article, thanks for mentioning my site.
The new location for ID3.org is actually here:
http://id3lib.sourceforge.net/id3/
Keep 'Em Flying!
Doug
Doug's AppleScripts for iTunes
malcolmadams.com/itunes/
-
Musical casts
2003-01-18 05:16:00 anonymous2 [Reply | View]
You bring up an interesting question in the first part of the article, one that I've been faced with. What is the best way to tag a musical soundtrack? Is "Cast of XXX" enough? How about "Cast of XXX: Performer"? -
Musical casts
2003-01-18 09:01:27 brian d foy |
[Reply | View]
Out of everyone I have talked too, including music theorists, performers, conductors, and so on, all of them say there is not a good way to classify all of music in one system (at least not yet).
Musicals, stage shows, operas, and even some popular music may have a lot of different people involved (performer, composer, librettist or lyricist, producer, etc.) and different people care about different things. One person may be interested in all Cole Porter songs, while another is interested in the same mp3 because Ella Fitzgerald performs them. Ricky Ian Gordon's Bright-Eyed Joy is a collection of poems from the likes of Dorothy Parker and Langston Hughes that he set to music, and the songs are performed by well-known concert singers like Audra McDonald, so who gets the place of honor in the mp3 tag?
For now, it is your personal preference.








Thank you very much for this article. I'm glad that other people want to use iTunes to listen to classical music and are also dissatisfied with the way the application classifies it.
I wonder though, if all this movement name for artist messiness is a problem with CDDB or iTunes. I ask because I only see the problem with iTunes, but the same CD imported into Windows Media Player 9 is classified fine. If that is the case, how can we get the apple developers to fix it?
Rafe