Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > (HD) DVD, Blu-ray & (S)VCD > (HD) DVD & Blu-ray authoring

Reply
 
Thread Tools Search this Thread Display Modes
Old 11th June 2022, 19:21   #21  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,259
Update for ConvTxtToOggChap.avsi, supports COMMA (,) fractional time separator as well as PERIOD (.) separator.

ConvTxtToOggChap.avsi
Code:
# ConvTxtToOggChap.avsi         # (c) StainlessS @ https://forum.doom9.org/showthread.php?p=1966757#post1966757
# Converts very loosely user specified times and chapter name in file, to Ogg/Ogm Chapter style in file.
# Requires AVS+, and RT_Stats v2.0 Beta13+

Function ChrIsNul(String S)      {return RT_Ord(S)== 0}                             # End of String
Function ChrIsHash(String S)     {return RT_Ord(S)==35}                             # #
Function ChrIsWhite(String S)    {C=RT_Ord(S) return C==32||C>=8&&C<=13}            # SPC, BackSPC, TAB, LF, VT, FF, CR
Function ChrIsDigit(String S)    {C=RT_Ord(S) return C>=48&&C<=57}
Function ChrEatWhite(String S)   {i=1 C=RT_Ord(S,i) While(C==32||C>=8&&C<=13)       {i=i+1 C=RT_Ord(S,i)} return i>1?MidStr(S,i):S}

# Return extent of string S [ie length from the beginning] that matches any character in Chars set of characters [Default case insignificant]. # StrMatchChrLen("1234.567abcd","0123456789.") = 8
Function StrMatchChrLen(String s,String Chars,Bool "Sig") {
    Function __StrMatchChrLen_LOW(String s,String Chars,int n) { c=s.MidStr(n+1,1) Return(c==""||Chars.FindStr(c)==0) ? n : s.__StrMatchChrLen_LOW(Chars,n+1) }
    Sig=Default(Sig,False)  # Default Case Insignificant
    s=(Sig)?s:s.UCASE   Chars=(Sig)?Chars:Chars.UCASE
    __StrMatchChrLen_LOW(s,Chars,0)
}

Function ConvTxtToOggChap(String txtfile,String "chapfile",Int "ChapIxLen",String "CommentChars") {
    myName    = "ConvTxtToOggChap: "
    Chap      = Default(chapfile,"")
    ChapIxLen = Default(ChapIxLen,3)                  # At Least ChapIxLen digits appended to CHAPTER Times and NAME. [NO CHECK if exceeded]
    CommentChars=Default(CommentChars,"#*")           # String of chars, any one of which will be interpreted as comment introducer.
    Assert(txtfile!="",RT_String("%stxtfile path required",myName))
    txtfile = txtfile.RT_GetFullPathName
    Assert(Txtfile.Exist,RT_String("%stxtfile Does not Exist",myName))
    Chapfile = ((chapfile=="") ? ".\OggChap.txt" : chapfile).RT_GetFullPathName  # Chapfile defaults "OggChap.txt" in current directory.
    Chapfile.RT_FileDelete
    SIN=RT_ReadTxtFromFile(txtfile)
    LINES = SIN.RT_TxtQueryLines
    DIGITS    = "0123456789"
    TIMEALP_A = DIGITS + ":"
    TIMEALP   = TIMEALP_A + ".,"
    ChapIX = 0
    for(i=0,LINES-1){
        S = SIN.RT_TxtGetLine(Line=i).ChrEatWhite.RevStr.ChrEatWhite.RevStr   # Get Line of text, remove EOL and Eat leading & trailing White Space.
        IsComment = CommentChars.RT_FindStr(S.LeftStr(1),sig=True)!=0
        if(!S.ChrIsNul && !IsComment) {   # Ignore blank lines and those beginning with Any character in CommentChars string.
            MilliSecs=0   Secs=0 Mins=0 Hrs=0
            Timelen=S.StrMatchChrLen(TIMEALP,sig=True)                                                  # Entire Time length
            Assert(TimeLen>0,RT_String("%sLine %d Time NOT FOUND @'%s'",myName,i+1,S))
            TITLE = S.MidStr(Timelen+1).ChrEatWhite                                                     # Chapter title
            ST = S.Leftstr(TimeLen)                                                                     # Time Only, no title
            Timelen_A=ST.StrMatchChrLen(TIMEALP_A,sig=True)                                             # Whole Part Only
            SA = ST.LeftStr(Timelen_A)                                                                  # Whole part string
            SB = ST.MidStr(TimeLen_A+1)                                                                 # Fraction Part String
            Chr = SB.MidStr(1,1)
            if(Chr=="." || Chr==",") { SB = SB.MidStr(2) }                                              # Strip leading '.' or ',' ::: Remaining SB MUST be digits only or "", else error
            Assert(SB.StrMatchChrLen(DIGITS,sig=True)==SB.StrLen,RT_String("%sLine %d Bad Fractional time @'%s'",myName,i+1,S))
            MilliSecs = LeftStr(SB+"000",3).Eval                                                        # Optional Millsecs, As integer, 0 -> 999 [Left Aligned, ie '.5' is 0.500 seconds]
            RTS = SA.RevStr
            ix = RTS.RT_FindStr(":")
            Secs = ((ix>0) ? RTS.LeftStr(ix-1) : RTS).RevStr.RT_NumberValue
            Assert(Secs < 60,RT_String("%sLine %d Invalid Seconds @'%s'",myName,i+1,S))
            RTS  = (ix>0) ? RTS.MidStr(ix+1) : ""
            ix   = RTS.RT_FindStr(":")
            Mins = ((ix>0) ? RTS.LeftStr(ix-1) : RTS).RevStr.RT_NumberValue
            Assert(Mins < 60,RT_String("%sLine %d Invalid Minutes @'%s'",myName,i+1,S))
            RTS  = (ix>0) ? RTS.MidStr(ix+1) : ""
            Hrs  = RTS.RevStr.RT_NumberValue
            Assert(Hrs < 24,RT_String("%sLine %d Invalid Hours @'%s'",myName,i+1,S))
            ChapIX = ChapIx + 1                                                                         # New Chapter
            TimeS            = RT_string("%02d:%02d:%02d.%03d",Hrs,Mins,Secs,MilliSecs)                 # Time as eg "23:59:59.987"
            CHAPTER_LINE     = RT_String("CHAPTER%0*d=%s",ChapIxLen,ChapIx,TimeS)
            TITLE = (TITLE=="") ? RT_String("Title %0*d",ChapIxLen,ChapIx) : TITLE                      # Improvise TITLE if is ""
            CHAPTERNAME_LINE = RT_String("CHAPTER%0*dNAME=%s",ChapIxLen,ChapIx,TITLE)
RT_DebugF("%d:%d] %s  : '%s' : '%s'",i+1,ChapIx,S.RT_StrPad(48),CHAPTER_LINE,CHAPTERNAME_LINE,name=myName)     # UnComment, output to DebugView
            RT_WriteFile(chapfile,"%s\n%s",CHAPTER_LINE,CHAPTERNAME_LINE,Append=True)
        }
    }
    return ChapIX # Number of Chapters written
}
Same Client,
ConvTxtToOggChap_Client.avs
Code:
# Import(".\ConvTxtToOggChap.avsi")

