Sign in to follow this  
Followers 0
jercfd

help with _XMLDomWrapper.au3 and itunes xml

2 posts in this topic

How would I go use _XMLDomWrapper to get what is located in the string of both of these keys below.

I also want to create an array of all of the Persistent IDs. I currently do not have any starting code so I would appreciate any help I get.

<key>Library Persistent ID</key><string>57BD4AFD579DEB32</string>
<key>Persistent ID</key><string>CCB550C029637502</string>

Sample iTunes XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Major Version</key><integer>1</integer>
    <key>Minor Version</key><integer>1</integer>
    <key>Application Version</key><string>7.6.2</string>
    <key>Features</key><integer>5</integer>
    <key>Show Content Ratings</key><true/>
    <key>Music Folder</key><string>{PATH TO FOLDER}</string>
    <key>Library Persistent ID</key><string>57BD4AFD579DEB32</string>
    <key>Tracks</key>
    <dict>
        <key>80</key>
        <dict>
            <key>Track ID</key><integer>80</integer>
            <key>Name</key><string>In Our Talons</string>
            <key>Artist</key><string>Bowerbirds</string>
            <key>Album Artist</key><string>Bowerbirds</string>
            <key>Album</key><string>Hymns for a Dark Horse</string>
            <key>Genre</key><string>Alternative</string>
            <key>Kind</key><string>Protected AAC audio file</string>
            <key>Size</key><integer>3907119</integer>
            <key>Total Time</key><integer>233535</integer>
            <key>Disc Number</key><integer>1</integer>
            <key>Disc Count</key><integer>1</integer>
            <key>Track Number</key><integer>2</integer>
            <key>Track Count</key><integer>10</integer>
            <key>Year</key><integer>2007</integer>
            <key>Date Modified</key><date>2008-05-10T00:11:10Z</date>
            <key>Date Added</key><date>2008-05-10T00:10:56Z</date>
            <key>Bit Rate</key><integer>128</integer>
            <key>Sample Rate</key><integer>44100</integer>
            <key>Release Date</key><date>2007-07-10T07:00:00Z</date>
            <key>Artwork Count</key><integer>1</integer>
            <key>Persistent ID</key><string>CCB550C029637502</string>
            <key>Track Type</key><string>File</string>
            <key>Protected</key><true/>
            <key>Purchased</key><true/>
            <key>Location</key><string>{PATH TO SONG}</string>
            <key>File Folder Count</key><integer>4</integer>
            <key>Library Folder Count</key><integer>1</integer>
        </dict>
    </dict>
</dict>
</plist>

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This one is very tricky. Apple uses an awful format for this, it basically takes all of the usefulness out of xml.

#include "_XMLDomWrapper.au3"

$oXMLFile = _XMLFileOpen("itunes.xml")
Switch @error
    Case 0
        ConsoleWrite("No Error" & @CRLF)
    Case 1
        ConsoleWrite("Parse Error" & @CRLF)
    Case 2
        ConsoleWrite("No Object" & @CRLF)
EndSwitch

;Retrieve first 'Library Persistent ID' value
$result = _GetFirstValue("/plist/dict/key[.='Library Persistent ID']/following-sibling::*[1]")
ConsoleWrite("Library Persistent ID: " & $result & @CRLF)

;Retrieve array of all 'Persistent ID' values (count is in element zero)
$result = _XMLGetValue("/plist/dict/dict/dict/key[.='Persistent ID']/following-sibling::*[1]")
If IsArray($result) Then
    For $X = 0 to Ubound($result)-1
        ConsoleWrite("["&$X&"]: " & $result[$X] & @CRLF)
    Next
Else
    ConsoleWrite("NOT AN ARRAY" & @CRLF)
EndIf

;Get the first real value returned from the _XMLGetValue() return array. REQUIRED
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc
Edited by weaponx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0