def choose_subtitle(self, interactive): if len(self.partitioned_streams['subtitle']) == 0: logging.warning(f"Couldn't find audio streams in input files") return if interactive and len(self.partitioned_streams['subtitle']) > 1: self.picked_streams['subtitle'] = interactive_picker( self.sources, self.partitioned_streams, 'subtitle') return k = 'subtitle' while self.picked_streams[k] is None: try: self.picked_streams[k] = next(self.pickers[k]) except StopIteration as s: logging.critical( f"Input files {self.sources} don't contain usable subtitles" ) self.insufficient = True return subfile = self.picked_streams[k].demux( overwrite_existing=self.demux_overwrite_existing) ignore_range = (self.ignore_range or []) + chapter_timestamps( self.picked_streams[k].file, self.ignore_chapters or []) if subfile is None: logging.warning( f"Error while demuxing {self.picked_streams[k]}") self.picked_streams[k] = None audiolength = subtools.get_audiofile_duration( self.picked_streams['audio'].demux_file.filepath) subdata = subtools.SubtitleManipulator(subfile.filepath, threshold=0, padding=self.padding, ignore_range=ignore_range, audio_length=audiolength) subdata.load(include_all=self.use_all_subs, regex=self.subtitle_regex_filter) if subdata.ssadata is None: logging.warning( f"Problem loading subtitle data from {self.picked_streams[k]}" ) self.picked_streams[k] = None continue self.subdata = subdata
def choose_subtitle(self, interactive: bool): if len(self.partitioned_streams['subtitle']) == 0: logging.warning(f"Couldn't find audio streams in input files") return k = 'subtitle' while True: if interactive and len(self.partitioned_streams['subtitle']) > 1: self.picked_streams['subtitle'] = interactive_picker( self.sources, self.partitioned_streams, 'subtitle') else: k = 'subtitle' try: self.picked_streams[k] = next(self.pickers[k]) except StopIteration as s: logging.critical( f"Input files {self.sources} don't contain usable subtitles" ) self.insufficient = True return subfile = self.picked_streams[k].demux( overwrite_existing=self.demux_overwrite_existing) if subfile is None: logging.warning( f"Error while demuxing {self.picked_streams[k]}") self.picked_streams[k] = None continue assert (self.picked_streams['audio'] is not None) # must call choose_audio first ignore_range = (self.ignore_range or []) + chapter_timestamps( self.picked_streams['audio'].file, self.ignore_chapters or []) audiolength = subtools.get_audiofile_duration( self.picked_streams['audio'].demux_file.filepath) subdata = subtools.SubtitleManipulator(subfile.filepath, threshold=self.threshold, padding=self.padding, ignore_range=ignore_range, audio_length=audiolength) subdata.load(include_all=self.use_all_subs, regex=self.subtitle_regex_filter, substrreplace_regex=self.subtitle_regex_substrfilter) if subdata.ssadata is None: logging.warning( f"Problem loading subtitle data from {self.picked_streams[k]}" ) self.picked_streams[k] = None continue subdata.merge_groups() times = subdata.get_times() ps_times = subtools.partition_and_split(times, self.partition, self.split) sublength = subtools.get_partitioned_and_split_times_duration( ps_times) compression_ratio = sublength / audiolength if compression_ratio < self.minimum_compression_ratio: if interactive: resp = input( f"Got compression ratio of {compression_ratio} (ratio of dialogue to total audio), " f"which is smaller than the minimum" f" ratio of {self.minimum_compression_ratio}. Continue with picked subtitles? (y/N)" ) if resp != 'y': continue else: logging.warning( f"Got compression ratio of {compression_ratio}, which is smaller than the minimum" f" ratio of {self.minimum_compression_ratio}" f"retrying wth different subtitle " f"file. If too many subtitles are being ignored, try -ni or -R. If the minimum " f"ratio is too high, try -c.") self.picked_streams[k] = None continue self.subdata = subdata self.dialogue_times = subtools.partition_and_split( sub_times=times, partition_size=1000 * self.partition, split_size=1000 * self.split) break
def choose_streams_old(self): if insufficient_source_streams(self.partitioned_streams): logging.error( f"Not enough input sources to generate condensed output for output stem {self.outstem}" ) self.insufficient = True return while picked_sources_are_insufficient(self.picked_streams): for k in ['audio', 'video', 'subtitle']: if len(self.partitioned_streams[k]) == 0: logging.debug(f"no input streams of type {k}") continue if self.picked_streams[k] is None: try: self.picked_streams[k] = next(self.pickers[k]) except StopIteration as s: logging.critical( "Input streams for this input group are invalid for condensing " "(missing audio or subtitles)") self.insufficient = True return for k in ['audio', 'subtitle', 'video']: # validate picked streams if k == 'audio': afile = self.picked_streams[k].demux( overwrite_existing=self.demux_overwrite_existing) if afile is None: self.picked_streams[k] = None # todo: maybe move this back into Condense, split/threshold is a cia thing, not a srs thing, # or have seperate functions for video, audio, and subtitles if k == 'subtitle': subfile = self.picked_streams[k].demux( overwrite_existing=self.demux_overwrite_existing ) # type AVSFile if subfile is None: self.picked_streams[k] = None continue # times = subtools.load_subtitle_times(subfile.filepath, include_all_lines=self.use_all_subs) audiolength = subtools.get_audiofile_duration( self.picked_streams['audio'].demux_file.filepath) subdata = subtools.SubtitleManipulator( subfile.filepath, threshold=self.threshold, padding=self.padding, ignore_range=self.ignore_range, audio_length=audiolength) subdata.load(include_all=self.use_all_subs, regex=self.subtitle_regex_filter) if subdata.ssadata is None: self.picked_streams[k] = None continue if self.picked_streams['audio'] is None: # can't verify subtitle validity until audio candidate is found continue # times = subtools.merge_times(times, threshold=self.threshold, padding=self.padding) subdata.merge_groups() times = subdata.get_times() ps_times = subtools.partition_and_split( times, self.partition, self.split) sublength = subtools.get_partitioned_and_split_times_duration( ps_times) compression_ratio = sublength / audiolength if compression_ratio < self.minimum_compression_ratio: logging.info( f"got compression ratio of {compression_ratio}, which is smaller than the minimum" f" ratio of {self.minimum_compression_ratio}, retrying wth different subtitle " f"file. If too many subtitles are being ignored, try -ni or -R. If the minimum " f"ratio is too high, try -c.") self.picked_streams[k] = None continue self.dialogue_times = subtools.partition_and_split( sub_times=times, partition_size=1000 * self.partition, split_size=1000 * self.split) if k == 'video': pass logging.info( f"Picked {self.picked_streams['audio']} to use for condensing") logging.info( f"Picked {self.picked_streams['video']} to use for condensing") logging.info( f"Picked {self.picked_streams['subtitle']} to use for condensing")