mirror of https://github.com/morpheus65535/bazarr
fix #731
This commit is contained in:
parent
53f7b234ba
commit
d5feea0b09
|
@ -12,3 +12,6 @@ class UnknownFormatIdentifierError(Pysubs2Error):
|
||||||
|
|
||||||
class FormatAutodetectionError(Pysubs2Error):
|
class FormatAutodetectionError(Pysubs2Error):
|
||||||
"""Subtitle format is ambiguous or unknown."""
|
"""Subtitle format is ambiguous or unknown."""
|
||||||
|
|
||||||
|
class ContentNotUsable(Pysubs2Error):
|
||||||
|
"""Current content not usable for specified format"""
|
||||||
|
|
|
@ -41,6 +41,7 @@ class SSAStyle(object):
|
||||||
self.italic = False #: Italic
|
self.italic = False #: Italic
|
||||||
self.underline = False #: Underline (ASS only)
|
self.underline = False #: Underline (ASS only)
|
||||||
self.strikeout = False #: Strikeout (ASS only)
|
self.strikeout = False #: Strikeout (ASS only)
|
||||||
|
self.drawing = False #: Drawing (ASS only, see http://docs.aegisub.org/3.1/ASS_Tags/#drawing-tags
|
||||||
self.scalex = 100.0 #: Horizontal scaling (ASS only)
|
self.scalex = 100.0 #: Horizontal scaling (ASS only)
|
||||||
self.scaley = 100.0 #: Vertical scaling (ASS only)
|
self.scaley = 100.0 #: Vertical scaling (ASS only)
|
||||||
self.spacing = 0.0 #: Letter spacing (ASS only)
|
self.spacing = 0.0 #: Letter spacing (ASS only)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from .formatbase import FormatBase
|
||||||
from .ssaevent import SSAEvent
|
from .ssaevent import SSAEvent
|
||||||
from .ssastyle import SSAStyle
|
from .ssastyle import SSAStyle
|
||||||
from .substation import parse_tags
|
from .substation import parse_tags
|
||||||
|
from .exceptions import ContentNotUsable
|
||||||
from .time import ms_to_times, make_time, TIMESTAMP, timestamp_to_ms
|
from .time import ms_to_times, make_time, TIMESTAMP, timestamp_to_ms
|
||||||
|
|
||||||
#: Largest timestamp allowed in SubRip, ie. 99:59:59,999.
|
#: Largest timestamp allowed in SubRip, ie. 99:59:59,999.
|
||||||
|
@ -81,6 +82,7 @@ class SubripFormat(FormatBase):
|
||||||
if sty.italic: fragment = "<i>%s</i>" % fragment
|
if sty.italic: fragment = "<i>%s</i>" % fragment
|
||||||
if sty.underline: fragment = "<u>%s</u>" % fragment
|
if sty.underline: fragment = "<u>%s</u>" % fragment
|
||||||
if sty.strikeout: fragment = "<s>%s</s>" % fragment
|
if sty.strikeout: fragment = "<s>%s</s>" % fragment
|
||||||
|
if sty.drawing: raise ContentNotUsable
|
||||||
body.append(fragment)
|
body.append(fragment)
|
||||||
|
|
||||||
return re.sub("\n+", "\n", "".join(body).strip())
|
return re.sub("\n+", "\n", "".join(body).strip())
|
||||||
|
@ -90,7 +92,10 @@ class SubripFormat(FormatBase):
|
||||||
for i, line in enumerate(visible_lines, 1):
|
for i, line in enumerate(visible_lines, 1):
|
||||||
start = ms_to_timestamp(line.start)
|
start = ms_to_timestamp(line.start)
|
||||||
end = ms_to_timestamp(line.end)
|
end = ms_to_timestamp(line.end)
|
||||||
text = prepare_text(line.text, subs.styles.get(line.style, SSAStyle.DEFAULT_STYLE))
|
try:
|
||||||
|
text = prepare_text(line.text, subs.styles.get(line.style, SSAStyle.DEFAULT_STYLE))
|
||||||
|
except ContentNotUsable:
|
||||||
|
continue
|
||||||
|
|
||||||
print("%d" % i, file=fp) # Python 2.7 compat
|
print("%d" % i, file=fp) # Python 2.7 compat
|
||||||
print(start, "-->", end, file=fp)
|
print(start, "-->", end, file=fp)
|
||||||
|
|
|
@ -110,7 +110,7 @@ def parse_tags(text, style=SSAStyle.DEFAULT_STYLE, styles={}):
|
||||||
|
|
||||||
def apply_overrides(all_overrides):
|
def apply_overrides(all_overrides):
|
||||||
s = style.copy()
|
s = style.copy()
|
||||||
for tag in re.findall(r"\\[ibus][10]|\\r[a-zA-Z_0-9 ]*", all_overrides):
|
for tag in re.findall(r"\\[ibusp][0-9]|\\r[a-zA-Z_0-9 ]*", all_overrides):
|
||||||
if tag == r"\r":
|
if tag == r"\r":
|
||||||
s = style.copy() # reset to original line style
|
s = style.copy() # reset to original line style
|
||||||
elif tag.startswith(r"\r"):
|
elif tag.startswith(r"\r"):
|
||||||
|
@ -122,6 +122,13 @@ def parse_tags(text, style=SSAStyle.DEFAULT_STYLE, styles={}):
|
||||||
elif "b" in tag: s.bold = "1" in tag
|
elif "b" in tag: s.bold = "1" in tag
|
||||||
elif "u" in tag: s.underline = "1" in tag
|
elif "u" in tag: s.underline = "1" in tag
|
||||||
elif "s" in tag: s.strikeout = "1" in tag
|
elif "s" in tag: s.strikeout = "1" in tag
|
||||||
|
elif "p" in tag:
|
||||||
|
try:
|
||||||
|
scale = int(tag[2:])
|
||||||
|
except (ValueError, IndexError):
|
||||||
|
continue
|
||||||
|
|
||||||
|
s.drawing = scale > 0
|
||||||
return s
|
return s
|
||||||
|
|
||||||
overrides = SSAEvent.OVERRIDE_SEQUENCE.findall(text)
|
overrides = SSAEvent.OVERRIDE_SEQUENCE.findall(text)
|
||||||
|
|
|
@ -279,6 +279,12 @@ class Subtitle(Subtitle_):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pysubs2_to_unicode(cls, sub, format="srt"):
|
def pysubs2_to_unicode(cls, sub, format="srt"):
|
||||||
|
"""
|
||||||
|
this is a modified version of pysubs2.SubripFormat.to_file with special handling for drawing tags in ASS
|
||||||
|
:param sub:
|
||||||
|
:param format:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
def ms_to_timestamp(ms, mssep=","):
|
def ms_to_timestamp(ms, mssep=","):
|
||||||
"""Convert ms to 'HH:MM:SS,mmm'"""
|
"""Convert ms to 'HH:MM:SS,mmm'"""
|
||||||
# XXX throw on overflow/underflow?
|
# XXX throw on overflow/underflow?
|
||||||
|
@ -290,9 +296,12 @@ class Subtitle(Subtitle_):
|
||||||
def prepare_text(text, style):
|
def prepare_text(text, style):
|
||||||
body = []
|
body = []
|
||||||
for fragment, sty in parse_tags(text, style, sub.styles):
|
for fragment, sty in parse_tags(text, style, sub.styles):
|
||||||
fragment = fragment.replace(r"\h", u" ")
|
fragment = fragment.replace(ur"\h", u" ")
|
||||||
fragment = fragment.replace(r"\n", u"\n")
|
fragment = fragment.replace(ur"\n", u"\n")
|
||||||
fragment = fragment.replace(r"\N", u"\n")
|
fragment = fragment.replace(ur"\N", u"\n")
|
||||||
|
if sty.drawing:
|
||||||
|
raise pysubs2.ContentNotUsable
|
||||||
|
|
||||||
if format == "srt":
|
if format == "srt":
|
||||||
if sty.italic:
|
if sty.italic:
|
||||||
fragment = u"<i>%s</i>" % fragment
|
fragment = u"<i>%s</i>" % fragment
|
||||||
|
@ -324,7 +333,10 @@ class Subtitle(Subtitle_):
|
||||||
for i, line in enumerate(visible_lines, 1):
|
for i, line in enumerate(visible_lines, 1):
|
||||||
start = ms_to_timestamp(line.start, mssep=mssep)
|
start = ms_to_timestamp(line.start, mssep=mssep)
|
||||||
end = ms_to_timestamp(line.end, mssep=mssep)
|
end = ms_to_timestamp(line.end, mssep=mssep)
|
||||||
text = prepare_text(line.text, sub.styles.get(line.style, SSAStyle.DEFAULT_STYLE))
|
try:
|
||||||
|
text = prepare_text(line.text, sub.styles.get(line.style, SSAStyle.DEFAULT_STYLE))
|
||||||
|
except pysubs2.ContentNotUsable:
|
||||||
|
continue
|
||||||
|
|
||||||
out.append(u"%d\n" % i)
|
out.append(u"%d\n" % i)
|
||||||
out.append(u"%s --> %s\n" % (start, end))
|
out.append(u"%s --> %s\n" % (start, end))
|
||||||
|
|
Loading…
Reference in New Issue