本文整理汇总了Python中pysrt.SubRipFile.clean_indexes方法的典型用法代码示例。如果您正苦于以下问题:Python SubRipFile.clean_indexes方法的具体用法?Python SubRipFile.clean_indexes怎么用?Python SubRipFile.clean_indexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysrt.SubRipFile
的用法示例。
在下文中一共展示了SubRipFile.clean_indexes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_subtitle
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import clean_indexes [as 别名]
def merge_subtitle(sub_a, sub_b, delta, encoding='utf-8'):
"""
合并两种不同言语的srt字幕
因为两个字幕文件的时间轴不一样,所以合并后的字幕会在某一字幕文件转换时生成新的一条字幕,
导致双语字幕并不是同时变化,不过这也是没有办法的事,无法避免
参考https://github.com/byroot/pysrt/issues/17
https://github.com/byroot/pysrt/issues/15
:param sub_a: 使用sub_a = SubRipFile.open(sub_a_path, encoding=encoding)
:param sub_b:
:param delta:
:return:
"""
out = SubRipFile()
intervals = [item.start.ordinal for item in sub_a]
intervals.extend([item.end.ordinal for item in sub_a])
intervals.extend([item.start.ordinal for item in sub_b])
intervals.extend([item.end.ordinal for item in sub_b])
intervals.sort()
j = k = 0
for i in xrange(1, len(intervals)):
start = SubRipTime.from_ordinal(intervals[i - 1])
end = SubRipTime.from_ordinal(intervals[i])
if (end - start) > delta:
text_a, j = find_subtitle(sub_a, start, end, j)
text_b, k = find_subtitle(sub_b, start, end, k)
text = join_lines(text_a, text_b)
if len(text) > 0:
item = SubRipItem(0, start, end, text)
out.append(item)
out.clean_indexes()
return out
示例2: merge_subtitle
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import clean_indexes [as 别名]
def merge_subtitle(sub_a, sub_b, delta):
out = SubRipFile()
intervals = [item.start.ordinal for item in sub_a]
intervals.extend([item.end.ordinal for item in sub_a])
intervals.extend([item.start.ordinal for item in sub_b])
intervals.extend([item.end.ordinal for item in sub_b])
intervals.sort()
j = k = 0
for i in xrange(1, len(intervals)):
start = SubRipTime.from_ordinal(intervals[i-1])
end = SubRipTime.from_ordinal(intervals[i])
if (end-start) > delta:
text_a, j = find_subtitle(sub_a, start, end, j)
text_b, k = find_subtitle(sub_b, start, end, k)
text = join_lines(text_a, text_b)
if len(text) > 0:
item = SubRipItem(0, start, end, text)
out.append(item)
out.clean_indexes()
return out
示例3: SubRipFile
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import clean_indexes [as 别名]
srt_log_path = current_directory + '/comment_log/' + chat_channel + '.srt'
bot = irc_bot.irc_bot(username, oauth, chat_channel, chat_server[0], chat_server[1], twitchclient_version = twitchclient_version)
outsrt = SubRipFile()
text = ''
while 1:
raw_msg_list = bot.get_message()
if len(raw_msg_list) > 0:
if len(text) > 0:
end = SubRipTime.from_time(datetime.now())
item = SubRipItem(0, start, end, text)
outsrt.append(item)
start = SubRipTime.from_time(datetime.now())
text = ''
timestamp = get_timestamp(timestamp_format)
for item in raw_msg_list:
if record_raw:
log_add(raw_log_path, timestamp + ' ' + item + '\n')
username, message = irc_bot.parse_user(item)
if username != '':
safe_print(chat_channel + " " + username + ": " + message)
log_add(log_path, timestamp + ' ' + username + ': ' + message + '\n')
text += username + ": " + message + '\n'
outsrt.clean_indexes()
outsrt.save(srt_log_path, encoding='utf-8')
示例4: SubRipFile
# 需要导入模块: from pysrt import SubRipFile [as 别名]
# 或者: from pysrt.SubRipFile import clean_indexes [as 别名]
srt = SubRipFile(eol='\n', encoding='utf-8')
i = 1
for line in sublog:
line = line.split(",", 1)
if (line[0] and line[0][0] == '-'):
if (START_TIME == None and line[0][:8] == '- start '):
START_TIME = datetime.strptime(line[0], '- start ' + TIMEFORMAT +
'\n')
continue
no = datetime.strptime(line[0], TIMEFORMAT) - START_TIME
if (abs(no) > timedelta(1)):
print("\nCan't go over a day in a subtitle! Delete non-used lines in" + \
" log.\nLet there only be one '- start' line at the top of" + \
" the log-file.")
sys.exit(1)
time = SubRipTime.from_ordinal(no.seconds*1000 + no.microseconds*0.001)
item = SubRipItem(i, start=time, end=time + 30*1000,
text=unicode(line[1], 'utf-8'))
srt.append(item)
i += 1
srt.clean_indexes()
#srt.save(path=sys.stdout)
for line in srt:
sys.stdout.write(unicode(line).encode('utf-8'))