@@ -115,14 +115,15 @@ public Form1()
115115 //}
116116
117117 private void button_processVTT_Click ( object sender , EventArgs e )
118- {
118+ {
119119 button_loadToSeperate . Enabled = true ;
120120 textBox_vttResult . Clear ( ) ;
121121 mySubtitle . Clear ( ) ;
122122 if ( radioButton_VTT . Checked == true )
123123 processVTT ( ) ;
124124 else
125125 processXML ( ) ;
126+ button_processVTT . Text = "OK!" ;
126127 }
127128
128129 private string msToTime ( string ms )
@@ -141,7 +142,6 @@ private void processXML()
141142 if ( filesPath [ 0 ] != "" )
142143 {
143144 string strXML = "" ;
144- int Position = 0 ;
145145 for ( int i = 0 ; i < textBox_vtt . Lines . Count ( ) ; i ++ )
146146 {
147147 strXML += textBox_vtt . Lines [ i ] + "\r \n " ;
@@ -159,12 +159,12 @@ private void processXML()
159159 //p with content could be the last line.
160160 //p without content could not be the last line. 2018-05-02
161161 int psFlag = 0 ;
162+ int sPosition = 0 ;
163+ string sContent ;
164+ string sWordStart ;
165+ string sWordEnd ;
162166 foreach ( XmlNode p in ps )
163- {
164- string Content ;
165- string WordStart ;
166- string WordEnd ;
167-
167+ {
168168 if ( p . ChildNodes . Count != 0 )
169169 {
170170 //Debug.WriteLine(p.InnerXml);
@@ -180,63 +180,64 @@ private void processXML()
180180 int ssFlag = 0 ;
181181 foreach ( XmlNode s in ss )
182182 {
183- Content = s . InnerText . Trim ( ) ;
183+ sContent = s . InnerText . Trim ( ) ;
184184 if ( s . Attributes [ "t" ] == null )
185185 {
186186 //s is the first word, WordStart should be LineStart.
187187 //s maybe the only word.
188188 //s maybe the final word.
189- WordStart = p . Attributes [ "t" ] . Value ;
189+ sWordStart = p . Attributes [ "t" ] . Value ;
190190 if ( s . NextSibling == null )
191191 {
192- if ( ssFlag == ss . Count - 1 )
192+ if ( psFlag == ps . Count - 1 )
193193 {
194194 //s is the final word, which means there is no more lines, WordEnd should be LineStart + Duration, which is a bit longer than normal ones.
195- WordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( p . Attributes [ "d" ] . Value ) ) . ToString ( ) ;
195+ sWordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( p . Attributes [ "d" ] . Value ) ) . ToString ( ) ;
196196 }
197197 else
198198 {
199199 //s is the only word, but not the final word, WordEnd should be next LineStart.
200- WordEnd = ps [ psFlag + 1 ] . Attributes [ "t" ] . Value ;
200+ sWordEnd = ps [ psFlag + 1 ] . Attributes [ "t" ] . Value ;
201201 }
202202 }
203203 else
204204 {
205205 //s is not the only word, WordEnd should be LineStart + next WordStart.
206- WordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( ss [ ssFlag + 1 ] . Attributes [ "t" ] . Value ) ) . ToString ( ) ;
206+ sWordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( ss [ ssFlag + 1 ] . Attributes [ "t" ] . Value ) ) . ToString ( ) ;
207207 }
208208 }
209209 else
210210 {
211211 //s is not the first word, WordStart should be LineStart + TimeShift.
212212 //s cannot be the only word.
213213 //s maybe the final word.
214- WordStart = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( s . Attributes [ "t" ] . Value ) ) . ToString ( ) ;
214+ sWordStart = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( s . Attributes [ "t" ] . Value ) ) . ToString ( ) ;
215215 if ( s . NextSibling == null )
216216 {
217217 //s is the last word.
218218 //s maybe the final word.
219- if ( ssFlag == ss . Count - 1 )
219+ if ( psFlag == ps . Count - 1 )
220220 {
221221 //s is the final word, which means there is no more lines, WordEnd should be LineStart + Duration, which is a bit longer than normal ones.
222- WordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( p . Attributes [ "d" ] . Value ) ) . ToString ( ) ;
222+ sWordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( p . Attributes [ "d" ] . Value ) ) . ToString ( ) ;
223223 }
224224 else
225225 {
226226 //s is the last word, but not the final word, WordEnd should be next LineStart.
227- WordEnd = ps [ psFlag + 1 ] . Attributes [ "t" ] . Value ;
227+ sWordEnd = ps [ psFlag + 1 ] . Attributes [ "t" ] . Value ;
228228 }
229229 }
230230 else
231231 {
232232 //s is not the last word, WordEnd should be LineStart + next WordStart.
233- WordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( ss [ ssFlag + 1 ] . Attributes [ "t" ] . Value ) ) . ToString ( ) ;
233+ sWordEnd = ( Convert . ToInt32 ( p . Attributes [ "t" ] . Value ) + Convert . ToInt32 ( ss [ ssFlag + 1 ] . Attributes [ "t" ] . Value ) ) . ToString ( ) ;
234234 }
235235 }
236236 ssFlag ++ ;
237- Debug . WriteLine ( Content + "\t " + WordStart + "\t " + WordEnd ) ;
238- mySubtitle . Add ( new subtitle { Content = Content , WordStart = msToTime ( WordStart ) , WordEnd = msToTime ( WordEnd ) , Position = Position , Selected = false } ) ;
239- Position += Content . Length + 1 ;
237+ //Debug.WriteLine(Content + "\t" + WordStart + "\t" + WordEnd);
238+ Debug . WriteLine ( sContent + "\t " + msToTime ( sWordStart ) + "\t " + msToTime ( sWordEnd ) + "\t " + sPosition ) ;
239+ mySubtitle . Add ( new subtitle { Content = sContent , WordStart = msToTime ( sWordStart ) , WordEnd = msToTime ( sWordEnd ) , Position = sPosition , Selected = false } ) ;
240+ sPosition = sPosition + sContent . Length + 1 ;
240241 }
241242 Debug . WriteLine ( "" ) ;
242243 }
@@ -275,25 +276,25 @@ private void processVTT()
275276
276277 string LineStart = "" ;
277278 string LineEnd = "" ;
278- string Content = "" ;
279- string WordStart = "" ;
280- string WordEnd = "" ;
281- int Position = 0 ;
279+ string sContent = "" ;
280+ string sWordStart = "" ;
281+ string sWordEnd = "" ;
282+ int sPosition = 0 ;
282283
283284 for ( int i = 10 ; i < textBox_vtt . Lines . Count ( ) ; i = i + 8 )
284285 {
285- Content += textBox_vtt . Lines [ i ] + "\r \n " + textBox_vtt . Lines [ i + 2 ] + "\r \n " ;
286+ sContent += textBox_vtt . Lines [ i ] + "\r \n " + textBox_vtt . Lines [ i + 2 ] + "\r \n " ;
286287 }
287288
288- textBox_vttResult . Text = Content ;
289+ textBox_vttResult . Text = sContent ;
289290 foreach ( var text in textBox_vttResult . Lines )
290291 {
291292 //match TimeLine
292293 if ( Regex . IsMatch ( text , patternTime ) )
293294 {
294295 LineStart = Regex . Match ( text , patternTime ) . Groups [ "TimeStart" ] . Value ;
295296 LineEnd = Regex . Match ( text , patternTime ) . Groups [ "TimeEnd" ] . Value ;
296- WordStart = LineStart ;
297+ sWordStart = LineStart ;
297298 }
298299 else
299300 {
@@ -303,15 +304,15 @@ private void processVTT()
303304 {
304305 if ( m . Groups [ "WordEnd" ] . Value == "" )
305306 {
306- WordEnd = LineEnd ;
307+ sWordEnd = LineEnd ;
307308 }
308309 else
309310 {
310- WordEnd = m . Groups [ "WordEnd" ] . Value ;
311+ sWordEnd = m . Groups [ "WordEnd" ] . Value ;
311312 }
312- mySubtitle . Add ( new subtitle { Content = m . Groups [ "Content" ] . Value , WordStart = WordStart , WordEnd = WordEnd , Position = Position , Selected = false } ) ;
313- Position = Position + m . Groups [ "Content" ] . Value . Length + 1 ;
314- WordStart = WordEnd ;
313+ mySubtitle . Add ( new subtitle { Content = m . Groups [ "Content" ] . Value , WordStart = sWordStart , WordEnd = sWordEnd , Position = sPosition , Selected = false } ) ;
314+ sPosition = sPosition + m . Groups [ "Content" ] . Value . Length + 1 ;
315+ sWordStart = sWordEnd ;
315316 }
316317 }
317318 }
@@ -417,6 +418,7 @@ private void button_loadToSeperate_Click(object sender, EventArgs e)
417418 }
418419 else
419420 generateRichText ( ) ;
421+ button_processVTT . Text = "Process VTT" ;
420422 }
421423
422424 private void richTextBox_Words_MouseUp ( object sender , MouseEventArgs e )
0 commit comments