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
Subtitleinstances 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.Pathobject 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
filecan be specified (as apathlib.Pathobject or string) to indicate the path and file name. If not given, the'file'reference will be retrieved from the meta information stored in thesourceattribute. Failing that, aValueErroris raised.An optional
encodingcan be specified. All valid encoding names are supported. If not given, the value for'encoding'will be retrieved from thesourcemeta 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
formatcan be specified, which would otherwise be deduced from the file ending.