在没有特定类型弹幕下会报NoneTypeError
Closed this issue · 1 comments
NingyuanWang commented
经测试,在打开没有某一类弹幕的json时(如没有
libass/display.py
class Display
中的弹幕类型,当danmaku.content内容为空时,程序报错。
在对相关区间做出如下修改后:
` def _max_length(self):
''' 最长的行字符数 '''
try:
assert hasattr(self.danmaku.content,'split')
return max(map(display_length, self.danmaku.content.split('\n')))
except AssertionError:
return 256
def _width(self):
''' 整条字幕宽度 '''
char_count = self.max_length / 2
return intceil(self.font_size * char_count)
def _height(self):
''' 整条字幕高度 '''
try:
assert hasattr(self.danmaku.content,'split')
line_count = len(self.danmaku.content.split('\n'))
return line_count * self.font_size
except AssertionError:
return self.font_size`
该文件不再报错。随后在
libass/util.py中correct_typos报错
在此处将程序修改为
def correct_typos(text):
''' 修正一些评论者的拼写错误 '''
try:
assert hasattr(text,'replace')
text = text.replace('/n', '\\N')
text = text.replace('>', '>')
text = text.replace('<', '<')
except AssertionError:
text = " "#Use a space as a dummy text to avoid further Nonetype Errors.
return text
程序不再报错,正常生成ass文件。
muzuiget commented
我几乎忘记这个 issue 了,你能提供出错的弹幕文件吗?