byroot / pysrt

Python parser for SubRip (srt) files
GNU General Public License v3.0
451 stars 69 forks source link

Is it possible to create a new srt file using this? #56

Closed tabs-mc closed 10 years ago

tabs-mc commented 10 years ago

This seems geared towards editing existing files. Is there a way to create a new .srt file in python with the existing functions?

byroot commented 10 years ago

There is:

import pysrt

file = pysrt.SubRipFile()
sub = pysrt.SubRipItem(1, start='00:02:04,000', end='00:02:08,000', text="Hello World!")
file.append(sub)
file.save('my_movie.srt')
$ cat my_movie.srt 
1
00:02:04,000 --> 00:02:08,000
Hello World!

Just take a look at the test suite, you'll see what the possibilities are.