def start_app(worker_queue, status_queue, log_queue): app = create_app() app.fastflix = FastFlix() app.fastflix.log_queue = log_queue app.fastflix.status_queue = status_queue app.fastflix.worker_queue = worker_queue app.fastflix.config = Config() init_fastflix_directories(app) init_logging(app) register_app() upgraded = app.fastflix.config.upgrade_check() if upgraded: # No translation will be possible in this case message( f"Your config file has been upgraded to FastFlix's new YAML config format\n" f"{app.fastflix.config.config_path}", title="Upgraded", ) try: app.fastflix.config.load() except MissingFF: if reusables.win_based and ask_for_ffmpeg(): try: ProgressBar(app, [Task(t("Downloading FFmpeg"), latest_ffmpeg)], signal_task=True) app.fastflix.config.load() except Exception as err: logger.exception(str(err)) sys.exit(1) except Exception: # TODO give edit / delete options logger.exception(t("Could not load config file!")) sys.exit(1) startup_tasks = [ Task(t("Gather FFmpeg version"), ffmpeg_configuration), Task(t("Gather FFmpeg audio encoders"), ffmpeg_audio_encoders), Task(t("Initialize Encoders"), init_encoders), ] try: ProgressBar(app, startup_tasks) except Exception: logger.exception(f'{t("Could not start FastFlix")}!') sys.exit(1) container = Container(app) container.show() app.exec_()
def clean_old_logs(self): try: ProgressBar(self.app, [Task(t("Clean Old Logs"), clean_logs)], signal_task=True, can_cancel=False) except Exception: error_message(t("Could not compress old logs"), traceback=True)
def select_folder(self): if self.concat_area.table.model.rowCount() > 0: if not yes_no_message( f"{t('There are already items in this list')},\n" f"{t('if you open a new directory, they will all be removed.')}\n\n" f"{t('Continue')}?", "Confirm Change Folder", ): return folder_name = QtWidgets.QFileDialog.getExistingDirectory(self, dir=self.folder_name) if not folder_name: return self.folder_name = folder_name self.set_folder_name(folder_name) def check_to_add(file, list_of_items, bad_items, **_): try: data = None details = probe(self.app, file) for stream in details.streams: if stream.codec_type == "video": data = (file.name, f"{stream.width}x{stream.height}", stream.codec_name) if not data: raise Exception() except Exception: logger.warning(f"Skipping {file.name} as it is not a video/image file") bad_items.append(file.name) else: list_of_items.append(data) items = [] skipped = [] tasks = [] for file in Path(folder_name).glob("*"): if file.is_file(): tasks.append( Task( f"Evaluating {file.name}", command=check_to_add, kwargs={"file": file, "list_of_items": items, "bad_items": skipped}, ) ) ProgressBar(self.app, tasks, can_cancel=True, auto_run=True) self.concat_area.table.update_items(items) if skipped: error_message( "".join( [ f"{t('The following items were excluded as they could not be identified as image or video files')}:\n", "\n".join(skipped[:20]), f"\n\n+ {len(skipped[20:])} {t('more')}..." if len(skipped) > 20 else "", ] ) )
def download_ffmpeg(self): ffmpeg_folder = Path(user_data_dir("FFmpeg", appauthor=False, roaming=True)) / "bin" ffmpeg = ffmpeg_folder / "ffmpeg.exe" ffprobe = ffmpeg_folder / "ffprobe.exe" try: self.pb = ProgressBar( self.app, [Task(t("Downloading FFmpeg"), latest_ffmpeg)], signal_task=True, can_cancel=True ) except FastFlixInternalException: pass except Exception as err: message(f"{t('Could not download the newest FFmpeg')}: {err}") else: if not ffmpeg.exists() or not ffprobe.exists(): message(f"{t('Could not locate the downloaded files at')} {ffmpeg_folder}!") else: self.app.fastflix.config.ffmpeg = ffmpeg self.app.fastflix.config.ffprobe = ffprobe self.pb = None
def start_app(worker_queue, status_queue, log_queue, queue_list, queue_lock): app = create_app() app.fastflix = FastFlix(queue=queue_list, queue_lock=queue_lock) app.fastflix.log_queue = log_queue app.fastflix.status_queue = status_queue app.fastflix.worker_queue = worker_queue app.fastflix.config = Config() init_fastflix_directories(app) init_logging(app) register_app() upgraded = app.fastflix.config.upgrade_check() if upgraded: # No translation will be possible in this case message( f"Your config file has been upgraded to FastFlix's new YAML config format\n" f"{app.fastflix.config.config_path}", title="Upgraded", ) try: app.fastflix.config.load() except MissingFF as err: if reusables.win_based and ask_for_ffmpeg(): try: ProgressBar(app, [Task(t("Downloading FFmpeg"), latest_ffmpeg)], signal_task=True) app.fastflix.config.load() except Exception as err: logger.exception(str(err)) sys.exit(1) else: logger.error(f"Could not find {err} location, please manually set in {app.fastflix.config.config_path}") sys.exit(1) except Exception: # TODO give edit / delete options logger.exception(t("Could not load config file!")) sys.exit(1) if app.fastflix.config.theme != "system": QtCore.QDir.addSearchPath(app.fastflix.config.theme, str(breeze_styles_path / app.fastflix.config.theme)) file = QtCore.QFile(f"{app.fastflix.config.theme}:stylesheet.qss") file.open(QtCore.QFile.OpenModeFlag.ReadOnly | QtCore.QFile.OpenModeFlag.Text) stream = QtCore.QTextStream(file) data = stream.readAll() if not reusables.win_based: data = data.replace("url(dark:", f"url({str(breeze_styles_path / 'dark')}/") data = data.replace("url(light:", f"url({str(breeze_styles_path / 'light')}/") data = data.replace("url(onyx:", f"url({str(breeze_styles_path / 'onyx')}/") app.setStyleSheet(data) logger.setLevel(app.fastflix.config.logging_level) startup_tasks = [ Task(t("Gather FFmpeg version"), ffmpeg_configuration), Task(t("Gather FFprobe version"), ffprobe_configuration), Task(t("Gather FFmpeg audio encoders"), ffmpeg_audio_encoders), Task(t("Determine OpenCL Support"), ffmpeg_opencl_support), Task(t("Initialize Encoders"), init_encoders), ] try: ProgressBar(app, startup_tasks) except Exception: logger.exception(f'{t("Could not start FastFlix")}!') sys.exit(1) container = Container(app) container.show() try: app.exec_() except Exception: logger.exception("Error while running FastFlix") raise
def start_app(worker_queue, status_queue, log_queue, queue_list, queue_lock): app = create_app() app.fastflix = FastFlix(queue=queue_list, queue_lock=queue_lock) app.fastflix.log_queue = log_queue app.fastflix.status_queue = status_queue app.fastflix.worker_queue = worker_queue app.fastflix.config = Config() init_fastflix_directories(app) init_logging(app) register_app() upgraded = app.fastflix.config.upgrade_check() if upgraded: # No translation will be possible in this case message( f"Your config file has been upgraded to FastFlix's new YAML config format\n" f"{app.fastflix.config.config_path}", title="Upgraded", ) try: app.fastflix.config.load() except MissingFF as err: if reusables.win_based and ask_for_ffmpeg(): try: ProgressBar(app, [Task(t("Downloading FFmpeg"), latest_ffmpeg)], signal_task=True) app.fastflix.config.load() except Exception as err: logger.exception(str(err)) sys.exit(1) else: logger.error( f"Could not find {err} location, please manually set in {app.fastflix.config.config_path}" ) sys.exit(1) except Exception: # TODO give edit / delete options logger.exception(t("Could not load config file!")) sys.exit(1) if app.fastflix.config.flat_ui: app.setStyleSheet(default_mode) logger.setLevel(app.fastflix.config.logging_level) startup_tasks = [ Task(t("Gather FFmpeg version"), ffmpeg_configuration), Task(t("Gather FFprobe version"), ffprobe_configuration), Task(t("Gather FFmpeg audio encoders"), ffmpeg_audio_encoders), Task(t("Initialize Encoders"), init_encoders), ] try: ProgressBar(app, startup_tasks) except Exception: logger.exception(f'{t("Could not start FastFlix")}!') sys.exit(1) container = Container(app) container.show() try: app.exec_() except Exception: logger.exception("Error while running FastFlix") raise