Get iTunes Metadata AppleScript [v0.2]

Discuss Max, an open source CD audio extractor and audio converter.
Locked
User avatar
sbooth
Site Admin
Posts: 2445
Joined: Fri Dec 23, 2005 7:45 am
Location: USA
Contact:

Get iTunes Metadata AppleScript [v0.2]

Post by sbooth » Wed Jan 30, 2008 5:48 am

Here is version 0.2 of an AppleScript to pull a CD's metadata from iTunes and import it into Max.

To use it, first copy and paste the code below into Script Editor and save the file as a script of some sort. Next, launch Max and iTunes and insert the CD. Once iTunes has obtained the CD's information from GraceNote, run the script and the metadata will populate to Max.

Code: Select all

tell application "iTunes"
	set foundCD to true
	try
		set myCD to some source whose kind is audio CD
	on error errorMessage number errorNumber
		-- error 1728 means the AudioCD was not found, so wait a little 
		if errorNumber is -1728 then
			set foundCD to false
		else
			display dialog errorMessage
		end if
	end try
	if foundCD then
		set CDname to myCD's name
		set myPlaylist to playlist 1 of myCD
		set theTracks to tracks of myPlaylist
		tell application "Max"
			set mc to (count every track of document 1)
			set maxdisk to document 1
		end tell
		set ic to (count theTracks)
		if mc = ic then
			repeat with i from 1 to (count theTracks)
				set atrack to item i of theTracks
				set ar to artist of atrack
				set al to album of atrack
				set tn to track number of atrack
				set tc to track count of atrack
				set ge to genre of atrack
				set co to composer of atrack
				set ye to year of atrack
				set na to name of atrack
				set comp to compilation of atrack
				set com to comment of atrack
				set dn to disc number of atrack
				set dc to disc count of atrack
				tell application "Max"
					set maxtrack to track i of document 1
					if not (rip in progress of maxtrack) and not (encode in progress of maxtrack) then
						set title of maxtrack to na
						set artist of maxtrack to ar
						set date of maxtrack to ye as string
						set genre of maxtrack to ge
						set composer of maxtrack to co
						--set number of maxtrack to tn
					end if
				end tell
				if i = 1 then
					tell application "Max"
						set title of maxdisk to al
						set artist of maxdisk to ar
						set compilation of maxdisk to comp
						set genre of maxdisk to ge
						set date of maxdisk to ye as string
						set composer of maxdisk to com
						-- set track count of maxdisk to tc
						-- max doesn't allow setting total tracks
						set composer of maxdisk to co
						if dn > 1 then
							set disc number of maxdisk to dn
							set total discs of maxdisk to dc
						end if
					end tell
				end if
			end repeat
		else
			display dialog "The iTunes CD track count and the Max CD track count do not match."
		end if
	else
		display dialog "Couldn't get a CD from iTunes. Please retry."
		
	end if
end tell

User avatar
sbooth
Site Admin
Posts: 2445
Joined: Fri Dec 23, 2005 7:45 am
Location: USA
Contact:

Re: Get iTunes Metadata AppleScript [v0.2]

Post by sbooth » Sun Mar 16, 2008 3:18 pm

Version 0.2 fixes the problem setting total discs.

Locked

Who is online

Users browsing this forum: No registered users and 4 guests