Package: pressurecooker
pressurecookerA library of various media processing functions and utilitiesSetting up your environmentInstall ffmpegif you don't have it already.Install GhostScriptif you don't have it already.Install poppler-utilsif you don't have it alreadyTODOpressurecooker.youtube v2 spec: seehttps://github.com/learningequality/pressurecooker/issues/32To handle ExtractorError as permanent failure (do not try to download repeatedly)Add to  Youtube video API (support for start time)https://www.youtube.com/watch?v=GOJUNJ1o394&t=52End time complicatedhttps://www.youtube.com/embed/WA8sLsM3McU?start=15&end=20but still possiblehttps://stackoverflow.com/questions/4661905/how-to-customize-an-end-time-for-a-youtube-videoSeehttps://developers.google.com/youtube/player_parametersConverting caption filesThepressurecookerlibrary contains utilities for converting caption files from a few various
formats into the preferredVTTformat. The currently supported formats include:DFXPSAMISCCSRTTTMLWebVTT or just VTTWithinpressurecooker, the term "captions" and "subtitles" are used interchangeably. All of the
classes and functions handling conversion use the "subtitles" term.Language codesTheDFXP,SAMI, andTTMLformats can encapsulate caption contents for multiple languages within one file.
TheSCC,SRT, andVTTformats are generally limited to a single language that isn't defined in
the file (theVTTmay be an exception to this rule, but our converters do not detect its language).
Therefore when converting these files we cannot know what language we are working
with and must instead use the constantLANGUAGE_CODE_UNKNOWNto extract the converted subtitles.Note also that language codes used within the subtitle files might differ from
the LE internal language codes defined inle-utils.Creating a converter from a fileTo create a subtitle converter from a local file path, use these commands:frompressurecooker.subtitlesimportbuild_subtitle_converter_from_fileconverter=build_subtitle_converter_from_file('/path/to/file.srt')Creating a converter from a stringIf you already have the captions loaded into a string variable,
you can create the converter like so:frompressurecooker.subtitlesimportbuild_subtitle_convertercaptions_str=''# In this example, `captions_str` holds the caption contentsconverter=build_subtitle_converter(captions_str)Converting captionsFor theSCC,SRT, andVTTsubtitles format that do not contain language code info,
you must refer to the language as the constantLANGUAGE_CODE_UNKNOWNat the
time of extracting the converted subtitles:frompressurecooker.subtitlesimportbuild_subtitle_converter_from_filefrompressurecooker.subtitlesimportLANGUAGE_CODE_UNKNOWNconverter=build_subtitle_converter_from_file('/path/to/file.srt')# Option A: Obtain the contents of the converted VTT file as a stringoutput_str=converter.convert(LANGUAGE_CODE_UNKNOWN)# Option B: Write the converted subtitles to a local pathconverter.write("/path/to/file.vtt",LANGUAGE_CODE_UNKNOWN)TheLANGUAGE_CODE_UNKNOWNconstant is the internal representationpycaptionuses to denote subtitles in an unknown language code. This will be the default
and only language code forSCC,SRT, andVTTsubtitle converters.If you are unsure of the format, but you know the language of the file,
it is safer to conditionally replace theLANGUAGE_CODE_UNKNOWNwith that language:frompressurecooker.subtitlesimportbuild_subtitle_converter_from_filefrompressurecooker.subtitlesimportLANGUAGE_CODE_UNKNOWNconverter=build_subtitle_converter_from_file('/path/to/file')# Replace unknown language code if presentifconverter.has_language(LANGUAGE_CODE_UNKNOWN):converter.replace_unknown_language('en')assertconverter.has_language('en'),'Must have English after replace'output_str=converter.convert('en')An example showing how to handle the subtitle formats likeDFXP,SAMI, andTTML,
which have multiple languages is shown below:frompressurecooker.subtitlesimportbuild_subtitle_converter_from_filefrompressurecooker.subtitlesimportLANGUAGE_CODE_UNKNOWN,InvalidSubtitleLanguageErrorconverter=build_subtitle_converter_from_file('/path/to/file')forlang_codeinconverter.get_language_codes():# `some_logic` would be your decisions on whether to use this languageifsome_logic(lang_code):converter.write("/path/to/file-{}.vtt".format(lang_code),lang_code)eliflang_code==LANGUAGE_CODE_UNKNOWN:raiseInvalidSubtitleLanguageError('Unexpected unknown language')