I'm trying to figure out how to make the srt subtitle file txt. I need to modify the sub_title_content.append(line) part to see if the last part of each line in the file ends with a period (.), so I don't know how to configure one line.
def extract_text_from_subtitle(file_name):
sub_title_contents = []
file = open(file_name, 'r')
for line in file:
line = line.replace('\n', '')
if len(line) < 3 and line.isnumeric():
continue
elif line.count(':') > 2 and line.count('-->') > 0:
pass
elif line == '':
pass
else:
sub_title_contents.append(line)
print(line)
file.close()
return sub_title_contents
If I can give you the answer that you want...
strPeriod = "lorem."
strNoPeriod = "ipsum"
print(strPeriod[-1:] is '.') # True
print(strNoPeriod[-1:] is '.') # False
By the way, subtitles are quite a few of the following cases. Think carefully and get what you want.
© 2024 OneMinuteCode. All rights reserved.