I’ve started adding in my error messages, but I’ve run into a snag. MediaInfo sometimes uses different identifiers for Codec. If I use a .MXF wrapper with AVC codec, in the Video Track Type it calls it “Format_Info”. If I use a .MXF wrapper that has the XDCAM HD 422 codec that I want it calls the codec “Commercial_name”.
I’m trying to add an If statement to say that if the XML does not contain “Commercial_name” that it should return an error saying “Incorrect Codec” and stop the script. But I’m having trouble figuring out how to do that.
The error I keep getting is that “xmltext” is not defined. I thought that it was because maybe the If statement wasn’t in the right spot. But when I move it down into the “mediainfo()” step and the XML does not contain “Commercial_name” I’ll get an error saying it could not define the “Commercial_name” value.
Here is the script so far:
set theErrorCounter to 0
set CodecError to 0
set BitRateError to 0
set FrameRateError to 0
set tracks to the mediainfoFile()'s tracks
--Is this If statement not in the right spot?
if xmltext does not contain "Commercial_name" then
display dialog "INCORRECT CODEC!" buttons "Thanks!"
return
end if
--
set theRightFormats to {"XDCAM HD422", "50.0 Mbps", "29.970 fps"} as list
--THIS SECTION STORES THE XML DATA INTO VARIABLES
set PromoCodec to (trackinfo given type:"Video", key:"Commercial_name")
set PromoBitRate to (trackinfo given type:"Video", key:"Bit_rate")
set PromoDuration to (trackinfo given type:"Audio", id:2, key:"Duration")
set PromoWidth to (trackinfo given type:"Video", key:"Width")
set PromoHeight to (trackinfo given type:"Video", key:"Height")
set PromoFrameRate to (trackinfo given type:"Video", key:"Frame_rate")
--END
--THIS SECTION PULLS THE XML DATA:
on trackinfo given type:type as text, id:|id| as text : -1, key:key as text
local key, |id|, type
global tracks
tell application "System Events"
if |id| = -1 then
set {trackdata} to the |tracks| where ¬
value of the XML attribute "type" = |type|
else
set {trackdata} to the |tracks| where ¬
value of the XML attribute "type" = |type| and ¬
value of the XML attribute "streamid" = |id|
end if
return the value of the XML element named key in the trackdata
end tell
end trackinfo
-- THIS SECTION GENERATES THE XML INFO
on mediainfoFile() -- Only call this once per script run
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"
set xml to make new XML data with properties {text:xmltext}
set mediaInfo to XML element "Mediainfo" of xml
set |file| to XML element "File" of mediaInfo
return {|tracks|:a reference to XML elements of |file|}
end tell
end mediainfoFile
--END OF DATA
--ERROR MESSAGES START HERE
tell application "Finder"
if PromoCodec is not in theRightFormats then
set CodecError to 1
display dialog "INCORRECT CODEC! • codec is " & PromoCodec & " " buttons "Thanks"
end if
if PromoBitRate is not in theRightFormats then
set BitRateError to 1
display dialog "INCORRECT BIT RATE! • bit rate is " & PromoBitRate & " " buttons "Thanks"
end if
if PromoFrameRate is not in theRightFormats then
set FrameRateError to 1
display dialog "INCORRECT FRAME RATE! • frame rate is " & PromoFrameRate & " " buttons "Thanks"
end if
end tell
if CodecError is equal to 0 and BitRateError is equal to 0 and FrameRateError is equal to 0 then
display dialog "All OK!" & "(Label color: green)" buttons "Thanks"
end if