Ajout fichier

This commit is contained in:
tfa
2024-07-24 10:32:55 +02:00
parent 47809e8a71
commit b50533436a

24
convert_vtt_to_srt.py Normal file
View File

@@ -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 <path_to_vtt_file>")
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}")