-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathvtt2srt.py
More file actions
31 lines (24 loc) · 1.39 KB
/
Copy pathvtt2srt.py
File metadata and controls
31 lines (24 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
"""
VTT to SRT conversion module
Thanks to (c) Jansen A. Simanullang for his function taken from vtt-to-srt project
See https://github.com/jansenicus/vtt-to-srt.py
SPDX-License-Identifier: MIT
"""
import re
class vtt2srt(object):
def convertContent(self, fileContents):
replacement = re.sub(r'(\d\d:\d\d:\d\d).(\d\d\d) --> (\d\d:\d\d:\d\d).(\d\d\d)(?:[ \-\w]+:[\w\%\d:]+)*\n', r'\1,\2 --> \3,\4\n', fileContents)
replacement = re.sub(r'(\d\d:\d\d).(\d\d\d) --> (\d\d:\d\d).(\d\d\d)(?:[ \-\w]+:[\w\%\d:]+)*\n', r'\1,\2 --> \3,\4\n', replacement)
replacement = re.sub(r'(\d\d).(\d\d\d) --> (\d\d).(\d\d\d)(?:[ \-\w]+:[\w\%\d:]+)*\n', r'\1,\2 --> \3,\4\n', replacement)
replacement = re.sub(r'WEBVTT\n', '', replacement)
replacement = re.sub(r'Kind:[ \-\w]+\n', '', replacement)
replacement = re.sub(r'Language:[ \-\w]+\n', '', replacement)
# replacement = re.sub(r'^\d+\n', '', replacement)
# replacement = re.sub(r'\n\d+\n', '\n', replacement)
replacement = re.sub(r'<c[.\w\d]*>', '', replacement)
replacement = re.sub(r'</c>', '', replacement)
replacement = re.sub(r'<\d\d:\d\d:\d\d.\d\d\d>', '', replacement)
replacement = re.sub(r'::[\-\w]+\([\-.\w\d]+\)[ ]*{[.,:;\(\) \-\w\d]+\n }\n', '', replacement)
replacement = re.sub(r'Style:\n##\n', '', replacement)
return replacement