class AssParse(AssFile): """ Ass Pase Class """ def __init__(self, filename, encoding = 'utf-8', err_ignore = False): """ 初始化here """ AssFile.__init__(self, filename, encoding) self.script_info = AssScriptInfo() self.styles = AssStyles() self.events = AssEvents() self.section = '' self.version = 0 #self.version 0: v4 style; 1: v4+ style; 2: v4++ style self.parse() def parse(self): """ 解析 """ for i in range(len(self.lines)): self.parse_line(self.lines[i]) def parse_line(self, line): try: if line.lower() == '[script info]': self.section = '[Script Info]' elif line.lower() == '[v4 styles]': self.section = '[V4+ Styles]' self.version = 0 elif line.lower() == '[v4+ styles]': self.section = '[V4+ Styles]' self.version = 1 elif line.lower() == '[v4++ styles]': self.section = '[V4+ Styles]' self.version = 2 elif line.lower() == '[events]': self.section = '[Events]' elif not self.section: raise UnknowDataError('Unknow Section: <%s>' % (line)) else: if self.section == '[Script Info]': self.script_info.parse(line)#line, self.version) elif self.section == '[V4+ Styles]': self.styles.parse(line, self.version) elif self.section == '[Events]': self.events.parse(line, self.version) else: raise UnknowDataError("Unkonw Data: <%s>" % (line)) except UnknowDataError, err_msg: print UnknowDataError, ':', err_msg
class AssParse(AssFile): """ Ass Pase Class """ def __init__(self, filename, encoding='utf-8', err_ignore=False): """ 初始化here """ AssFile.__init__(self, filename, encoding) self.script_info = AssScriptInfo() self.styles = AssStyles() self.events = AssEvents() self.section = '' self.version = 0 #self.version 0: v4 style; 1: v4+ style; 2: v4++ style self.parse() def parse(self): """ 解析 """ for i in range(len(self.lines)): self.parse_line(self.lines[i]) def parse_line(self, line): try: if line.lower() == '[script info]': self.section = '[Script Info]' elif line.lower() == '[v4 styles]': self.section = '[V4+ Styles]' self.version = 0 elif line.lower() == '[v4+ styles]': self.section = '[V4+ Styles]' self.version = 1 elif line.lower() == '[v4++ styles]': self.section = '[V4+ Styles]' self.version = 2 elif line.lower() == '[events]': self.section = '[Events]' elif not self.section: raise UnknowDataError('Unknow Section: <%s>' % (line)) else: if self.section == '[Script Info]': self.script_info.parse(line) #line, self.version) elif self.section == '[V4+ Styles]': self.styles.parse(line, self.version) elif self.section == '[Events]': self.events.parse(line, self.version) else: raise UnknowDataError("Unkonw Data: <%s>" % (line)) except UnknowDataError, err_msg: print UnknowDataError, ':', err_msg
def __init__(self, filename, encoding='utf-8', err_ignore=False): """ 初始化here """ AssFile.__init__(self, filename, encoding) self.script_info = AssScriptInfo() self.styles = AssStyles() self.events = AssEvents() self.section = '' self.version = 0 #self.version 0: v4 style; 1: v4+ style; 2: v4++ style self.parse()
def __init__(self, filename, encoding = 'utf-8', err_ignore = False): """ 初始化here """ AssFile.__init__(self, filename, encoding) self.script_info = AssScriptInfo() self.styles = AssStyles() self.events = AssEvents() self.section = '' self.version = 0 #self.version 0: v4 style; 1: v4+ style; 2: v4++ style self.parse()