Hello,
I’m using MediaInfo CLI to generate an XML file of metadata that I want to then sort through and pick out specific pieces of metadata. I’m able to generate the XML file easily enough with a shell script:
set theFile to quoted form of POSIX path of (choose file)
set XMLtext to do shell script "usr/local/bin/mediainfo " & theFile & " --Output=XML"
I’ve been able to find lots of scripts that read information from XML files that exist as a stored file.
I found this one:
on run -- example
set theFile to quoted form of POSIX path of (choose file)
set XMLtext to do shell script "usr/local/bin/mediainfo " & theFile & " --Output=XML"
tell application "System Events" to set XMLdata to make new XML data with properties {text:XMLtext}
set codec to getXMLElement from {XMLdata, "File", "track type=\"Video\"", "Commercial_Name"}
codec
end run
to getXMLElement from XMLItems
(*
get the specified element from a simple XML structure by name or index
the number of items is not fixed, but must be at least 2 (the XML data and an XML element)
parameters: XMLItems [list] -
item 1 [record]: the XML data
item 2 [varies]: the XML element name or index (names are case sensitive)
item(s) 3+ [varies]: sub item(s)
returns [varies]: contents of the element
*)
try
if (count XMLItems) is less than 2 then error "getXMLElement handler: item list contains too few items"
tell application "System Events"
set myXMLdata to (the first item of XMLItems)
if class of myXMLdata is not XML data then error "getXMLElement handler: not XML data"
set myXMLelement to XML element 1 of myXMLdata -- start at the root element
--repeat with anItem in rest of XMLItems -- add on the sub items
-- set anItem to contents of anItem
-- try
-- set anItem to anItem as integer -- index number?
-- end try
-- set myXMLelement to (get XML element anItem of myXMLelement)
--end repeat
try -- return the element(s)
set theResult to value of myXMLelement
if theResult is missing value then error
return theResult
on error errorMessage number errorNumber -- the element is empty or a list of items
log errorMessage
return value of XML elements of myXMLelement
end try
end tell
on error errorMessage number errorNumber
log errorMessage
return missing value
-- error "getXMLElement handler: element not found (" & errorNumber & ")"
end try
end getXMLElement
But it just keeps returning the error message “missing value”.
For reference this is the XML that was generated from my test file via mediainfo:
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Mediainfo version="0.7.60">