]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/webvtt.py
[ie/commonmistakes] Raise error on blob URLs (#9897)
[yt-dlp.git] / yt_dlp / webvtt.py
index 23d67a8971d78ad3cec493c516fcc078c60fe313..7683bfb0f3a0768e44b76c70ab034cd2da5a5d82 100644 (file)
@@ -78,7 +78,7 @@ def commit(self):
 class ParseError(Exception):
     def __init__(self, parser):
         super().__init__("Parse error at position %u (near %r)" % (
-            parser._pos, parser._data[parser._pos:parser._pos + 20]
+            parser._pos, parser._data[parser._pos:parser._pos + 100]
         ))
 
 
@@ -93,8 +93,9 @@ def __init__(self, parser):
     ([0-9]{3})?
 ''')
 _REGEX_EOF = re.compile(r'\Z')
-_REGEX_NL = re.compile(r'(?:\r\n|[\r\n])')
+_REGEX_NL = re.compile(r'(?:\r\n|[\r\n]|$)')
 _REGEX_BLANK = re.compile(r'(?:\r\n|[\r\n])+')
+_REGEX_OPTIONAL_WHITESPACE = re.compile(r'[ \t]*')
 
 
 def _parse_ts(ts):
@@ -140,7 +141,6 @@ class HeaderBlock(Block):
     A WebVTT block that may only appear in the header part of the file,
     i.e. before any cue blocks.
     """
-
     pass
 
 
@@ -287,6 +287,7 @@ def parse(cls, parser):
         if not m1:
             return None
         m2 = parser.consume(cls._REGEX_SETTINGS)
+        parser.consume(_REGEX_OPTIONAL_WHITESPACE)
         if not parser.consume(_REGEX_NL):
             return None