def _load_audio_source(log_api: LogApi, uid: uuid.UUID, path: Path) -> Optional[ffms2.AudioSource]: """Create FFMS audio source. :param log_api: logging API :param uid: uid of the stream (for logging) :param path: path to the audio file :return: resulting FFMS audio source or None if failed to create """ log_api.info(f"audio {uid} started loading ({path})") if not path.exists(): log_api.error(f"error loading audio {uid} (file {path} not found)") return None try: indexer = ffms2.Indexer(str(path)) for track in indexer.track_info_list: indexer.track_index_settings(track.num, 1, 0) index = indexer.do_indexing2() except ffms2.Error as ex: log_api.error(f"error loading audio {uid} ({ex})") return None try: track_number = index.get_first_indexed_track_of_type( ffms2.FFMS_TYPE_AUDIO) source = ffms2.AudioSource(str(path), track_number, index) except ffms2.Error as ex: log_api.error(f"error loading audio {uid} ({ex})") return None else: log_api.info(f"audio {uid} finished loading") return source
def __init__(self, args: argparse.Namespace) -> None: """Initialize self. :param args: CLI arguments """ self.args = args self.cfg = Config() self.log = LogApi(self.cfg) self.subs = SubtitlesApi(self.cfg) self.undo = UndoApi(self.cfg, self.subs) self.threading = ThreadingApi(self.log) self.video = VideoApi(self.threading, self.log, self.subs) self.audio = AudioApi(self.threading, self.log) self.playback = PlaybackApi(self.log, self.subs, self.video, self.audio) self.audio.view = AudioViewApi(self.subs, self.audio, self.video) self.video.view = VideoViewApi(self.subs) self.gui = GuiApi(self) self.cmd = bubblesub.api.cmd.CommandApi(self) self.gui.terminated.connect(self.audio.unload_all_streams) self.gui.terminated.connect(self.video.unload_all_streams) self.gui.terminated.connect(self.cmd.unload) self.subs.loaded.connect(self._on_subs_load)
def _on_menu_about_to_show(log_api: LogApi, menu: QMenu) -> None: window = _window_from_menu(menu) window.setProperty("focused-widget", window.focusWidget()) for action in menu.actions(): if getattr(action, "commands", None): enabled = False with log_api.exception_guard(): enabled = all(cmd.is_enabled for cmd in action.commands) action.setEnabled(enabled)
def _load_video_source(log_api: LogApi, uid: uuid.UUID, path: Path) -> T.Optional[ffms2.VideoSource]: """Create video source. :param log_api: logging API :param uid: uid of the stream (for logging) :param path: path to the video file :return: input path and resulting video source """ log_api.info(f"video {uid} started loading ({path})") if not path.exists(): log_api.error(f"error loading video {uid} (file {path} not found)") return None try: source = ffms2.VideoSource(str(path)) except ffms2.Error as ex: log_api.error(f"error loading video {uid} ({ex})") return None else: log_api.info(f"video {uid} finished loading") return source