File size: 963 Bytes
6b5f1f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python

import os
import re

def process_caption_files():
    for file in os.listdir():
        if file.endswith(".caption"):
            # Check if the file already contains processed data
            with open(file, 'r') as f:
                lines = f.readlines()
                
                if "\n----------\n" not in "".join(lines):
                    continue
                
                for line in lines:
                    if "----------" in line:
                        break  # Stop processing after finding the separator
                        
                content = ''.join(lines[:lines.index(line)])  # Extract text before the separator
                processed_content = re.sub(r'[\-]+|\n', '', content)  # Remove newlines and separator
                
            with open(file, 'w') as f:  # Save the condensed caption back to the same file
                f.write(processed_content)

process_caption_files()