pysrt icon indicating copy to clipboard operation
pysrt copied to clipboard

Deleting a subtitles line should also trigger a renumber

Open Andbarz opened this issue 10 years ago • 3 comments

I'm using your library to build a simple scripts which downloads subtitles from opensubtitles.org, removes all the unnecessary lines(synced by... and similar entries), saves the srt file and then encodes it into the video file with ffmpeg. I've found that ffmpeg doesn't like srt files where there's a missing line, and it refuses to work with them.

This is what happens now:

1
00:00:22,712 --> 00:00:24,478
first line

2
00:00:25,000 --> 00:00:31,074
second line

3
00:00:57,413 --> 00:01:00,180
third line

when i run

del sub[1]

I get

1
00:00:22,712 --> 00:00:24,478
first line

3
00:00:57,413 --> 00:01:00,180
third line

Which is not valid according to ffmpeg. Instead I should get

1
00:00:22,712 --> 00:00:24,478
first line

2
00:00:57,413 --> 00:01:00,180
third line

Can you please make that when I close an srt file, pysrt automatically renumbers all the lines, so that there are no interruptions?

Andbarz avatar Jan 09 '15 16:01 Andbarz

I have to think about it. On one hand it would make perfect sense to do it automatically, but in the other end some subtitle have sometimes some kind of tags as indexes, so it would lose data.

I guess it could do it by default, and you could prevent it with close(clean_indexes=False).

That would require a minor version bump though.

byroot avatar Jan 09 '15 16:01 byroot

By the way until I issue a new version you can simply call clean_indexes() yourself: https://github.com/byroot/pysrt/blob/47aaa592c3bc185cd2bc1d58d1451bf98be3c1ef/pysrt/srtfile.py#L128.

byroot avatar Jan 09 '15 16:01 byroot

Sorry, I didn't find that function. That was what I was really interested in, not automating it on close(). If you haven't time, just let things as they are now.

Andbarz avatar Jan 09 '15 18:01 Andbarz