Subtitles#
- class Subtitles(subtitles=None, source=None)[source]#
Represents a sequence of subtitles.
Example:
>>> import subsy >>> subtitles = subsy.load('reference.srt') >>> len(subtitles)
- subtitles#
List of
Subtitle
instances that make up the sequence.
- source#
Dictionary holding meta information about the subtitles’s source.
This is usually a file, and the dictionary would contain a key named
'file'
with apathlib.Path
object for its value pointing to the file-system location that the subtitles were loaded from. A second key named'encoding'
would store the text encoding, as automatically detected bysubsy.load()
or passed in to it specifically.These two entries, if they exist, are used by the
save()
method to update the file (if called without arguments).
- save(file=None, encoding=None, format=None)[source]#
Saves the subtitles to disk.
An optional
file
can be specified (as apathlib.Path
object or string) to indicate the path and file name. If not given, the'file'
reference will be retrieved from the meta information stored in thesource
attribute. Failing that, aValueError
is raised.An optional
encoding
can be specified. All valid encoding names are supported. If not given, the value for'encoding'
will be retrieved from thesource
meta info. If the key is not found, it defaults to'UTF-8-sig'
, i.e. variable-length Unicode with signature / byte-order mark.An optional
format
can be specified, which would otherwise be deduced from the file ending.