当前位置: 首页>>代码示例>>Python>>正文


Python Time.generate_mt方法代码示例

本文整理汇总了Python中Time.generate_mt方法的典型用法代码示例。如果您正苦于以下问题:Python Time.generate_mt方法的具体用法?Python Time.generate_mt怎么用?Python Time.generate_mt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Time的用法示例。


在下文中一共展示了Time.generate_mt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import Time [as 别名]
# 或者: from Time import generate_mt [as 别名]
class Subtitle:
    def __init__(self, number=0, begin='', end='', text=None):
        self.number = number
        self.begin = begin
        self.end = end
        if text is None:
            self.text = []
        else:
            self.text = text

    # Used to validate the content of the subtitle.
    # Mandatory because it generates times.
    # Also generate the mt, which is used to describe the position of the
    # subtitle among others.
    # @return valid True if validate is successful, False otherwise
    def validate(self):
        if self.number == 0 or self.begin == '' or self.end == '' or self.text is None: return False
        zbegin = re.split('\W+', self.begin)
        zend = re.split('\W+', self.end)
        self.time_begin = Time(int(zbegin[0]), int(zbegin[1]), int(zbegin[2]), int(zbegin[3]))
        self.time_end = Time(int(zend[0]), int(zend[1]), int(zend[2]), int(zend[3]))
        self.set_mt()
        del self.begin
        del self.end
        return True

    # Prints the entire subtitle at cout as if it was written in a .srt file
    # @return none
    def show(self):
        print(str(self.number))
        print(self.time_begin.get_formatted() + ' --> ' + self.time_end.get_formatted())
        for line in self.text:
            print(line, end='')
        print('')

    # Generate the mt based on the beginning time of the subtitle
    # @return none
    def set_mt(self):
        self.mt = self.time_begin.generate_mt()

    # Write the subtitle on the file provided
    # @param file The file to be written to
    # @return none
    def write(self, file):
        file.write(str(self.number) + "\n")
        file.write(self.time_begin.get_formatted() + ' --> ' + self.time_end.get_formatted() + "\n")
        for line in self.text:
            file.write(line)
        file.write("\n")

    # Shift the subtitle by shift Time
    # @param shift The time to shift the subtitle
    def shift(self, shift):
        self.time_begin.shift(shift)
        self.time_end.shift(shift)
        self.set_mt()

    # Know if the subtitle begins after time Time
    # @param time The time to be compared to
    # @return boolean True if the subtitle begins after the time provided, False otherwise
    def begins_after(self, time):
        return self.time_begin.is_after(time)

    # Know if the subtitle begins before time Time
    # @param time The time to be compared to
    # @return boolean True if the subtitle begins before the time provided, False otherwise
    def begins_before(self, time):
        return self.time_begin.is_before(time)
开发者ID:Nelgamix,项目名称:python_subtitles_utilities,代码行数:70,代码来源:Subtitle.py


注:本文中的Time.generate_mt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。