View Single Post
Old 26th May 2013, 18:13   #16  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Bernardd, would you like to give this a bit of a try out.

Code:
Function CondReader2FrameSelect(String Ifn,String "Ofn") {
# CondReader2FrameSelect.avs v0.02, By StainlessS
# Convert Conditional Reader command file to FrameSelect Command file.
# Type can ONLY be Bool
# DEFAULT MUST be specified
# Frames and Ranges MUST be Opposite of DEFAULT, ie if DEFAULT is False then all frames/ranges MUST be True
# Returns DEFAULT, If True, FrameSelect(Reject) should be set True, else False (Reject in FS selects All frames NOT selected in FS, sequentially)
# Interpolate NOT supported (Conditional Reader Specific)
    DEBUG=True
    myName="CondReader2FrameSelect: "
    Assert(Exist(Ifn),"Cannot Open File "+Ifn)
    Str=RT_ReadTxtFromFile(Ifn)
    NLines=RT_TxtQueryLines(Str)
    Offset=0
    Def=0
    GScript("""
        if(!Defined(Ofn)) {
            ext=RT_FilenameSplit(ifn,get=8)
            ofn=RT_FilenameSplit(ifn,get=15-8)+"_NEW"+ext
        }
        (Exist(ofn)) ? RT_FileDelete(ofn) : NOP
        GotT=False  GotD=False
        For(i=0,NLines-1) {
            S=RT_TxtGetLine(Str,i)
            ES=" $='"+S+"'"
            off=1
            WR_S="" CMT=""
            while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
            if(ch=="") {
                (DEBUG) ? RT_Debug(myName,String(i+1)+")","BLANK LINE",ES,false) : NOP
            } else if (ch=="#") {
                (DEBUG) ? RT_Debug(myName,String(i+1)+")","COMMENT ONLY",ES,false) : NOP # Dont think comment valid in file but we ignore anyway
                CMT=MidStr(S,off)
                while(RT_Ord(S,off)!=0) {off=off+1}                                     # Eat Till EOL
            } else if (ch=="O") {
                if(RT_FindStr(S,"OffSet ",Sig=False,pos=off)==off) {
                    off=off+6                                                           # Skip "Offset"
                    while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
                    Assert(ch>="0" && ch<="9",myName+"Offset # NOT Found @ Line "+String(i+1)+Chr(10)+ES)
                    Offset=RT_NumberValue(S,pos=off)
                    (DEBUG) ? RT_Debug(myName,String(i+1)+")","Offset =",String(Offset,"%.0f"),ES,false) : NOP
                    while(ch>="0" && ch<="9") {off=off+1 ch=Chr(RT_Ord(S,off))}         # Eat Digs
                }
            } else if(GotT==False) {
                Assert(RT_FindStr(S,"Type",Sig=False,pos=off)==off,myName+String(i+1)+") Type Must Be Specified first")
                off=off+4                                                               # Skip "Type"
                while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
                Assert(RT_FindStr(S,"Bool",Sig=False,pos=off)==off,myName+String(i+1)+") Type == Bool ONLY Supported")
                (DEBUG) ? RT_Debug(myName,String(i+1)+") Got TYPE Line "+ES,false) : NOP
                off=off+4                                                               # Skip "Bool"
                GotT=True
            } else if(GotD==False) {
                Assert(RT_FindStr(S,"Default",Sig=False,pos=off)==off,myName+String(i+1)+") Default MUST Be Specified")
                off=off+7                                                               # Skip "Default"
                while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
                Def=(ch == "T" || ch=="Y") ? True : (ch == "F" || ch=="N") ? False : 0
                Assert(IsBool(Def),myName+String(i+1)+") Default Type NOT specified")
                (DEBUG) ? RT_Debug(myName,String(i+1)+") Got DEFAULT Line "+ES,false) : NOP
                While(ch>="A"&&ch<="Z") {off=off+1 ch=UCase(Chr(RT_Ord(S,off)))}        # Eat Alpha
                DefS1=(Def==False)  ? "False"   : "True"
                DefS2=(Def==False)  ? "F"       : "T"
                DefS3=(Def==False)  ? "No"      : "Yes"
                NDefS1=(Def==False) ? "True"    : "False"
                NDefS2=(Def==False) ? "T"       : "F"
                NDefS3=(Def==False) ? "Yes"     : "No"
                (DEBUG && Def==True) ? RT_Debug(myName,"WARN Default=True, will Require FrameSelect(Reject=True)",false) : NOP
                GotD=True
            } else if (ch=="R") {
                off=off+1                                                               # skip "R"
                while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
                Assert(ch>="0" && ch<="9",myName+"Range Start NOT Found @ Line "+String(i+1)+Chr(10)+ES)
                R1=RT_NumberValue(S,pos=off) + Offset
                while(ch>="0" && ch<="9") {off=off+1 ch=Chr(RT_Ord(S,off))}             # Eat Digs
                while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
                Assert(ch>="0" && ch<="9",myName+"Range End NOT Found @ Line "+String(i+1)+Chr(10)+ES)
                R2=RT_NumberValue(S,pos=off) + Offset
                Assert(R2>=R1,myName+"Range End Before Range Start @ Line "+String(i+1)+Chr(10)+ES)
                if(R1==R2) {    # Single frame range, convert to single frame, avoid eg (0,0) meaning whole clip
                    WR_S=String(R1,"%.0f")
                } else {
                    WR_S=String(R1,"%.0f")+","+ String(R2,"%.0f")
                }
                while(ch>="0" && ch<="9") {off=off+1 ch=Chr(RT_Ord(S,off))}             # Eat Digs
                while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
                Assert((Def==False && (ch=="T"||ch=="Y")) || (Def==True && (ch=="F"||ch=="N")), \
                    myName+"Default value in file NOT supported @ Line "+String(i+1)+Chr(10)+ES)
                (DEBUG) ? RT_Debug(myname,String(i+1)+")",WR_S,ES,false) : NOP
                While(ch>="A"&&ch<="Z") {off=off+1 ch=UCase(Chr(RT_Ord(S,off)))}        # Eat Alpha
            } else if (ch>="0" && ch<="9") {
                R1=RT_NumberValue(S,pos=off) + Offset
                WR_S=String(R1,"%.0f")
                while(ch>="0" && ch<="9") {off=off+1 ch=Chr(RT_Ord(S,off))}             # Eat Digs
                while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
                Assert((Def==False && (ch=="T"||ch=="Y")) || (Def==True && (ch=="F"||ch=="N")), \
                   myName+"Default value in file NOT supported @ Line "+String(i+1)+Chr(10)+ES)
                (DEBUG) ? RT_Debug(myname,String(i+1)+")",WR_S,ES,false) : NOP
                While(ch>="A"&&ch<="Z") {off=off+1 ch=UCase(Chr(RT_Ord(S,off)))}        # Eat Alpha
            } else if(ch=="I") {
                Assert(False,myName+"Interpolate NOT Supported @ Line "+String(i+1)+Chr(10)+ES)
            }
            while(RT_Ord(S,off)==32 || RT_Ord(S,off)==9) {off=off+1} ch=UCase(Chr(RT_Ord(S,off)))   # Eat White
            if(ch=="#") {
               CMT=MidStr(S,off)
              (DEBUG) ? RT_Debug(myName,String(i+1)+")","Eating trailing COMMENT '"+MidStr(S,off)+"'",false) : NOP
              while(RT_Ord(S,off)!=0) {off=off+1}                                       # Eat Till EOL
              ch=""
            }
            # MUST have parsed to EOL else ERROR
            Assert(ch=="", \
                    myName+"Non Parse @ Line " + String(i+1)+ " Col "+String(off) + Chr(10) + \
                    "Ord="+String(RT_Ord(ch))+" Char='"+ch+"'"+ Chr(10) + \
                   +ES)
            if(WR_S!="" || CMT!="") {
                RT_TxtWriteFile(WR_S+((WR_S!="" && CMT!="")?Chr(9):"")+CMT,ofn,append=true)
            }
        }
    """)
    Assert(IsBool(Def),myName+"Bad Header")
    Return Def
}

