本文整理汇总了Python中Time.get_formatted方法的典型用法代码示例。如果您正苦于以下问题:Python Time.get_formatted方法的具体用法?Python Time.get_formatted怎么用?Python Time.get_formatted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time
的用法示例。
在下文中一共展示了Time.get_formatted方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Time [as 别名]
# 或者: from Time import get_formatted [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)