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 a pathlib.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 by subsy.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 a pathlib.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 the source attribute. Failing that, a ValueError 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 the source 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.