def segment(self, webvtt, output='', seconds=SECONDS, mpegts=MPEGTS):
        """Segments the captions based on a number of seconds."""
        if isinstance(webvtt, str):
            # if a string is supplied we parse the file
            captions = WebVTT().read(webvtt).captions
        elif not self._validate_webvtt(webvtt):
            raise InvalidCaptionsError('The captions provided are invalid')
        else:
            # we expect to have a webvtt object
            captions = webvtt.captions

        self._total_segments = 0 if not captions else int(ceil(captions[-1].end_in_seconds / seconds))
        self._output_folder = output
        self._seconds = seconds
        self._mpegts = mpegts

        output_folder = os.path.join(os.getcwd(), output)
        if not os.path.exists(output_folder):
            os.makedirs(output_folder)

        self._slice_segments(captions)
        self._write_segments()
        self._write_manifest()
def segment ( self , webvtt , output = '' , seconds = SECONDS , mpegts = MPEGTS ) : if isinstance ( webvtt , str ) : captions = WebVTT ( ) . read ( webvtt ) . captions elif not self . _validate_webvtt ( webvtt ) : raise InvalidCaptionsError ( 'The captions provided are invalid' ) else : captions = webvtt . captions self . _total_segments = 0 if not captions else int ( ceil ( captions [ - 1 ] . end_in_seconds / seconds ) ) self . _output_folder = output self . _seconds = seconds self . _mpegts = mpegts output_folder = os . path . join ( os . getcwd ( ) , output ) if not os . path . exists ( output_folder ) : os . makedirs ( output_folder ) self . _slice_segments ( captions ) self . _write_segments ( ) self . _write_manifest ( )
Segments the captions based on a number of seconds.