Hi,
Thanks for this package! It does exactly what I needed.
Running it on 1700 files it panicked once on Subtitle.RemoveHI() method:
Exception has occurred: panic
"runtime error: index out of range [0] with length 0"
Stack:
2 0x0000000100413cd4 in github.com/icza/srtgears.(*Subtitle).RemoveHI
at ./go/pkg/mod/github.com/icza/srtgears@v0.0.0-20220812134320-0c724b7bb537/subtitle.go:57
3 0x0000000100413545 in github.com/icza/srtgears.(*SubsPack).RemoveHI
at ./go/pkg/mod/github.com/icza/srtgears@v0.0.0-20220812134320-0c724b7bb537/subspack.go:68
(truncated)
Subtitle that caused it:
185
00:27:39,128 --> 00:27:43,923
<he explains how trap works>
Fixed with length check:
func (s *Subtitle) RemoveHI() (remove bool) {
// It may be just some (e.g. first) lines are hearing impaired.
for i := len(s.Lines) - 1; i >= 0; i-- {
line := s.Lines[i]
// Check without HTML formatting to recognize and remove these:
// "<i>[PHONE RINGING]</i>"
line = htmlPattern.ReplaceAllString(line, "")
// BEGIN FIX
if len(line) == 0 {
remove = true
s.Lines = append(s.Lines[:i], s.Lines[i+1:]...)
continue
}
// END FIX
first, last := line[0], line[len(line)-1]
if first == '[' && last == ']' || first == '(' && last == ')' {
remove = true
s.Lines = append(s.Lines[:i], s.Lines[i+1:]...)
}
}
return
}
Also, in subrip.go line 219, should have comma before milliseconds:
Hi, Thanks for this package! It does exactly what I needed.
Running it on 1700 files it panicked once on Subtitle.RemoveHI() method:
Subtitle that caused it:
Fixed with length check:
Also, in subrip.go line 219, should have comma before milliseconds:
wr.prf("%02d:%02d:%02d,%03d", hour, min, sec, ms)
Hope this helps. Thanks again.