Thursday, September 20, 2018

#1 2010-07-25 04:59:58 pm

ygor
Member
Registered: 2008-09-09
Posts: 8

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.  sad

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

Offline

 

#2 2010-07-26 05:02:39 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11508
Website

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

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

Applescript:


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


regards

Stefan

Offline

 

#3 2010-07-26 06:15:17 am

ygor
Member
Registered: 2008-09-09
Posts: 8

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

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

Offline

 

#4 2010-07-26 07:30:39 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11508
Website

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

the core is

[code] // 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];[/code]
the rest is error handling and the print routine


regards

Stefan

Offline

 

#5 2010-07-26 07:34:37 am

ygor
Member
Registered: 2008-09-09
Posts: 8

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

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

Offline

 

#6 2018-07-08 07:28:44 am

technomorph
Member
Registered: 2017-12-14
Posts: 46

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

do you still have the file available?

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)