Aeidon Subtitle Library

1.16 · active · verified Fri Apr 17

Aeidon is a library designed for reading, writing, and manipulating text-based subtitle files (e.g., SRT, ASS, SUB). It is primarily developed as a core component for the Gaupol subtitle editor. The current version is 1.16, and releases occur infrequently, typically 1-3 times per year, focusing on Python compatibility and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load SRT subtitle content from a string, manipulate cues (add, shift times), and then save the modified content back to a string using Aeidon's `File` and `SrtFormat` classes.

import io
from aeidon.files import File
from aeidon.formats import SrtFormat
from aeidon.cues import Cue, Time, Line

# Simulate an existing SRT file content
srt_content = """
1
00:00:01,000 --> 00:00:03,000
Hello World!

2
00:00:04,500 --> 00:00:06,500
This is a test.
"""

# Create an Aeidon File object
subtitle_file = File()

# Load subtitle content from a string (can be a file path too)
sio_input = io.StringIO(srt_content)
SrtFormat.read(sio_input, subtitle_file)

print("--- Original Cues ---")
for cue in subtitle_file.cues:
    print(f"  {cue.start_time} --> {cue.end_time}: {[line.text for line in cue.lines]}")

# Add a new cue
new_cue = Cue()
new_cue.start_time = Time(milliseconds=8000)
new_cue.end_time = Time(milliseconds=10000)
new_cue.lines.append(Line("A new cue added by Aeidon!"))
subtitle_file.cues.append(new_cue)

# Shift all cues by 2 seconds forward
for cue in subtitle_file.cues:
    cue.start_time = cue.start_time.shift_milliseconds(2000)
    cue.end_time = cue.end_time.shift_milliseconds(2000)

print("\n--- Modified Cues (shifted and new cue) ---")
for cue in subtitle_file.cues:
    print(f"  {cue.start_time} --> {cue.end_time}: {[line.text for line in cue.lines]}")

# Save the modified subtitle content to a string
sio_output = io.StringIO()
SrtFormat.write(sio_output, subtitle_file)

print("\n--- Saved SRT Content ---")
print(sio_output.getvalue())

sio_input.close()
sio_output.close()

view raw JSON →