srthandler
is an .srt
(a.k.a SubRip) subtext file handler written in
Python. A whole .srt
file is represented as one SubtextLayer
object,
a list
consisting of SubtextEntry
objects.
Copyright © 2019–2024, Legisign.org, Tommi Nieminen
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
In addition to internal changes, the public object names were
changed. The new names are Subtext
(was SubtextLayer
) and Entry
(was SubtextEntry
).
Subtext
is a list
of Entry
objects.
check()
-- check integrity of the subtext layerinsert()
-- insert a new entrymove_by()
-- move given entries by given offset forwards or backwardsmove_to()
-- move given entries to a given position in timeparse()
-- parse string as subtext layerread()
-- read and parse a subtext filesync()
-- tries to synchronize entries between given timepointswrite()
-- write a subtext
Entry
is an object holding a single subtext frame with its in- and
out-times and lines of text (as a list of strings).
dur
-- duration of entryintime
-- intime of entryouttime
-- outtime of entrytext
-- text of entry (as a string)
move_by()
-- adjust times by offsetmove_to()
-- set in- and outtimes
to_secs(time_string)
converts a string in SubRip time format
[[[dd:]hh:]mm:]ss[,fff]
(days, hours, minutes, seconds, fractions of
seconds) into seconds. If called with a numeric value, returns the value.
to_timestr(seconds)
converts seconds (float
) to SubRip time format
[[[dd:]hh:]mm:]ss[,fff]
.
ParseError
-- error parsing the fileIndexError
-- invalid indexTimeStampError
-- invalid time stamp