Closed doakey3 closed 7 years ago
In my remove_overlaps function, I made it automatically call clean_indexes() if a subtitle section gets entirely removed.
I noticed in one of your comments you said that this could cause a problem for certain types of srt files. If this is the case, then I should alter my function to not automatically clean the indexes. EDIT: Done.
Sorry but I don't think remove_overlap
belongs to pysrt
. It's a very opinionated method that could legitimately behave in multiple different ways. I prefer to let pysrt
users implement that themselves.
As for to_string
, I'm pretty sure ''.join(subtitles)
should works.
Although this PR didn't make it into the main repo, this helped me a lot with my project. Thank you very much @doakey3!
@byroot you are right to reject this PR, even for me this was not the overlap removal method I needed. This changes start times of subtitles, but what actually made sense is to shorten lifetime of subtitles by changing the end time.
As for to_string, I'm pretty sure
''.join(subtitles)
should works.
That doesn't seem to be the case.
>>> subtitles = pysrt.from_string('1\n00:00:00,000 --> 00:00:05,000\nTest')
>>> ''.join(subtitles)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, SubRipItem found
This works though:
>>> subtitles = pysrt.from_string('1\n00:00:00,000 --> 00:00:05,000\nTest\n\n2\n00:00:10,000 --> 00:00:15,000\nTest 2')
>>> '\n'.join(map(str, subtitles))
'1\n00:00:00,000 --> 00:00:05,000\nTest\n\n2\n00:00:10,000 --> 00:00:15,000\nTest 2\n'
I've created 2 new functions. 1 for removing the overlap between subtitles and another for getting the srt format as a string (as opposed to saving to a file).