From f376d1417439605392635e162326323f3282e3ad Mon Sep 17 00:00:00 2001 From: Pozitronik Date: Wed, 26 Jul 2023 00:23:19 +0400 Subject: [PATCH] fixed: case, when all frames already processed, but not resulted --- sinner/Core.py | 7 ++++--- sinner/utilities.py | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sinner/Core.py b/sinner/Core.py index d60b7470..31ca89fc 100644 --- a/sinner/Core.py +++ b/sinner/Core.py @@ -14,7 +14,7 @@ from sinner.processors.frame.BaseFrameProcessor import BaseFrameProcessor from sinner.State import State from sinner.typing import Frame -from sinner.utilities import is_image, is_video, delete_subdirectories, list_class_descendants, resolve_relative_path, get_app_dir, TEMP_DIRECTORY +from sinner.utilities import is_image, is_video, delete_subdirectories, list_class_descendants, resolve_relative_path, get_app_dir, TEMP_DIRECTORY, suggest_output_path from sinner.validators.AttributeLoader import AttributeLoader, Rules # single thread doubles cuda performance - needs to be set before torch import @@ -113,9 +113,10 @@ def run(self, set_progress: Callable[[int], None] | None = None) -> None: if self.extract_frames: temp_resources.append(state.in_dir) - if current_processor is not None: + if temp_resources is not []: + output_filename = current_processor.output_path if current_processor is not None else suggest_output_path(self.target_path) final_handler = BaseFrameHandler.create(handler_name=self.frame_handler, parameters=self.parameters, target_path=self.target_path) - if final_handler.result(from_dir=current_target_path, filename=current_processor.output_path, audio_target=self.target_path) is True: + if final_handler.result(from_dir=current_target_path, filename=output_filename, audio_target=self.target_path) is True: if self.keep_frames is False: self.update_status('Deleting temp resources') delete_subdirectories(self.temp_dir, temp_resources) diff --git a/sinner/utilities.py b/sinner/utilities.py index d882114b..eadfcc75 100644 --- a/sinner/utilities.py +++ b/sinner/utilities.py @@ -209,3 +209,12 @@ def declared_attr_type(obj: object, attribute: str) -> Any: if attribute in declared_typed_variables: return declared_typed_variables[attribute] return None + + +def suggest_output_path(target_path: str, output_path: str | None = None) -> str: + target_name, target_extension = os.path.splitext(os.path.basename(target_path)) + if output_path is None: + return os.path.join(os.path.dirname(target_path), 'result-' + target_name + target_extension) + if os.path.isdir(output_path): + return os.path.join(output_path, 'result-' + target_name + target_extension) + return output_path