StainlessS
5th March 2016, 00:08
MediaInfo Client library MIFO_Lib v1.01
MIFO_Library.Avsi v1.01, MediaInfo library routines.
Req GScript, RT_Stats, CallCmd. Using MediaInfo Cli v0.7.83
Library of script functions to access MediaInfo Command Line version, to provide media information on named media file.
Can do Template String and Template file searches (best for Info Display), and extract individual parameter items
(for making decisions in real time, eg source filter selection based on whether AVI is lossless [AviSource] or Lossy [FFMPegSource or L-Smash to Index the file]).
Also can extract full/Raw information or only specific sections.
MIFO_Library.avsi Part 1 (too big)
######
# MIFO_Library.Avsi v1.01, Req GScript, RT_Stats, CallCmd. Using MediaInfo Cli v0.7.83
######
######
# If Below Global Variable Exists then will use it, Otherwise MediaInfo.Exe must live somewhere in Path of system Environment.
#Global Glb_MEDIAINFO_PATH = "C:\BIN\MediaInfo.Exe" # Modify for your system, Comment out if Command line MediaInfo.Exe already in system Path.
######
######
# If Below Global variable exists as FileName (ie String), then will Write latest MediaInfo commands to the named file (successful or
# otherwise).
# (Enable to track bugs, test used command in MediaInfo CLI).
# Comment out to Disable. Can Enable anywhere, ie does not have to be enabled in this file only.
#Global Glb_MEDIAINFO_LAST_COMMAND="MediaInfo_Latest_Command.txt"
######
######
# If Below Global variable exists as FileName (ie String), then will Write latest SUCCESSFUL MediaInfo results to the named file.
# Comment out to Disable. Can Enable anywhere, ie does not have to be enabled in this file only.
#Global Glb_MEDIAINFO_LAST_RESULT="MediaInfo_Latest_Result.txt"
######
/*
MediaInfo.Exe Command line, "MIFO_" Library. http://forum.doom9.org/showthread.php?t=173268
Some Notes, mainly for core MIFO_Get() function, but also apply to other functions:-
Parameter, TemplateString, and TemplateFile modes are mutually exclusive, when all three are "" then MIFO_Get is in section extract mode.
Parameter mode, does a MediaInfo search for a parameter returning result, where Parameter is used without enclosing Percent chars (%) eg
"DisplayAspectRatio" not "%DisplayAspectRatio%". Parameter mode requires a none "" Section name and Stream number.
TemplateString mode does MediaInfo search using a Template String.
TemplateFile mode does MediaInfo search using a Template File.
Template contents are not interfered with by MIFO_Lib, however supplied Section and Stream are handled as below.
Template modes seem to work better with the Section name supplied in the template rather than as Section and Stream number.
Section (string) can be can be empty string "" (ie ALL), "General", "Video", "Audio", "Text", "Image", "Menu". Case IS significant within
MediaInfo, but we will ensure that eg 'video' is converted to 'Video' for you.
Where Parameter and both Templates are "" and Section is a particular section type (ie NOT ""), then
MIFO_Get() will call MediaInfo with empty Section ("") and then will extract the requested
Section (including any appended stream number identifier) for you.
If you supply a Section of "", then we will return ALL results without attempting any extraction.
Stream, Int. Where Section = "" (ie ALL sections), then Stream number is ignored altogether.
When Stream Number is not ignored (Section != "") then Stream=0 OR Stream=1 denotes the first stream in Section no matter how many streams
there are (so long as there are some streams of course).
We differ from MediaInfo in that for MediaInfo stream 0 denotes first stream where there is only a single stream, and stream 1 is the
first stream when there is more than one stream (we dont like this and interpret both 0 and 1 to mean first stream irrespective of number
of streams). Media Info expects eg for the first stream of single stream audio "Audio" in call to get the section, and for 1st stream in
multistream audio expect "Audio #1", we hide this from you. We convert streams 0 or 1 to be "Audio" for single stream audio and
"Audio #1" for multi stream, you dont have to worry about any of this. Suggest that you use stream=1 to MIFO_StreamCount() result.
If you will be wanting to extract multiple sections, then might be best to request Section = ALL (""), and extract the multiple sections
yourself from the resultant multi-section text string result.
See MediaInfo supplied CLI_Help.Doc for further on MediaInfo use and templates.
*/
########
### Internal Functions::
########
GSCript("""
Function MIFO_Executable() { # If Glob Var exists use it else MediaInfo to be in a sys path.
Return (RT_VarExist("Glb_MEDIAINFO_PATH") && Glb_MEDIAINFO_PATH.IsString && Glb_MEDIAINFO_PATH!="")
\ ? RT_GetFullPathName(Glb_MEDIAINFO_PATH) : "MediaInfo.Exe"
}
Function MIFO_LastCommand() { # Return FullPathName set in Global Glb_MEDIAINFO_LAST_COMMAND, "" if Global var does not exist.
Return (RT_VarExist("Glb_MEDIAINFO_LAST_COMMAND") && Glb_MEDIAINFO_LAST_COMMAND.IsString && Glb_MEDIAINFO_LAST_COMMAND!="")
\ ?RT_GetFullPathName(Glb_MEDIAINFO_LAST_COMMAND):""
}
Function MIFO_LastResult() { # Return FullPathName set in Global Glb_MEDIAINFO_LAST_RESULT, "" if Global var does not exist.
Return (RT_VarExist("Glb_MEDIAINFO_LAST_RESULT") && Glb_MEDIAINFO_LAST_RESULT.IsString && Glb_MEDIAINFO_LAST_RESULT!="")
\ ?RT_GetFullPathName(Glb_MEDIAINFO_LAST_RESULT):""
}
Function MIFO_CheckSection(string Section) {
# Return int -1 if Invalid Name, string "" if null string ("") and ProperCase'd Section if valid name (ie swaps "video" to "Video").
Ret = -1 Sections=RT_String("\nGeneral\nVideo\nAudio\nText\nImage\nMenu\n")
For(n=0,6) {s=RT_TxtGetLine(Sections,n) if(s==Section) {Ret=s n=7}}
Return Ret
}
Function MIFO_EatWhite(string S) {Pos=1 While(RT_Ord(S,pos=Pos)==32 || RT_Ord(S,pos=Pos)==9){Pos=Pos+1}Return MidStr(S,Pos)}
Function MIFO_CallMediaInfo(String Cmd,String Outfn,Bool "Debug",String "myName") {
myName=Default(myName,"MIFO_CallMediaInfo: ") debug=Default(Debug,false)
outfn=(outfn!="")?RT_GetFullPathName(outfn):outfn RT_FileDelete(outfn)
LCommand=MIFO_LastCommand LResult=MIFO_LastResult
(Debug&&LCommand!="")?RT_DebugF("Glb_MEDIAINFO_LAST_COMMAND is set, Writing Current Cmd to '%s'",LCommand,name=myName):NOP
(LCommand!="")?RT_WriteFile(LCommand,"%s",Cmd):NOP
(Debug) ? RT_DebugF("Calling CallCmd",name=myName) : NOP
CallCmd(BlankClip(Length=1,Width=1,Height=1),Open=Cmd,Hide=True,debug=Debug,Synchronous=1) # Call the command, wait command terminated.
Assert(Exist(outfn),RT_String("%sCallCmd FAILED on \n'%s'",myName,Cmd))
Ret=RT_ReadTxtFromFile(outfn) RT_FileDelete(outfn)
Ret=(RT_TxtQueryLines(Ret)==1) ? RT_TxtGetLine(Ret,0) : Ret # Strip N/L for Single line result
(Debug&&LResult!=""&&Ret=="")?RT_DebugF("Result='' NOT Writing Result to '%s'",LResult,name=myName):NOP
(Debug&&LResult!=""&&Ret!="")?RT_DebugF("Glb_MEDIAINFO_LAST_RESULT is set, Writing Current Result to '%s'",LResult,name=myName):NOP
(LResult!=""&&Ret!="")?RT_WriteFile(LResult,"%s",Ret):NOP
Return Ret
}
""") # End Of GScript
########
### User Functions
########
GSCript("""
Function MIFO_Version(Bool "Debug",String "myName") { # Return MediaInfo Command line version number as a String eg "0.7.83".
myName=Default(myName,"MIFO_Version: ") debug=Default(Debug,false) MEDIAINFO=MIFO_Executable
outfn=RT_GetFullPathName("MediaInfo_"+RT_LocalTimeString(File=true)+".txt") # Unique Output text filename, full path
# Need to use system Command.com and redirect Stdout to file, LogFile dont work (also returns error code -1 if only --Version requested).
Cmd=RT_String("cmd /C %s --Version >%c%s%c" ,MEDIAINFO,34,outfn,34) # DONT use quotes around MediaInfo name, command.com will complain.
S=MIFO_CallMediaInfo(Cmd,outfn,Debug,myName)
Pos=1 While(RT_Ord(S,pos=Pos)<48||RT_Ord(S,pos=Pos)>57){Pos=Pos+1} # Hunt first Digit
S=MidStr(S,Pos)
Pos=1 While(RT_Ord(S,pos=Pos)==46||(RT_Ord(S,pos=Pos)>=48&&RT_Ord(S,pos=Pos)<=57)){Pos=Pos+1} # Hunt not (Digit||'.')
Ret=LeftStr(S,Pos-1)
(Debug) ? RT_DebugF("MediaInfo.Exe CLI Version = '%s'",Ret,name=myName) : NOP
return Ret
}
Function MIFO_StreamCount(String Fn,String Section,Bool "Debug",String "myName") {
# Get Int number of streams in Section, (Section can be:- "General", "Video", "Audio", "Text", "Image", "Menu"
myName=Default(myName,"MIFO_StreamCount: ") sn = MIFO_CheckSection(Section)
Fn = (Fn!="") ? RT_GetFullPathName(Fn) : Fn
Assert(Exist(Fn),RT_String("%sMediaFile Does NOT Exist '%s'",myName,Fn))
Assert(sn.IsString && sn!="",RT_String("%sBad Section('%s')",myName,Section))
if(sn=="General") {
Count = 1
} Else {
Fmt="%c%s%c --LogFile=%c%s%c --Inform=General;%%%sCount%% %c%s%c"
MEDIAINFO = MIFO_Executable
outfn=RT_GetFullPathName("MediaInfo_"+RT_LocalTimeString(File=true)+".txt") # Unique Output text filename, full path
Cmd=RT_String(Fmt,34,MEDIAINFO,34,34,outfn,34,sn,34,Fn,34)
Count = RT_NumberValue(MIFO_CallMediaInfo(Cmd,outfn,Debug,myName))
}
return Count
}
Function MIFO_FullSectionName(String Fn,String Section,Int Stream,Bool "Debug",String "myName") {
# Given Media file name Fn, Section, and Stream number, returns full Section Name including stream id eg "Audio" for single audio
# stream or "Audio #1" for first stream in multi-audio stream Fn media file. (ie a fully specified Section name as required by
# MediaInfo).
myName=Default(myName,"MIFO_FullSectionName: ") Debug=Default(Debug,False)
Assert(Stream>=0,RT_String("%sStream Must be >=0 (%d)",myName,Stream))
Result=""
if(Section!="") {
sn = MIFO_CheckSection(Section) Assert(sn.IsString,RT_String("%sBad Section('%s')",myName,Section))
(Debug) ? RT_DebugF("Calling MIFO_StreamCount",name=myName) : NOP
Count = MIFO_StreamCount(Fn,sn,Debug=Debug)
Stream = (Stream==0 || Stream==1) ? Min(Count-1,1) : (Stream<=Count) ? Stream : -1
Assert(Stream>=0,RT_String("%sInvalid Stream number(%d) Last Stream Number = %d",myName,Stream,Count))
Result=(Stream!=0)?RT_String("%s #%d",sn,Stream):sn
}
Return Result
}
Function MIFO_ExtractSectionItem(String SectionText,String Parameter,Bool "Pair",bool "Debug",String "myName") {
# Given Section text extracted via MIFO_ExtractSection (called indirectly via MIFO_Section or MIFO_Get [when Section!="" and
# Parameter and Templates all ""]), finds Parameter in the SectionText and returns the associated data (entire line including
# Parameter if Pair=True [Default False]).
myName=Default(myName,"MIFO_ExtractSectionItem: ") Pair=Default(Pair,False) Debug=Default(Debug,false) Ret = "" # Not Found
ParmLen=Strlen(Parameter) Lines=RT_TxtQueryLines(SectionText)
COLON = RT_Ord(":")
For(i=0,Lines-1) {
SSS=RT_TxtGetLine(SectionText,i).MIFO_EatWhite
if(RT_FindStr(SSS,Parameter,sig=False)==1) {
S=MidStr(SSS,ParmLen+1).MIFO_EatWhite # Strip Parameter from Start and EatWhite
if(RT_Ord(S)==COLON) {
if(Pair) {Ret = SSS} # Return Entire string, both Parameter and data Item
else {Ret = MidStr(S,2).MIFO_EatWhite} # Return just data Item
i = Lines # Break
}
}
}
(Debug) ? RT_DebugF("'%s' = '%s'",Parameter,Ret,name=myName) : NOP # Write Parameter = Extracted Text to DebugView
return Ret
}
Function MIFO_ExtractSection(String Txt,String Section,Int "Stream",Bool "Debug",String "myName") {
# Extract single section from complete MediaInfo result text (where MIFO_Get was called with Section="" ie full text)
# Section Name eg "General", "Video", "Audio", "Text", "Image", "Menu".
# Stream = 0 or 1, will extract first stream no matter if single or multi-stream section.
myName=Default(myName,"MIFO_ExtractSection: ") Stream=Default(Stream,0) Debug=Default(Debug,False)
Assert(Stream>=0,RT_String("%sBad Stream number(%d)",myName,Stream))
sn = MIFO_CheckSection(Section) Assert(sn.IsString && sn!="",RT_String("%sBad Section('%s')",myName,Section))
Lines=RT_TxtQueryLines(Txt) T="" InSect= False
sn=(Stream>1)?sn+" #"+String(Stream) : sn sn_Hash1=sn+" #1"
For(i=0,Lines-1){
S=RT_TxtGetLine(Txt,i)
if(S=="") { # "" is End Of Section
if(InSect) {i=Lines} # End of Extracted Section, All Done, Break
}else {
if(!InSect) {
if(S==sn) {
InSect=True
} else if(Stream<=1 && S==sn_Hash1) {
InSect=True
sn=sn_Hash1 # Is first stream in multi-channel section.
}
}
if(InSect) {T=RT_TxtAddStr(T,S)}
}
}
(Debug) ? RT_DebugF("'%s' Extracting\n%s",sn,T,name=myName) : NOP
Return T
}
""") # End Of GScript
See MediaFire in sig below (MIFO_Lib)
MIFO_Library.Avsi v1.01, MediaInfo library routines.
Req GScript, RT_Stats, CallCmd. Using MediaInfo Cli v0.7.83
Library of script functions to access MediaInfo Command Line version, to provide media information on named media file.
Can do Template String and Template file searches (best for Info Display), and extract individual parameter items
(for making decisions in real time, eg source filter selection based on whether AVI is lossless [AviSource] or Lossy [FFMPegSource or L-Smash to Index the file]).
Also can extract full/Raw information or only specific sections.
MIFO_Library.avsi Part 1 (too big)
######
# MIFO_Library.Avsi v1.01, Req GScript, RT_Stats, CallCmd. Using MediaInfo Cli v0.7.83
######
######
# If Below Global Variable Exists then will use it, Otherwise MediaInfo.Exe must live somewhere in Path of system Environment.
#Global Glb_MEDIAINFO_PATH = "C:\BIN\MediaInfo.Exe" # Modify for your system, Comment out if Command line MediaInfo.Exe already in system Path.
######
######
# If Below Global variable exists as FileName (ie String), then will Write latest MediaInfo commands to the named file (successful or
# otherwise).
# (Enable to track bugs, test used command in MediaInfo CLI).
# Comment out to Disable. Can Enable anywhere, ie does not have to be enabled in this file only.
#Global Glb_MEDIAINFO_LAST_COMMAND="MediaInfo_Latest_Command.txt"
######
######
# If Below Global variable exists as FileName (ie String), then will Write latest SUCCESSFUL MediaInfo results to the named file.
# Comment out to Disable. Can Enable anywhere, ie does not have to be enabled in this file only.
#Global Glb_MEDIAINFO_LAST_RESULT="MediaInfo_Latest_Result.txt"
######
/*
MediaInfo.Exe Command line, "MIFO_" Library. http://forum.doom9.org/showthread.php?t=173268
Some Notes, mainly for core MIFO_Get() function, but also apply to other functions:-
Parameter, TemplateString, and TemplateFile modes are mutually exclusive, when all three are "" then MIFO_Get is in section extract mode.
Parameter mode, does a MediaInfo search for a parameter returning result, where Parameter is used without enclosing Percent chars (%) eg
"DisplayAspectRatio" not "%DisplayAspectRatio%". Parameter mode requires a none "" Section name and Stream number.
TemplateString mode does MediaInfo search using a Template String.
TemplateFile mode does MediaInfo search using a Template File.
Template contents are not interfered with by MIFO_Lib, however supplied Section and Stream are handled as below.
Template modes seem to work better with the Section name supplied in the template rather than as Section and Stream number.
Section (string) can be can be empty string "" (ie ALL), "General", "Video", "Audio", "Text", "Image", "Menu". Case IS significant within
MediaInfo, but we will ensure that eg 'video' is converted to 'Video' for you.
Where Parameter and both Templates are "" and Section is a particular section type (ie NOT ""), then
MIFO_Get() will call MediaInfo with empty Section ("") and then will extract the requested
Section (including any appended stream number identifier) for you.
If you supply a Section of "", then we will return ALL results without attempting any extraction.
Stream, Int. Where Section = "" (ie ALL sections), then Stream number is ignored altogether.
When Stream Number is not ignored (Section != "") then Stream=0 OR Stream=1 denotes the first stream in Section no matter how many streams
there are (so long as there are some streams of course).
We differ from MediaInfo in that for MediaInfo stream 0 denotes first stream where there is only a single stream, and stream 1 is the
first stream when there is more than one stream (we dont like this and interpret both 0 and 1 to mean first stream irrespective of number
of streams). Media Info expects eg for the first stream of single stream audio "Audio" in call to get the section, and for 1st stream in
multistream audio expect "Audio #1", we hide this from you. We convert streams 0 or 1 to be "Audio" for single stream audio and
"Audio #1" for multi stream, you dont have to worry about any of this. Suggest that you use stream=1 to MIFO_StreamCount() result.
If you will be wanting to extract multiple sections, then might be best to request Section = ALL (""), and extract the multiple sections
yourself from the resultant multi-section text string result.
See MediaInfo supplied CLI_Help.Doc for further on MediaInfo use and templates.
*/
########
### Internal Functions::
########
GSCript("""
Function MIFO_Executable() { # If Glob Var exists use it else MediaInfo to be in a sys path.
Return (RT_VarExist("Glb_MEDIAINFO_PATH") && Glb_MEDIAINFO_PATH.IsString && Glb_MEDIAINFO_PATH!="")
\ ? RT_GetFullPathName(Glb_MEDIAINFO_PATH) : "MediaInfo.Exe"
}
Function MIFO_LastCommand() { # Return FullPathName set in Global Glb_MEDIAINFO_LAST_COMMAND, "" if Global var does not exist.
Return (RT_VarExist("Glb_MEDIAINFO_LAST_COMMAND") && Glb_MEDIAINFO_LAST_COMMAND.IsString && Glb_MEDIAINFO_LAST_COMMAND!="")
\ ?RT_GetFullPathName(Glb_MEDIAINFO_LAST_COMMAND):""
}
Function MIFO_LastResult() { # Return FullPathName set in Global Glb_MEDIAINFO_LAST_RESULT, "" if Global var does not exist.
Return (RT_VarExist("Glb_MEDIAINFO_LAST_RESULT") && Glb_MEDIAINFO_LAST_RESULT.IsString && Glb_MEDIAINFO_LAST_RESULT!="")
\ ?RT_GetFullPathName(Glb_MEDIAINFO_LAST_RESULT):""
}
Function MIFO_CheckSection(string Section) {
# Return int -1 if Invalid Name, string "" if null string ("") and ProperCase'd Section if valid name (ie swaps "video" to "Video").
Ret = -1 Sections=RT_String("\nGeneral\nVideo\nAudio\nText\nImage\nMenu\n")
For(n=0,6) {s=RT_TxtGetLine(Sections,n) if(s==Section) {Ret=s n=7}}
Return Ret
}
Function MIFO_EatWhite(string S) {Pos=1 While(RT_Ord(S,pos=Pos)==32 || RT_Ord(S,pos=Pos)==9){Pos=Pos+1}Return MidStr(S,Pos)}
Function MIFO_CallMediaInfo(String Cmd,String Outfn,Bool "Debug",String "myName") {
myName=Default(myName,"MIFO_CallMediaInfo: ") debug=Default(Debug,false)
outfn=(outfn!="")?RT_GetFullPathName(outfn):outfn RT_FileDelete(outfn)
LCommand=MIFO_LastCommand LResult=MIFO_LastResult
(Debug&&LCommand!="")?RT_DebugF("Glb_MEDIAINFO_LAST_COMMAND is set, Writing Current Cmd to '%s'",LCommand,name=myName):NOP
(LCommand!="")?RT_WriteFile(LCommand,"%s",Cmd):NOP
(Debug) ? RT_DebugF("Calling CallCmd",name=myName) : NOP
CallCmd(BlankClip(Length=1,Width=1,Height=1),Open=Cmd,Hide=True,debug=Debug,Synchronous=1) # Call the command, wait command terminated.
Assert(Exist(outfn),RT_String("%sCallCmd FAILED on \n'%s'",myName,Cmd))
Ret=RT_ReadTxtFromFile(outfn) RT_FileDelete(outfn)
Ret=(RT_TxtQueryLines(Ret)==1) ? RT_TxtGetLine(Ret,0) : Ret # Strip N/L for Single line result
(Debug&&LResult!=""&&Ret=="")?RT_DebugF("Result='' NOT Writing Result to '%s'",LResult,name=myName):NOP
(Debug&&LResult!=""&&Ret!="")?RT_DebugF("Glb_MEDIAINFO_LAST_RESULT is set, Writing Current Result to '%s'",LResult,name=myName):NOP
(LResult!=""&&Ret!="")?RT_WriteFile(LResult,"%s",Ret):NOP
Return Ret
}
""") # End Of GScript
########
### User Functions
########
GSCript("""
Function MIFO_Version(Bool "Debug",String "myName") { # Return MediaInfo Command line version number as a String eg "0.7.83".
myName=Default(myName,"MIFO_Version: ") debug=Default(Debug,false) MEDIAINFO=MIFO_Executable
outfn=RT_GetFullPathName("MediaInfo_"+RT_LocalTimeString(File=true)+".txt") # Unique Output text filename, full path
# Need to use system Command.com and redirect Stdout to file, LogFile dont work (also returns error code -1 if only --Version requested).
Cmd=RT_String("cmd /C %s --Version >%c%s%c" ,MEDIAINFO,34,outfn,34) # DONT use quotes around MediaInfo name, command.com will complain.
S=MIFO_CallMediaInfo(Cmd,outfn,Debug,myName)
Pos=1 While(RT_Ord(S,pos=Pos)<48||RT_Ord(S,pos=Pos)>57){Pos=Pos+1} # Hunt first Digit
S=MidStr(S,Pos)
Pos=1 While(RT_Ord(S,pos=Pos)==46||(RT_Ord(S,pos=Pos)>=48&&RT_Ord(S,pos=Pos)<=57)){Pos=Pos+1} # Hunt not (Digit||'.')
Ret=LeftStr(S,Pos-1)
(Debug) ? RT_DebugF("MediaInfo.Exe CLI Version = '%s'",Ret,name=myName) : NOP
return Ret
}
Function MIFO_StreamCount(String Fn,String Section,Bool "Debug",String "myName") {
# Get Int number of streams in Section, (Section can be:- "General", "Video", "Audio", "Text", "Image", "Menu"
myName=Default(myName,"MIFO_StreamCount: ") sn = MIFO_CheckSection(Section)
Fn = (Fn!="") ? RT_GetFullPathName(Fn) : Fn
Assert(Exist(Fn),RT_String("%sMediaFile Does NOT Exist '%s'",myName,Fn))
Assert(sn.IsString && sn!="",RT_String("%sBad Section('%s')",myName,Section))
if(sn=="General") {
Count = 1
} Else {
Fmt="%c%s%c --LogFile=%c%s%c --Inform=General;%%%sCount%% %c%s%c"
MEDIAINFO = MIFO_Executable
outfn=RT_GetFullPathName("MediaInfo_"+RT_LocalTimeString(File=true)+".txt") # Unique Output text filename, full path
Cmd=RT_String(Fmt,34,MEDIAINFO,34,34,outfn,34,sn,34,Fn,34)
Count = RT_NumberValue(MIFO_CallMediaInfo(Cmd,outfn,Debug,myName))
}
return Count
}
Function MIFO_FullSectionName(String Fn,String Section,Int Stream,Bool "Debug",String "myName") {
# Given Media file name Fn, Section, and Stream number, returns full Section Name including stream id eg "Audio" for single audio
# stream or "Audio #1" for first stream in multi-audio stream Fn media file. (ie a fully specified Section name as required by
# MediaInfo).
myName=Default(myName,"MIFO_FullSectionName: ") Debug=Default(Debug,False)
Assert(Stream>=0,RT_String("%sStream Must be >=0 (%d)",myName,Stream))
Result=""
if(Section!="") {
sn = MIFO_CheckSection(Section) Assert(sn.IsString,RT_String("%sBad Section('%s')",myName,Section))
(Debug) ? RT_DebugF("Calling MIFO_StreamCount",name=myName) : NOP
Count = MIFO_StreamCount(Fn,sn,Debug=Debug)
Stream = (Stream==0 || Stream==1) ? Min(Count-1,1) : (Stream<=Count) ? Stream : -1
Assert(Stream>=0,RT_String("%sInvalid Stream number(%d) Last Stream Number = %d",myName,Stream,Count))
Result=(Stream!=0)?RT_String("%s #%d",sn,Stream):sn
}
Return Result
}
Function MIFO_ExtractSectionItem(String SectionText,String Parameter,Bool "Pair",bool "Debug",String "myName") {
# Given Section text extracted via MIFO_ExtractSection (called indirectly via MIFO_Section or MIFO_Get [when Section!="" and
# Parameter and Templates all ""]), finds Parameter in the SectionText and returns the associated data (entire line including
# Parameter if Pair=True [Default False]).
myName=Default(myName,"MIFO_ExtractSectionItem: ") Pair=Default(Pair,False) Debug=Default(Debug,false) Ret = "" # Not Found
ParmLen=Strlen(Parameter) Lines=RT_TxtQueryLines(SectionText)
COLON = RT_Ord(":")
For(i=0,Lines-1) {
SSS=RT_TxtGetLine(SectionText,i).MIFO_EatWhite
if(RT_FindStr(SSS,Parameter,sig=False)==1) {
S=MidStr(SSS,ParmLen+1).MIFO_EatWhite # Strip Parameter from Start and EatWhite
if(RT_Ord(S)==COLON) {
if(Pair) {Ret = SSS} # Return Entire string, both Parameter and data Item
else {Ret = MidStr(S,2).MIFO_EatWhite} # Return just data Item
i = Lines # Break
}
}
}
(Debug) ? RT_DebugF("'%s' = '%s'",Parameter,Ret,name=myName) : NOP # Write Parameter = Extracted Text to DebugView
return Ret
}
Function MIFO_ExtractSection(String Txt,String Section,Int "Stream",Bool "Debug",String "myName") {
# Extract single section from complete MediaInfo result text (where MIFO_Get was called with Section="" ie full text)
# Section Name eg "General", "Video", "Audio", "Text", "Image", "Menu".
# Stream = 0 or 1, will extract first stream no matter if single or multi-stream section.
myName=Default(myName,"MIFO_ExtractSection: ") Stream=Default(Stream,0) Debug=Default(Debug,False)
Assert(Stream>=0,RT_String("%sBad Stream number(%d)",myName,Stream))
sn = MIFO_CheckSection(Section) Assert(sn.IsString && sn!="",RT_String("%sBad Section('%s')",myName,Section))
Lines=RT_TxtQueryLines(Txt) T="" InSect= False
sn=(Stream>1)?sn+" #"+String(Stream) : sn sn_Hash1=sn+" #1"
For(i=0,Lines-1){
S=RT_TxtGetLine(Txt,i)
if(S=="") { # "" is End Of Section
if(InSect) {i=Lines} # End of Extracted Section, All Done, Break
}else {
if(!InSect) {
if(S==sn) {
InSect=True
} else if(Stream<=1 && S==sn_Hash1) {
InSect=True
sn=sn_Hash1 # Is first stream in multi-channel section.
}
}
if(InSect) {T=RT_TxtAddStr(T,S)}
}
}
(Debug) ? RT_DebugF("'%s' Extracting\n%s",sn,T,name=myName) : NOP
Return T
}
""") # End Of GScript
See MediaFire in sig below (MIFO_Lib)