1
1
from __future__ import absolute_import
2
- import re
2
+ from re import finditer , search , sub , DOTALL , MULTILINE
3
3
4
4
from .baseparser import BaseParser , ParseError , HEX_COLORS
5
5
@@ -12,7 +12,7 @@ def _parse(self, text, fps):
12
12
return self ._srt_to_dict (text )
13
13
14
14
def _removeTags (self , text ):
15
- return re . sub ('<[^>]*>' , '' , text )
15
+ return sub ('<[^>]*>' , '' , text )
16
16
17
17
def _getColor (self , text , color ):
18
18
newColor = color
@@ -21,7 +21,7 @@ def _getColor(self, text, color):
21
21
if text .find ('</font>' ) != - 1 or text .find ('</Font>' ) != - 1 :
22
22
newColor = 'default'
23
23
else :
24
- colorMatch = re . search ('<[Ff]ont [Cc]olor=(.+?)>' , text , re . DOTALL )
24
+ colorMatch = search ('<[Ff]ont [Cc]olor=(.+?)>' , text , DOTALL )
25
25
colorText = colorMatch and colorMatch .group (1 )
26
26
colorText = colorText and colorText .replace ("'" , "" ).replace ('"' , '' )
27
27
if text .find ('</font>' ) != - 1 or text .find ('</Font>' ) != - 1 :
@@ -30,12 +30,12 @@ def _getColor(self, text, color):
30
30
newColor = color
31
31
else :
32
32
color = 'default'
33
- colorMatch = re . search ('<[Ff]ont [Cc]olor=(.+?)>' , text , re . DOTALL )
33
+ colorMatch = search ('<[Ff]ont [Cc]olor=(.+?)>' , text , DOTALL )
34
34
colorText = colorMatch and colorMatch .group (1 ) or color
35
35
colorText = colorText .replace ("'" , "" ).replace ('"' , '' )
36
36
37
37
if colorText :
38
- hexColor = re . search ("(\#[0-9,a-f,A-F]{6})" , colorText )
38
+ hexColor = search ("(\#[0-9,a-f,A-F]{6})" , colorText )
39
39
if hexColor :
40
40
color = hexColor .group (1 )[1 :]
41
41
else :
@@ -90,7 +90,7 @@ def _srt_to_dict(self, srtText):
90
90
subs = []
91
91
idx = 0
92
92
srtText = srtText .replace ('\r \n ' , '\n ' ).strip () + "\n \n "
93
- for s in re . finditer (r'(^\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*-->\s*(\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*\n(.+?)(?:\n\n|\n\d+\s*\n)' , srtText , re . DOTALL | re . MULTILINE ):
93
+ for s in finditer (r'(^\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*-->\s*(\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*\n(.+?)(?:\n\n|\n\d+\s*\n)' , srtText , DOTALL | MULTILINE ):
94
94
try :
95
95
idx += 1
96
96
shour , smin , ssec , smsec = int (s .group (1 )), int (s .group (2 )), int (s .group (3 )), int (s .group (4 ))
0 commit comments