Package: pycaptions
PyCaptionsPyCaptions is a caption reading/writing library.WhyLGPL-3.0?This is just to ensure that source code for the library is always under the same licence and cannot be closed-sourced. All the conditions for this licence only apply for the the library itself and it's modifications. We reccomend to just contribute to the project if you are making modifications, unless they are drastic and specific to your case.Table of ContentsInstallationSupported FormatsPlansExamplesChangelogRead theWikiInstallationPIPpip install --upgrade pycaptionsSourcegit clone https://github.com/adfreelife/PyCaptions.git
cd PyCaptions
python setup.py installSupported FormatsSubRip (SRT)(reader + writer)MicroDVD (SUB)(reader + writer)Timed Text Markup Language (TTML, DFXP, XML)(reader* + writer*)Web Video Text Tracks Format (VTT)(reader + writer*)*Limited functionalityFuture plansadd writers to all supported formatsauto-fit lines into multilines or split captions blocks into two partsadd support for more formatsSynchronized Accessible Media Interchange (SAMI)Universal Subtitle Format (USF)LyRiCs (LRC)open an issue with "enhancement" label for moreExamplesGeneric from file namefrompycaptionsimportCaptionswithCaptions("tests/test.en.srt")ascaptions:captions.saveVTT("test")Generic from file streamwithopen("tests/test.en.srt",encoding="UTF-8")asf:captions=Captions(f)# or captions = Captions()# captions.read(f)captions.saveVTT("test")Generic from stringsrt="""100:00:00,500 --> 00:00:02,000This is a test file"""captions=Captions(srt)# or captions = Captions()# captions.detect(srt)captions.saveVTT("test")Specific readerHave the same functions as generic, exceptfrompycaptionsimportSubRip,detectSRTwithopen("tests/test.en.srt",encoding="UTF-8")asf:ifdetectSRT(f):# or SubRip.detect(f)captions=SubRip().read(f)captions.saveVTT("test")MultilingualfrompycaptionsimportCaptions# if the format supports multiple languageswithCaptions("tests/test.ttml")ascaptions:# first line will be in english, second one in spanishcaptions.saveSRT("test",["en","es"]lines=1)# recomended to specify lines=1# if you have multiple files and you want to make multilingual onewithCaptions("tests/test.en.srt")ascaptions:withCaptions("tests/test.es.srt")ascaptions2:# only subtitle text and comments (if format supports them) are addedcaptions+=captions2# first line will be in english, second one in spanishcaptions.save("test",["en","es"],lines=1)# recomended to specify lines=1Combine fileswithCaptions("tests/test.en.srt")ascaptions:captions.joinFile("tests/test.en.srt",add_end_time=True)captions.save("test")Changelogv0.7.0Release date: 2024-02-06Changes:Added cli support(e.gpycaptions "path/to/file/file.srt" -f vtt)Added autoformat for all values oflinesAdded functionCaptionsFormat.getLanguagesAndFilenameAdded functionCaptionsFormat.getFilenameAddedMicroTime.fromMicrotimecreates a MicroTime from a listAddedMicroTime.toMicrotimereturns a MicroTime as a listAddedMicroTime.fromAnyFormatreturns a MicroTime from provided format (case insensitive)MicroTime.fromSUBTimeandMicroTime.toSUBTimenow supports framerate as stringCaptions.saveoutput_format is now case insensitiveImproved MicroDVD style conversionInternal restructure for faster developmentInvalidstyleargument will result instyle=NoneAddedstyle_optionsfor changing style globaly, defaultstyle="full"lines=-1, this affects how the style is parsed. (e.g.style_options.style=Noneand then using argumentstyle="full"will not convert any style due to optimizations for faster conversion)Hypens at the end of the lines (e.g "Some-thing") will be removed iflinesis >-1Stylingis now split intoStyleFormatandStyling(StyleFormat)Fixes:Fixed "lxml is not installed" errorFixedStyling.getTTMLconverting invalid css properties into ttml properties. To-do: add value checks for these properties.FixedCaptionsFormat.getLanguagesFromFilenamegetting languages from directory path (e.g.\path.to.file\file.en.srt->["to", "en"])Fixed width and height not being saved to jsonRead past changeshere.