From b50533436a076344550bc8879e1d71d7afdf7bf7 Mon Sep 17 00:00:00 2001 From: tfa Date: Wed, 24 Jul 2024 10:32:55 +0200 Subject: [PATCH] Ajout fichier --- convert_vtt_to_srt.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 convert_vtt_to_srt.py diff --git a/convert_vtt_to_srt.py b/convert_vtt_to_srt.py new file mode 100644 index 0000000..a8315b7 --- /dev/null +++ b/convert_vtt_to_srt.py @@ -0,0 +1,24 @@ +import sys +import webvtt + +def vtt_to_srt(vtt_file, srt_file): + webvtt_file = webvtt.read(vtt_file) + with open(srt_file, 'w', encoding='utf-8') as srt: + counter = 1 + for caption in webvtt_file: + srt.write(f"{counter}\n") + srt.write(f"{caption.start.replace('.', ',')} --> {caption.end.replace('.', ',')}\n") + srt.write(f"{caption.text}\n\n") + counter += 1 + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python convert_vtt_to_srt.py ") + sys.exit(1) + + vtt_file = sys.argv[1] + srt_file = vtt_file.replace('.vtt', '.srt') + + vtt_to_srt(vtt_file, srt_file) + print(f"Converted {vtt_file} to {srt_file}") +