Function CondReader2FrameSelectMsg(String Ifn,String "Ofn") {
    # Return message clip instead of Bool
    b=CondReader2FrameSelect(Ifn,Ofn)
    Return MessageClip("CondReader2FrameSelect: All Done"+((b)?Chr(10)+"Use Reject=True in FrameSelect":""))
}

IFN="CR.TXT"
OFN="FS.TXT"
return CondReader2FrameSelectMsg(IFN,OFN)     # Returns MessageClip

AVISource("D:\AVS\Test.avi")
REJECT=CondReader2FrameSelect(IFN,OFN)
FrameSelect(cmd=OFN,reject=REJECT,Show=True)
Test File: "CR.TXT"

Code:
Type Bool
Default False
# Dont know if Comments valid, this is a test
25 True
27 T

34 True
            # Another comment
40 True
49 True
Offset 100
57 True
58 t
59 True     # Additional Comment test
70 YES
Offset  0

80 yes
89 True
R 100 200 true
R 400 500 true     # Range Comment test
300 True
Ouput FS.TXT
Code:
# Dont know if Comments valid, this is a test
25
27
34
# Another comment
40
49
157
158
159	# Additional Comment test
170
80
89
100,200
400,500	# Range Comment test
300
Debugview log
Code:
00000005	1.29902506	[3608] CondReader2FrameSelect: 1) Got TYPE Line  $='Type Bool'
00000006	1.30856156	[3608] CondReader2FrameSelect: 2) Got DEFAULT Line  $='Default False'	
00000007	1.32179034	[3608] CondReader2FrameSelect: 3) COMMENT ONLY  $='# Dont know if Comments valid, this is a test'	
00000008	1.33403933	[3608] CondReader2FrameSelect: 4) 25  $='25 True'	
00000009	1.34664965	[3608] CondReader2FrameSelect: 5) 27  $='27 T'	
00000010	1.35276651	[3608] CondReader2FrameSelect: 6) BLANK LINE  $=''	
00000011	1.36185002	[3608] CondReader2FrameSelect: 7) 34  $='34 True'	
00000012	1.37056422	[3608] CondReader2FrameSelect: 8) COMMENT ONLY  $='            # Another comment'	
00000013	1.38138473	[3608] CondReader2FrameSelect: 9) 40  $='40 True'	
00000014	1.39403093	[3608] CondReader2FrameSelect: 10) 49  $='49 True'	
00000015	1.40505445	[3608] CondReader2FrameSelect: 11) Offset = 100  $='Offset 100'	
00000016	1.41523278	[3608] CondReader2FrameSelect: 12) 157  $='57 True'	
00000017	1.42785954	[3608] CondReader2FrameSelect: 13) 158  $='58 t'	
00000018	1.43853021	[3608] CondReader2FrameSelect: 14) 159  $='59 True     # Additional Comment test'	
00000019	1.44401228	[3608] CondReader2FrameSelect: 14) Eating trailing COMMENT '# Additional Comment test'	
00000020	1.45429206	[3608] CondReader2FrameSelect: 15) 170  $='70 YES'	
00000021	1.46463823	[3608] CondReader2FrameSelect: 16) Offset = 0  $='Offset  0'	
00000022	1.46965158	[3608] CondReader2FrameSelect: 17) BLANK LINE  $=''	
00000023	1.47869956	[3608] CondReader2FrameSelect: 18) 80  $='80 yes'	
00000024	1.49056959	[3608] CondReader2FrameSelect: 19) 89  $='89 True'	
00000025	1.50995982	[3608] CondReader2FrameSelect: 20) 100,200  $='R 100 200 true'	
00000026	1.52935898	[3608] CondReader2FrameSelect: 21) 400,500  $='R 400 500 true     # Range Comment test'	
00000027	1.53484905	[3608] CondReader2FrameSelect: 21) Eating trailing COMMENT '# Range Comment test'	
00000028	1.54537678	[3608] CondReader2FrameSelect: 22) 300  $='300 True'
Not had a lot of testing, I'll probably do a plug conversion.

EDITED:
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th May 2013 at 13:21.
StainlessS is offline   Reply With Quote