def start_command():
     nonlocal currently_encoding
     log_queue.put(
         f"CLEAR_WINDOW:{video.uuid}:{video.video_settings.conversion_commands[video.status.current_command].uuid}"
     )
     reusables.remove_file_handlers(logger)
     new_file_handler = reusables.get_file_handler(
         log_path / sanitize_filename(
             f"flix_conversion_{video.video_settings.video_title or video.video_settings.output_path.stem}_{file_date()}.log"
         ),
         level=logging.DEBUG,
         log_format="%(asctime)s - %(message)s",
         encoding="utf-8",
     )
     logger.addHandler(new_file_handler)
     prevent_sleep_mode()
     currently_encoding = True
     runner.start_exec(
         video.video_settings.conversion_commands[
             video.status.current_command].command,
         work_dir=str(video.work_path),
     )
     set_status(video,
                queue_list=queue_list,
                queue_lock=queue_lock,
                running=True)
     status_queue.put(("queue", ))
Beispiel #2
0
def init_logging(app: FastFlixApp):
    stream_handler = reusables.get_stream_handler(level=logging.DEBUG)
    file_handler = reusables.get_file_handler(
        app.fastflix.log_path / f"flix_gui_{file_date()}.log",
        level=logging.DEBUG,
        encoding="utf-8",
    )
    logger.setLevel(logging.DEBUG)
    logger.addHandler(stream_handler)
    logger.addHandler(file_handler)
    coloredlogs.install(level="DEBUG", logger=logger)
Beispiel #3
0
 def start_command():
     nonlocal currently_encoding
     log_queue.put(f"CLEAR_WINDOW:{video_uuid}:{command_uuid}")
     reusables.remove_file_handlers(logger)
     new_file_handler = reusables.get_file_handler(
         log_path /
         sanitize_filename(f"flix_conversion_{log_name}_{file_date()}.log"),
         level=logging.DEBUG,
         log_format="%(asctime)s - %(message)s",
         encoding="utf-8",
     )
     logger.addHandler(new_file_handler)
     currently_encoding = True
     runner.start_exec(
         command,
         work_dir=work_dir,
     )
Beispiel #4
0
 def start_command():
     nonlocal currently_encoding
     log_queue.put(
         f"CLEAR_WINDOW:{commands_to_run[0][0]}:{commands_to_run[0][1]}")
     reusables.remove_file_handlers(logger)
     new_file_handler = reusables.get_file_handler(
         log_path /
         f"flix_conversion_{commands_to_run[0][4]}_{file_date()}.log",
         level=logging.DEBUG,
         log_format="%(asctime)s - %(message)s",
         encoding="utf-8",
     )
     logger.addHandler(new_file_handler)
     prevent_sleep_mode()
     currently_encoding = True
     status_queue.put(
         ("running", commands_to_run[0][0], commands_to_run[0][1]))
     runner.start_exec(
         commands_to_run[0][2],
         work_dir=commands_to_run[0][3],
     )
Beispiel #5
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    data_path = Path(user_data_dir("FastFlix", appauthor=False, roaming=True))
    data_path.mkdir(parents=True, exist_ok=True)
    log_dir = data_path / "logs"
    log_dir.mkdir(parents=True, exist_ok=True)

    queue = Queue()
    status_queue = Queue()
    log_queue = Queue()

    def log(msg, level=logging.INFO):
        log_queue.put(msg)
        logger.log(level, msg)

    runner = BackgroundRunner(log_queue=log_queue)
    gui_proc = Process(target=start_app,
                       args=(queue, status_queue, log_queue, data_path,
                             log_dir))
    gui_proc.start()
    logger = logging.getLogger("fastflix-core")
    coloredlogs.install(level="DEBUG", logger=logger)
    logger.info(f"Starting FastFlix {__version__}")

    for leftover in Path(data_path).glob(f"encoder_output_*.log"):
        try:
            leftover.unlink()
        except OSError:
            pass

    sent_response = True
    gui_close_message = False
    queued_requests = []
    while True:
        if not gui_close_message and not gui_proc.is_alive():
            gui_proc.join()
            gui_close_message = True
            if runner.is_alive() or queued_requests:
                log(
                    "The GUI might have died, but I'm going to keep converting!",
                    logging.WARNING)
            else:
                break
        try:
            request = queue.get(block=True, timeout=0.01)
        except Empty:
            if not runner.is_alive(
            ) and not sent_response and not queued_requests:
                ret = runner.process.poll()
                if ret > 0:
                    log(f"Error during conversion", logging.WARNING)
                else:
                    log("conversion complete")
                reusables.remove_file_handlers(logger)
                status_queue.put("complete")
                sent_response = True

                if not gui_proc.is_alive():
                    return
        except KeyboardInterrupt:
            status_queue.put("exit")
            return
        else:
            if request[0] == "command":
                if runner.is_alive():
                    queued_requests.append(request)
                else:
                    log_queue.put("CLEAR_WINDOW")
                    reusables.remove_file_handlers(logger)
                    new_file_handler = reusables.get_file_handler(
                        log_dir / f"flix_conversion_{file_date()}.log",
                        level=logging.DEBUG,
                        log_format="%(asctime)s - %(message)s",
                        encoding="utf-8",
                    )
                    logger.addHandler(new_file_handler)
                    runner.start_exec(*request[1:])
                    sent_response = False
            if request[0] == "cancel":
                queued_requests = []
                runner.kill()
                status_queue.put("cancelled")
                sent_response = True
        if not runner.is_alive():
            if queued_requests:
                runner.start_exec(*queued_requests.pop()[1:])
                sent_response = False