glut23 / webvtt-py

Read, write, convert and segment WebVTT caption files in Python.
MIT License
192 stars 56 forks source link

MalformedCaptionError #12

Closed cschwem2er closed 7 years ago

cschwem2er commented 7 years ago

Hi, I'm not sure whether this is related to the other issues so I opened a new one. I have issues with loadin in a youtube VTT file:

MalformedCaptionError                     Traceback (most recent call last)
<ipython-input-10-cf8d0e78a7c6> in <module>()
----> 1 WebVTT().read('PdUpXrgzSrI.de.vtt')

~/anaconda3/lib/python3.6/site-packages/webvtt/main.py in f(self, file)
     50         def f(self, file):
     51             self.file = file
---> 52             self._captions = parser_class().read(file).captions
     53             return self
     54 

~/anaconda3/lib/python3.6/site-packages/webvtt/generic.py in read(self, file)
    117         content = self._read_content(file)
    118         self._validate(content)
--> 119         self._parse(content)
    120 
    121         return self

~/anaconda3/lib/python3.6/site-packages/webvtt/parsers.py in _parse(self, lines)
     68                     continue
     69                 if not c.lines:
---> 70                     raise MalformedCaptionError('Caption missing text in line {}.'.format(index + 1))
     71 
     72                 self.captions.append(c)

MalformedCaptionError: Caption missing text in line 12.

WebVTT version is 0.3.3

glut23 commented 7 years ago

Hi @methodds looking at the error trace you provided we get a hint of the problem. In line 12 we have a caption missing the text. I read the file you attached and I see same thing happens for few captions. I had a look at the problematic ones and saw a space was used to force the caption text to display in the second line. At the moment the parser removes those spaces and that is why it raises an error. I will update the parser to fix it. I was planning to release an update today or tomorrow with new features and it can also contain this fix. I will let you know when this happens. Thanks for reporting the issue.

cschwem2er commented 7 years ago

Awesome, thank you :)

glut23 commented 7 years ago

Hi @methodds I just released version 0.4.0 that should fix this issue. Thanks!

cschwem2er commented 7 years ago

that was super fast, thank you :)

glut23 commented 7 years ago

Closing this issue as it was solved.