Skip to content

Commit ab1a33d

Browse files
committed
Add --output-ext option for SRT output file extension
Introduces a command-line argument to specify the output file extension for processed SRT files, defaulting to .md. Updates help text and ensures the extension is correctly formatted.
1 parent 4a4abfd commit ab1a33d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Programming/srttotext.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def main():
188188
"""
189189
parser = argparse.ArgumentParser(
190190
description="Process SRT subtitle files and text files. Cleans SRT files and formats text files with one sentence per line.",
191-
epilog="Example: text_processor.py *.srt *.txt -s"
191+
epilog="Example: text_processor.py *.srt *.txt -s --output-ext .txt"
192192
)
193193
parser.add_argument(
194194
'files',
@@ -205,8 +205,17 @@ def main():
205205
action='store_true',
206206
help="Skip the sentence-per-line formatting for text files."
207207
)
208+
parser.add_argument(
209+
'--output-ext',
210+
default='.md',
211+
help="Specify the output file extension for SRT files (default: .md)"
212+
)
208213
args = parser.parse_args()
209214

215+
# Ensure output extension starts with a dot
216+
if not args.output_ext.startswith('.'):
217+
args.output_ext = '.' + args.output_ext
218+
210219
input_files = args.files
211220

212221
# If no files were passed as arguments, glob for .srt and .txt files in the current directory.
@@ -252,10 +261,10 @@ def main():
252261
output_folder = input_file.parent / "no_timestamps"
253262
# Create the output folder if it doesn't exist
254263
output_folder.mkdir(exist_ok=True)
255-
output_file_path = output_folder / f"{input_file.stem}_no_timestamps.txt"
264+
output_file_path = output_folder / f"{input_file.stem}_no_timestamps{args.output_ext}"
256265
else:
257266
# Place output in the same directory as the input file
258-
output_file_path = input_file.parent / f"{input_file.stem}_no_timestamps.txt"
267+
output_file_path = input_file.parent / f"{input_file.stem}_no_timestamps{args.output_ext}"
259268

260269
if process_srt_file(input_path, output_file_path):
261270
srt_processed += 1

0 commit comments

Comments
 (0)