Arthur - an iTunes Art script

Sometimes I have some songs in my library from a particular album, and these songs already have album art. Then, I later add another song from that same album, and I enter the same album name in iTunes. But iTunes makes no effort to detect that it is the same album and copy the artwork over. That’s where this script comes in.

Put this script in the ~/Library/iTunes/Scripts/ folder and will appear in the script menu in iTunes. Then, you can select a track or multiple tracks and run this script. The script searches for a “precedent” - a previous track in your library that is from the same album - and copies the album artwork from the precedent to the selection.

KNOWN ISSUES:

  1. <NEVER MIND, FIXED>
  2. If you have multiple albums that have the exact same name, use of this script is not recommended.

Let me know what you think, or if you have ideas to improve it. (Please be polite.) I know this isn’t a groundbreaking script, but it addresses an issue that I found annoying.

--Arthur 1.0.1 7/16/04 

tell application "iTunes"
	repeat with newTrack in the selection
		if album of newTrack is "" then
			display dialog "The selection must have album name specified." buttons {"Cancel"} default button "Cancel"
		else if kind of artwork 1 of newTrack >= 0 then
			display dialog "That track already has artwork." buttons {"Cancel"} default button "Cancel"
		else
			set newAlbum to album of newTrack as string
			try
				set oldTrack to null
				repeat with precedent in (tracks of first library playlist where album is newAlbum)
					if kind of artwork 1 of precedent >= 0 then
						set oldTrack to precedent
					end if
				end repeat
				if oldTrack is null then
					display dialog "No precedent found." buttons {"Cancel"} default button "Cancel"
				else
					set oldArt to artwork 1 of oldTrack
					set olddata to data of oldArt
					set data of artwork 1 of newTrack to olddata
				end if
			on error
				display dialog "Couldn't copy the artwork." buttons {"Cancel"} default button "Cancel"
			end try
		end if
	end repeat
end tell

It’s about time someone named a script after me, (it saves me the embarrassment of having to do it myself). :wink:

Hey Donkey Hoatie,

This is pretty nifty!

When you get things like ya want’em, please upload to ScriptBuilders? :idea:

[That way AdmiralNovia get’s his name in lights!]

Arthur + AdmiralNovia = gigglefactor ¡xª=2º :wink:

LOL

I assume you guys are kidding, but it was just a play on “art.” I don’t know the people around here that well. But if you want it to be named after you, I guess we could do that.

I’ll upload the script like you said if I get a chance.

EDIT: I have some code almost ready that fixes issue #1, but it is late here and I’ll have to pick it up tomorrow.
EDIT 2: I just discovered that some of the characters didn’t post to the Internet correctly. If you tried it before and it didn’t compile, try it again now.

Version 1.0.1 has now been posted above. If I don’t hear of any problems with this, I will try to upload it to ScriptBuilders.

Could you add a second precedent? That would (supposably) get around the same name album. Second Precedent would be Band name or Year…I don’t know, might be unecessary, but thought I’d interject…

I intentionally did not use the artist name, because some compilation CDs have multiple artists on the same album and thus multiple tracks should have the same album art even though the artist is different.

I suppose the script could be written to check for different artists with different artwork and then prompt which one to use, but determining if two images are the same can be very complicated, and there would still be a problem if you had two albums with the same name from the same artist that are supposed to have different artwork (e.g. American version and Japanese version, etc.).

I’m not planning on adding this because it would make the script very messy and complicated and there would still be some issues like the one described above, but you are welcome to modify the script and post your achievement here.

Also, the issue you are describing is not related to having a second precedent but rather how the first (and only) precedent should be chosen. Currently, the only criteria for choosing a precedent are that the album name is the same and it has artwork.