textFile  = ".\SimpleTimes.txt"     chapfile  = ".\chapfile.txt"
textFile2 = ".\SimpleTimes_2.txt"   chapfile2 = ".\chapfile_2.txt"
textFile3 = ".\SimpleTimes_3.txt"   chapfile3 = ".\chapfile_3.txt"
textFile4 = ".\SimpleTimes_4.txt"   chapfile4 = ".\chapfile_4.txt"

Nchaps = ConvTxtToOggChap(textfile,chapfile)
#Nchaps = ConvTxtToOggChap(textfile2,chapfile2)
#Nchaps = ConvTxtToOggChap(textfile3,chapfile3)
#Nchaps = ConvTxtToOggChap(textfile4,chapfile4)

MessageClip("DONE")

Return last
Mod to one of the test input files, SimpleTimes.txt [Added comma separator] {the other test files unchanged}
SimpleTimes.txt
Code:
00:00 Title 1
02:40 Title 2
09:27 Title 3
15:12 Title 4
#...
1:05:23 Title x
1:13:26 Title xx
#...
00:00. Title 7
02:40.12 Title 8
09:27.99 Title 9
15:12.71 Title 10
# Next line has fractional seconds period separator
23:59:59.987 Title 11
# Next line HAS NO TITLE TEXT - NOTE has fractional seconds comma separator
11:10:09,876
# Next line fractional seconds comma separator, and 500 millisecs time (.500)
11:10:09,5
# Next line No Hours, and no millisecs, NO TITLE TEXT
12:31
And result ChapFile.txt
Code:
CHAPTER001=00:00:00.000
CHAPTER001NAME=Title 1
CHAPTER002=00:02:40.000
CHAPTER002NAME=Title 2
CHAPTER003=00:09:27.000
CHAPTER003NAME=Title 3
CHAPTER004=00:15:12.000
CHAPTER004NAME=Title 4
CHAPTER005=01:05:23.000
CHAPTER005NAME=Title x
CHAPTER006=01:13:26.000
CHAPTER006NAME=Title xx
CHAPTER007=00:00:00.000
CHAPTER007NAME=Title 7
CHAPTER008=00:02:40.120
CHAPTER008NAME=Title 8
CHAPTER009=00:09:27.990
CHAPTER009NAME=Title 9
CHAPTER010=00:15:12.710
CHAPTER010NAME=Title 10
CHAPTER011=23:59:59.987
CHAPTER011NAME=Title 11
CHAPTER012=11:10:09.876
CHAPTER012NAME=Title 012
CHAPTER013=11:10:09.500
CHAPTER013NAME=Title 013
CHAPTER014=00:12:31.000
CHAPTER014NAME=Title 014
__________________
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 ???
StainlessS is offline   Reply With Quote
Reply

Tags
chapter, chapter entries, chaptereditor, converstion, converter

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:25.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.