second-state / chat-with-chatgpt

Chat with ChatGPT via GitHub issue comments.
111 stars 13 forks source link

closed captions #363

Open The-Bart-The opened 9 months ago

The-Bart-The commented 9 months ago

Compose a Python script that converts a Sonic Scenarist Closed Captions file (.scc) to an Advanced SubStation Alpha file (.ass)

alabulei1 commented 9 months ago

Sure! Here's a simple Python script that can convert a Sonic Scenarist Closed Captions file (.scc) to an Advanced SubStation Alpha file (.ass):

def convert_scc_to_ass(scc_file, ass_file):
    with open(scc_file, 'r') as scc:
        lines = scc.readlines()

    ass_lines = []
    for line in lines:
        if line.startswith('Scenarist_SCC V1.0'):
            continue  # Skip header

        if line.startswith('00:'):
            time, caption = line.replace('\n', '').split(' ', 1)
            start_time, end_time = time.split(':')[-1], time.split(':')[-1]
            start_time = f'{start_time[:-2]}.{start_time[-2:]}'  # Convert to ASS time format
            end_time = f'{end_time[:-2]}.{end_time[-2:]}'  # Convert to ASS time format
            ass_lines.append(f'Dialogue: 0,{start_time},{end_time},Default,,0,0,0,,{caption}\n')

    with open(ass_file, 'w') as ass:
        ass.writelines(ass_lines)

# Usage example
convert_scc_to_ass('input.scc', 'output.ass')

Make sure you replace 'input.scc' and 'output.ass' with the actual paths to your input SCC file and the desired output ASS file, respectively.

You can run this script by saving it to a Python file (e.g., scc_to_ass_converter.py) and executing it using a Python interpreter:

$ python scc_to_ass_converter.py

Hope this helps! Let me know if you have any further questions.