See the upgrade notes for what to change in code using the library.
Changes that may need updates to the code using the library
- Requires Python 3.10 or later, as Python 3.7, 3.8 and 3.9 are end-of-life (#136, #148)
- Strict parsing raises
MalformedCaptionErrorfor cues whose end time is not after the start time, for blocks that are not a cue, comment, style or region, such as text without cue timings, for comments whereNOTEis not followed by a space, a tab or a line break, or with-->, and for styles after the first cue (#97, #133) - Writing WebVTT raises
ValueErrorfor-->in a comment or in the header text, which WebVTT does not allow (#134, #135) NOTEblocks with-->are not read as comments, and header text with-->is read as empty, as WebVTT does, so the file can be saved again (#134, #135)- Removed
Caption.CUE_TEXT_TAGS, which is no longer used (#139, #153) save,save_as_srtand the-ooption of the CLI write a path with an extension as given, instead of adding.vttor.srtto it, socaptions.webvttis no longer saved ascaptions.webvtt.vtt(#144, #156)saveandsave_as_srtwithout a path or with a folder, and the-ooption of the CLI with a folder, keep the extension of the file when it is already of the format, so a file read fromcaptions.webvttis saved to it instead ofcaptions.vtt(#159, #195)from_bufferraisesTypeErrorfor a string or bytes, instead ofMalformedFileError: usefrom_stringto read a string, orio.BytesIOto read bytes (#143, #157)- SRT cues without an index are read, as most SRT players do, instead of skipped (#142, #158)
- Styles after the first cue and blocks where
NOTEis not followed by a space, a tab or a line break, such asNOTEBOOK, are ignored, as WebVTT does, and strict parsing raisesMalformedFileErrorwhenWEBVTTis not followed by a space, a tab or the end of the first line, such asWEBVTTX(#141, #194) saveraisesValueErrorforadd_bom=Truewith an encoding without a Byte Order Mark, such aslatin-1, and foradd_bom=Falsewithutf-8-sig,utf-16orutf-32, which always write one, instead of ignoringadd_bom(#160, #196)save_as_srtsaves captions read withfrom_srtorfrom_bufferin SRT format and anencodingin the same encoding, instead of UTF-8, andencoding=Nonesaves in UTF-8 instead of the encoding of the locale (#161, #197)- Setting
Caption.textto a value that is not a string or a sequence of lines raisesTypeErrorinstead ofAttributeError, andCaptionraises it for lines that are not strings instead of accepting them (#162, #198) WebVTTkeeps empty lists given as arguments, as it does with other lists, instead of replacing them with new ones, andStylecopies a list of lines, asCaptiondoes, instead of keeping it (#163, #199)segmentraisesFileExistsError, and thesegmentcommand of the CLI exits with an error, when the output folder has the playlist or segments of an earlier run, instead of writing over them and keeping the segments the new playlist does not have: useoverwrite=Trueor--overwriteto replace them (#164, #200)from_bufferraisesValueErrorforstrict=Truewith thesrtorsbvformat, which have no strict parsing, instead of ignoring it (#167, #203)
Changes
- Added reading binary file-like objects with
from_buffer, such as files opened in'rb'mode, with the encoding of their Byte Order Mark, kept when saving, or the newencodingargument (#143, #157) - Added setting
Caption.textto a sequence of lines, as when creating aCaption(#162, #198) - Added
WebVTTErroras the base class of the errors, and madeMalformedFileErrorandMalformedCaptionErrorsubclasses ofValueError(#146, #155) - Added
MalformedRegionError, a subclass ofMalformedCaptionError, raised for region settings that are not valid and, with strict parsing, for regions after the first cue (#168, #204) - Added the
overwriteargument ofsegmentand the--overwriteoption of the CLI, which replace the files of an earlier segmentation and delete its segments that the new playlist does not have (#164, #200) - Added the
durationargument ofsegment,slice_segmentsandwrite_manifest, and the--durationoption of the CLI, for the length of the media, so the HLS playlist covers all of it and its last segment ends with it instead of lasting the whole target duration (#165, #201) - Added segmenting a
WebVTTinstance withsegment, such as captions edited or read from another format, without saving them first, and reading the captions from standard input with-as thePATHof thesegmentcommand (#205, #209) - Added the
--versionoption of the CLI, and reading the captions from standard input with-as thePATHof theshiftandsynccommands (#169, #207) - Added running the CLI with
python -m webvtt(#210) - Fixed reading SRT files with whitespace around the first cue index, thanks to @youdie006 (#130)
- Fixed WebVTT styles ignored when
STYLEis followed by whitespace (#133) - Fixed WebVTT regions ignored after header text with
-->(#135) - Fixed reading SRT and SBV files that start with blank lines or with a cue without text, which raised
MalformedFileError(#142, #158) - Fixed non-ASCII digits read as numbers in timestamps and SRT cue indexes, thanks to @emirmrkaljevic (#140, #147)
- Fixed
from_bufferkeeping a name that is not a path as thefileto save to, such as<stdin>or the file descriptor of a file opened from one, whichsavewrote to<stdin>.vttor failed on withTypeError(#206, #208) - Fixed comparing a
Timestampwith other types raisingAttributeError:==returnsFalseand ordering comparisons raiseTypeError(#137, #150) - Fixed the SRT output not ending with a line break (#138, #151)
- Fixed SRT output of captions without text, such as text of blank lines, which were written as cues without text that are lost when read back: they are left out and the others numbered consecutively (#166, #202)
- Fixed
saveleaving out the Byte Order Mark when the encoding is written differently, such asUTF-8orutf8(#160, #196) - Fixed HLS segments repeating a cue that ends on a segment boundary, and the playlist having no segments for captions without cues, thanks to @radixun (#145, #149)
- Fixed segmenting raising
IndexErrorfor a cue that ends before it starts, which is now written to the segment it starts in (#152, #154) - Fixed the
read_bufferdeprecation warning pointing at the library instead of the code calling it (#139, #153)