cdown/srt

Can't make the compose() works

Closed this issue · 9 comments

To me is impossible to make the composer method work. So I wrote this basic example anda everything works mostly fine for my needs, but the compose don't. 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)
cdown commented

It's filtered because it's never displayed (end <= start). If you want to just verbatim print the Subtitle objects, you need to pass reindex=False to srt.compose.

The creators of this module may want to adjust the docs as the same example is given there.
https://srt.readthedocs.io/en/latest/api.html#srt.compose

>>> from datetime import timedelta
>>> td = timedelta(seconds=1)
>>> subs = [
...     Subtitle(index=1, start=td, end=td, content='x'),
...     Subtitle(index=2, start=td, end=td, content='y'),
... ]
>>> compose(subs)  
'1\n00:00:01,000 --> 00:00:01,000\nx\n\n2\n00:00:01,000 --> ...'

The output shown in the docs will not in fact be produced unless reindex=False is passed.

Thanks,

Passing reindex=False to srt.compose works for me. Or just filling the starts and ends with differente and crescent values.

cdown commented

The creators of this module may want to adjust the docs as the same example is given there.

Huh! Thank you very much, these are supposed to be validated automatically by doctest, but it seems it isn't working, let me look into that...

cdown commented

Ok, so this was actually updated in the documentation already, but it looks like readthedocs didn't rebuild for some reason. Looks like RTD didn't build for a year and a half (oh dear...)

cdown commented

Looks like the webhook was failing. I just recreated the project on RTD and it seems to be ok now. Thanks for letting me know!

I got caught by this. Not sure the documentation has been updated
https://srt.readthedocs.io/en/latest/api.html

cdown commented

The documentation looks up to date to me, what are you seeing? It shows this example, which works:

>>> from datetime import timedelta
>>> start = timedelta(seconds=1)
>>> end = timedelta(seconds=2)
>>> subs = [
...     Subtitle(index=1, start=start, end=end, content='x'),
...     Subtitle(index=2, start=start, end=end, content='y'),
... ]
>>> compose(subs)  
'1\n00:00:01,000 --> 00:00:02,000\nx\n\n2\n00:00:01,000 --> ...'

Yep I got that to work too.
But with my work I had to do this srt.compose(subs, reindex=False) as per this Issue.
Thanks for the project