Search code examples
pythonsrt

Python formating SRT files with SRT module


It is impossible for me to make the composer method work with the SRT module. So I wrote this basic example and everything works mostly fine for my needs, but the compose doesn't work. Is there anything wrong with the way I'm using it?

from datetime import timedelta
import srt

td = timedelta(seconds=1)

a = srt.Subtitle(index=1, start=td, end=td, content='Word 1')
b = srt.Subtitle(index=2, start=td, end=td, content='Word 2')

c = [a, b]

print(srt.compose(c))

c = a.to_srt() + b.to_srt()

print("========")
print(c)

print("====")
d = list(srt.parse(c))
print(d)

Solution

  • Apparently the problem was some mistake in the example code I was following. And for to solve this, I need to pass reindex=False to srt.compose.

    Found this solution in the git-hub of the module.

    https://github.com/cdown/srt/issues/62