Beispiel #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()
    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))
Beispiel #3
0
    def press_upscale_button(self):

        self.ui.upscale_status_label.setFont(
            QtGui.QFont("Yu Gothic UI Semibold", 11, QtGui.QFont.Bold))
        self.ui.upscale_status_label.setText("Upscaling in Progress")

        self.parse_gui_inputs()

        config = configparser.ConfigParser()
        config.read('gui_config.ini')
        config.set("dandere2x", "workspace", self.workspace_dir)
        config.set("dandere2x", "file_dir", self.file_dir)
        config.set("dandere2x", "block_size", self.block_size)
        config.set("dandere2x", "quality_low", self.image_quality)
        config.set("dandere2x", "waifu2x_type", self.waifu2x_type)
        config.set("dandere2x", "scale_factor", self.scale_factor)

        print("workspace = " + self.workspace_dir)
        print("file_dir = " + self.file_dir)
        print("block_size = " + self.block_size)
        print("quality_low = " + self.image_quality)
        print("waifu2x_type = " + self.waifu2x_type)

        d = Dandere2x(config)
        #   d.run_concurrent()

        try:
            d.run_concurrent()
        except:
            print("Oops!", sys.exc_info()[0], "occured.")
            self.ui.upscale_status_label.setFont(
                QtGui.QFont("Yu Gothic UI Semibold", 11, QtGui.QFont.Bold))
            self.ui.upscale_status_label.setText("Upscale Failed. See log")
Beispiel #4
0
def cli_start():
    args = Dandere2xServiceRequest.get_args_parser(
    )  # Get the parser specific to dandere2x
    root_service_request = Dandere2xServiceRequest.load_from_args(args=args)
    root_service_request.log_all_variables()
    root_service_request.make_workspace()

    dandere2x_session = Dandere2x(service_request=root_service_request)
    dandere2x_session.start()
    dandere2x_session.join()
Beispiel #5
0
    def run(self):
        from dandere2x import Dandere2x
        self._pre_process()

        for sub_service in self.service_request_list:
            print("Processing %s" % sub_service.input_file)

            sub_service.make_workspace()
            instance = Dandere2x(service_request=sub_service)
            instance.start()
            instance.join()

            print("%s completed" % sub_service.input_file)

        self._on_completion()
    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()
Beispiel #7
0
def debug_start():
    """
    Debug function meant for dandere2x development. Starts dandere2x with minimal exterior function calls and
    will only work based off what's in the yaml.
    """
    # 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)

    # load the context with yaml stuff
    context = Context(config)

    # continue d2x
    d2x = Dandere2x(context)
    d2x.run_concurrent()
def main():

    start = time.time()

    # 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)

    # load the context with yaml stuff
    context = Context(config)

    # continue d2x
    d2x = Dandere2x(context)
    d2x.run_concurrent()

    print("\n Total runtime duration:", time.time() - start)
Beispiel #9
0
                    help="Output directory and workspace.")

parser.add_argument("-b",
                    "--block_size",
                    type=int,
                    nargs=1,
                    metavar="block_size",
                    default=None,
                    help="Block size for Dandere2x to work with")

parser.add_argument(
    "-q",
    "--quality_low",
    type=int,
    nargs=1,
    metavar="quality integer",
    default=None,
    help="Lowest quality to accept a block, relative to JPG standards")

args = parser.parse_args()

print(args.quality_low)

d = Dandere2x('config.ini')

d.context.file_dir = args.input
d.context.workspace = args.output

print(args.quality_low)

#d.run_concurrent()
Beispiel #10
0
    def __init__(self, parent, config_yaml):
        super(QtDandere2xThread, self).__init__(parent)

        context = Context(config_yaml)
        self.dandere2x = Dandere2x(context)
Beispiel #11
0
try:
    with open(dandere2x_config_file, "r") as read_file:
        config = yaml.safe_load(read_file)
        print("File read!")
except:
    print("Couldn't open %s, exiting" % dandere2x_config_file)
    exit(1)

print(" > Attempting to load context / dandere2x with this file...")

import logging
dandere2x = None

try:
    context = Context(config)
    dandere2x = Dandere2x(context=context)
except:
    print("Loading %s failed!" % dandere2x_config_file)

log = logging.getLogger()
log.info("Hellllllooo ok *taps mic* is this thing on")
log.warning("*cough* *cough* this is a warning message")
log.error("BOO ERROR im an error")
log.info("Haha gotcha")

time.sleep(0.1)
print("----------------------------------------------------")

log.info(
    "Ok first things first I'm going to make sure your workspace exists, the one found in %s"
    % dandere2x_config_file)
Beispiel #12
0
import json
import time

from context import Context
from dandere2x import Dandere2x

start = time.time()

with open("dandere2x.json", "r") as read_file:
    config_json = json.load(read_file)

context = Context(config_json)

d = Dandere2x(context)
d.run_concurrent()

end = time.time()

print("\n duration: " + str(time.time() - start))
Beispiel #13
0
    if not args["block_size"] == None:
        user_modified.append("block_size=\"%s\"" % args["block_size"])
        config["block_matching"]["block_size"] = args["block_size"]

    if not args["denoise_level"] == None:
        user_modified.append("denoise_level=\"%s\"" % args["denoise_level"])
        config["upscaler"]["denoise_level"] = args["denoise_level"]

    if not args["tile_size"] == None:
        user_modified.append("tile_size=\"%s\"" % args["tile_size"])
        config["upscaler"]["tile_size"] = args["tile_size"]

    if not args["debug_video"] == False:
        user_modified.append("debug_video=\"%s\"" % args["debug_video"])
        config["debug"]["write_debug_video"] = args["debug_video"]

    print("[DEBUG] ENTERED ARGS, PLEASE CHECK: ", args)

    # Run Dandere2x
    d2x = Dandere2x(config)
    d2x.load()
    d2x.setup()

    try:
        d2x.run()
    except KeyboardInterrupt:
        print("KeyboardInterrupt catched, saving and exiting..")
        d2x.controller.exit()
        d2x.context.resume = True
        d2x.context.save_vars()
Beispiel #14
0
    def __init__(self, parent, service_request: Dandere2xServiceRequest):
        super(QtDandere2xThread, self).__init__(parent)

        self.service_request = service_request
        self.dandere2x = Dandere2x(service_request)
Beispiel #15
0
 def load_and_configure(self, config):
     self.config = config
     self.dandere2x = Dandere2x(self.config)