Skip to content

Commit 3a23b8d

Browse files
committed
remove SRT timestamps
1 parent 8e9021f commit 3a23b8d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import re
2+
import sys
3+
from pathlib import Path
4+
5+
def remove_timestamps_and_line_numbers(input_file, output_file):
6+
# Regex pattern to match timestamp lines
7+
timestamp_pattern = re.compile(r'^\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}$')
8+
# Regex pattern to match line numbers
9+
line_number_pattern = re.compile(r'^\d+$')
10+
11+
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
12+
for line in infile:
13+
line = line.strip()
14+
# Skip timestamp lines and line numbers, write all others
15+
if not timestamp_pattern.match(line) and not line_number_pattern.match(line) and line != '':
16+
outfile.write(line + '\n')
17+
18+
def main():
19+
if len(sys.argv) < 2:
20+
print("Usage: drag and drop SRT files onto this script.")
21+
sys.exit(1)
22+
23+
for input_path in sys.argv[1:]:
24+
input_file = Path(input_path)
25+
if not input_file.exists() or input_file.suffix.lower() != '.srt':
26+
print(f"Skipping invalid file: {input_path}")
27+
continue
28+
29+
output_file = input_file.with_name(f"{input_file.stem}_no_timestamps{input_file.suffix}")
30+
print(f"Processing: {input_file} -> {output_file}")
31+
32+
try:
33+
remove_timestamps_and_line_numbers(input_file, output_file)
34+
print(f"Processed: {output_file}")
35+
except Exception as e:
36+
print(f"Error processing {input_file}: {e}")
37+
38+
if __name__ == "__main__":
39+
main()

0 commit comments

Comments
 (0)