def from_model(doc: model.ContentDocument, isd_config: Optional[ISDConfiguration] = None, progress_callback=lambda _: None) -> str: """Converts the data model to a SRT document""" srt = SrtContext() # split progress between ISD construction and SRT writing def _isd_progress(progress: float): progress_callback(progress / 2) # Compute ISDs isds = ISD.generate_isd_sequence(doc, _isd_progress, is_multithreaded=isd_config.multi_thread if isd_config is not None else True) # process ISDs for i, (offset, isd) in enumerate(isds): for srt_filter in srt.filters: srt_filter.process(isd) srt.add_isd(isd, offset) progress_callback(0.5 + (i + 1) / len(isds) / 2) srt.finish() return str(srt)
def from_model(doc: model.ContentDocument, config = None, progress_callback=lambda _: None) -> str: """Converts the data model to a VTT document""" # split progress between ISD construction and VTT writing def _isd_progress(progress: float): progress_callback(progress / 2) # create context vtt = VttContext(config if config is not None else VTTWriterConfiguration()) # Compute ISDs isds = ISD.generate_isd_sequence(doc, _isd_progress) # process ISDs for i, (begin, isd) in enumerate(isds): end = isds[i + 1][0] if i + 1 < len(isds) else None vtt.add_isd(isd, begin, end) progress_callback(0.5 + (i + 1) / len(isds) / 2) vtt.finish() return str(vtt)