fix: handle "-" output filename to write to stdout
This commit is contained in:
parent
a8c72b3efa
commit
17c7d50eef
1 changed files with 10 additions and 2 deletions
12
merge_srt.py
12
merge_srt.py
|
@ -166,6 +166,14 @@ if __name__ == '__main__':
|
||||||
'text': entry2['text'],
|
'text': entry2['text'],
|
||||||
})
|
})
|
||||||
|
|
||||||
with open(output_filename, 'w', encoding='utf-8') as f:
|
if output_filename == '-':
|
||||||
|
out = sys.stdout
|
||||||
|
else:
|
||||||
|
out = open(output_filename, 'w', encoding='utf-8')
|
||||||
|
|
||||||
|
try:
|
||||||
for i, entry in enumerate(output, start=1):
|
for i, entry in enumerate(output, start=1):
|
||||||
f.write(f"{i}\n{entry['timestamp']}\n{entry['text'].strip()}\n\n")
|
out.write(f"{i}\n{entry['timestamp']}\n{entry['text'].strip()}\n\n")
|
||||||
|
finally:
|
||||||
|
if out is not sys.stdout:
|
||||||
|
out.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue