udemy-downloader/vtt_to_srt.py
Puyodead1 9f3bda6c6c Revert "Merge branch 'master' into feat_aria2c"
This reverts commit e6dcde0335e8fdd7278dc72e9233034a5efc2748, reversing
changes made to 1ad4f1eddee0e34d028e3e74bf331a92a8388a36.
2021-05-28 23:05:54 -04:00

20 lines
631 B
Python

from webvtt import WebVTT
import html, os
from pysrt.srtitem import SubRipItem
from pysrt.srttime import SubRipTime
def convert(directory, filename):
index = 0
vtt_filepath = os.path.join(directory, filename + ".vtt")
srt_filepath = os.path.join(directory, filename + ".srt")
srt = open(srt_filepath, "w")
for caption in WebVTT().read(vtt_filepath):
index += 1
start = SubRipTime(0, 0, caption.start_in_seconds)
end = SubRipTime(0, 0, caption.end_in_seconds)
srt.write(
SubRipItem(index, start, end, html.unescape(
caption.text)).__str__() + "\n")