How can I AppleScript info out of iTunes Music Library.xml ?

The info in iTunes Music Library.xml is way more extensive than in the track attributes that are available in a Smart Playlist. As an example, for a video track, it has the pixel height and width of the video.

Anyone know how can I AppleScript the height and width of a video track out of iTunes Music Library.xml ?

I have already looked on Doug’s AppleScripts. I could not find the scripting info I want.

I looked around here and did not find an immediate answer neither. :frowning:

Model: Intel iMac
AppleScript: 2.0.1
Browser: Safari 531.22.7
Operating System: Mac OS X (10.5)

Hi,

parsing a hugh XML file with AppleScript can take a very long time
Here’s a small foundation CLI which prints track info for a track specified by its persistent ID
If no second parameter is passed, all information of the track will be displayed.
The output is one line per property, key and value is tab separated.

usage: iTunesTrackInfo persistentID
iTunesTrackInfo persistentID key1[,key2,.]

Save the file somewhere and call it from AppleScript, for example


tell application "iTunes"
	set sel to selection
	if sel is {} then return
	set persistentID to persistent ID of item 1 of sel
end tell
do shell script "'/path/to/iTunesTrackInfo' " & persistentID & " 'Video Width,Video Height'"

replace /path/to/iTunesTrackInfo with the real path

Download: iTunesTrackInfo

Thanks. I will try it when I get home from work.
Would you be willing to share the source ?

the core is

// iTunesXML contains the path to the XML file // persistentID contains the persistent ID of the track NSDictionary *root = [NSDictionary dictionaryWithContentsOfFile:iTunesXML]; NSDictionary *tracks = [root objectForKey:@"Tracks"]; NSPredicate *fDatabaseID = [NSPredicate predicateWithFormat:@"%K == %@", @"Persistent ID", persistentID]; NSArray *matchingTracks = [[tracks allValues] filteredArrayUsingPredicate:fDatabaseID]; NSDictionary *foundTrack = [matchingTracks objectAtIndex:0];
the rest is error handling and the print routine

:smiley:
Thanks again. I am still learning Objective C
This is a great snippet for learning.

do you still have the file available?