This recipe demonstrates how to combine two different subtitle files (e.g., English and Italian) into a single ASS file where one language is positioned at the top and the other at the bottom with different colors.
import pysubs2
from pysubs2 import Alignment, Color, SSAFile, SSAStyle
# Load input files
subs_en = pysubs2.load("subs.en.srt")
subs_it = pysubs2.load("subs.it.srt")
# Create a new container
subs = SSAFile()
# Define styles for positioning and color
subs.styles = {
"bottom": SSAStyle(alignment=Alignment.BOTTOM_CENTER, primarycolor=Color(255, 255, 0)),
"top": SSAStyle(alignment=Alignment.TOP_CENTER, primarycolor=pysubs2.Color(0, 128, 128)),
}
# Add Italian subtitles to the bottom
for e in subs_it:
e.style = "bottom"
subs.append(e)
# Add English subtitles to the top
for e in subs_en:
e.style = "top"
subs.append(e)
# Save as ASS to support positioning
subs.save("subs.ass")