コード例 #1
0
def cli_start(args):
    """
    Start Dandere2x using command line

    :param args: args loaded from load_parser()
    :return: none
    """

    # get config based on OS
    configfile = "dandere2x_%s.yaml" % get_operating_system()

    # load yaml

    with open(configfile, "r") as read_file:
        config = yaml.safe_load(read_file)

    config['dandere2x']['usersettings']['output_file'] = args.output_file
    config['dandere2x']['usersettings']['input_file'] = args.input_file

    config['dandere2x']['usersettings']['block_size'] = args.block_size
    config['dandere2x']['usersettings']['quality_minimum'] = args.image_quality
    config['dandere2x']['usersettings']['waifu2x_type'] = args.waifu2x_type
    config['dandere2x']['usersettings']['scale_factor'] = args.scale_factor
    config['dandere2x']['usersettings']['denoise_level'] = args.noise_level

    print("arg input file: " + args.input_file)
    if os.path.isdir(args.input_file):
        print("is not dir")
        if not os.path.isdir(args.output_file):
            print(
                "input is type 'directory' but output is not type 'directory'. Dandere2x exiting"
            )
            sys.exit(1)
        config['dandere2x']['usersettings']['input_folder'] = args.input_file
        config['dandere2x']['usersettings']['output_folder'] = args.output_file

        d2x = Dandere2xUpscaleFolder(config)
        d2x.start()

    else:
        context = Context(config)

        if dir_exists(context.workspace):
            print("Deleted Folder")

            # This is a recurring bug that seems to be popping up on other people's operating systems.
            # I'm unsure if this will fix it, but it could provide a solution for people who can't even get d2x to work.
            try:
                shutil.rmtree(context.workspace)
            except PermissionError:
                print(
                    "Trying to delete workspace via RM tree threw PermissionError - Dandere2x may not work."
                )

            while (file_exists(context.workspace)):
                time.sleep(1)

        d2x = Dandere2x(context)
        d2x.start()
        d2x.join()
コード例 #2
0
    def run(self):

        if dir_exists(self.dandere2x.context.workspace):
            print("Deleted Folder")

            # This is a recurring bug that seems to be popping up on other people's operating systems.
            # I'm unsure if this will fix it, but it could provide a solution for people who can't even get d2x to work.
            try:
                shutil.rmtree(self.dandere2x.context.workspace)
            except PermissionError:
                print(
                    "Trying to delete workspace via RM tree threw PermissionError - Dandere2x may not work."
                )

            while (file_exists(self.dandere2x.context.workspace)):
                time.sleep(1)

        try:
            self.dandere2x.start()

        except:
            print("dandere2x failed to work correctly")
            sys.exit(1)

        self.join()
コード例 #3
0
    def start(self):
        print(self.context.workspace)

        if dir_exists(self.context.workspace):
            print("Deleted Folder")
            shutil.rmtree(self.context.workspace)

        wait_on_delete_dir(self.context.workspace)
        try:
            os.mkdir(self.context.workspace)
        except OSError:
            print("Creation of directory failed")

        start = time.time()

        # starting shit
        print("Starting Dandere2x")
        d = Dandere2x(self.context)
        d.run_concurrent()
        d.context.close_logger()

        if d.context.config_json['dandere2x']['developer_settings'][
                'gui_delete_workspace_after']:
            d.delete_workspace_files()

        print("Dandere2x GUI Run Finished Successfully")

        end = time.time()

        print("\n " "duration: " + str(time.time() - start))
コード例 #4
0
    def start(self):

        files_in_folder = []

        for file in glob.glob(os.path.join(self.input_folder, "*")):
            files_in_folder.append(os.path.basename(file))

        for x in range(len(files_in_folder)):
            # Cycle through each file

            iteration_yaml = copy.copy(self.config_yaml)

            file_name = os.path.join(self.input_folder, files_in_folder[x])

            path, name = os.path.split(files_in_folder[x])
            name_only = name.split(".")[0]

            # Set the output name to be 'upscaled + original name'
            output_name = os.path.join(self.output_folder,
                                       "upscaled_" + name_only + ".mp4")

            # change the yaml to contain the data for this iteration of dandere2x
            iteration_yaml['dandere2x']['usersettings'][
                'input_file'] = file_name
            iteration_yaml['dandere2x']['usersettings'][
                'output_file'] = output_name
            iteration_yaml['dandere2x']['developer_settings'][
                'workspace'] = self.workspace + str(x) + os.path.sep

            context = Context(iteration_yaml)

            # Delete the workspace if it already exists to prevent bugs
            if dir_exists(context.workspace):
                print("Deleted Folder")

                try:
                    shutil.rmtree(context.workspace)
                except PermissionError:
                    print(
                        "Trying to delete workspace via RM tree threw PermissionError - Dandere2x may not work."
                    )

                while (file_exists(context.workspace)):
                    time.sleep(1)

            d2x = Dandere2x(context)
            d2x.start()
            d2x.join()