From 2d7e38047685dead423e56e2f4ce05412d2e1d14 Mon Sep 17 00:00:00 2001 From: localhorst Date: Mon, 25 Dec 2023 21:11:38 +0100 Subject: [PATCH] remove convert functionality from extract script --- extract_photos.py | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/extract_photos.py b/extract_photos.py index 01b6f08..8cc53a8 100644 --- a/extract_photos.py +++ b/extract_photos.py @@ -13,32 +13,6 @@ number_of_photos_in_scan = 4 crop_height = 4.0 # offset in percent crop_width = 4.0 # offset in percent -def convert_to_avif(input_dir, output_dir): - # print("input: " + str(input)) - # print("output: " + str(output)) - - for path in os.listdir(input_dir): - if os.path.isfile(os.path.join(input_dir, path)): - input = os.path.join(input_dir, path) - output = os.path.join(output_dir,(os.path.splitext(os.path.basename(os.path.normpath(input)))[0] + ".avif")) - #print("Found extracted photo: " + str(input)) - #print("Convert to: " + str(output)) - - cmd_handle = subprocess.Popen(["avifenc", "--jobs", "all", input, output], stdout=subprocess.PIPE) - cmd_handle.communicate()[0] - - if cmd_handle.returncode != 0: - raise Exception("Unable to convert via avifenc! Return code: " + str(cmd_handle.returncode)) - - if os.path.exists(input): - os.remove(input) - - cmd_handle = subprocess.Popen(["sync",],stdout=subprocess.PIPE,) - cmd_handle.communicate()[0] - - if cmd_handle.returncode != 0: - raise Exception("Unable to sync! Return code: " + str(cmd_handle.returncode)) - def auto_crop_scan(src_path, output_dir): areas = list() areas.clear() @@ -111,21 +85,18 @@ def main(): destination_dir_path = -1 source_dir_path = -1 - tmp_dir_path = -1 for argument in sys.argv: if argument.startswith("destination_dir"): destination_dir_path = argument.split("=")[1] if argument.startswith("source_dir"): source_dir_path = argument.split("=")[1] - if argument.startswith("tmp_dir"): - tmp_dir_path = argument.split("=")[1] - if (destination_dir_path == -1) or (source_dir_path == -1) or (tmp_dir_path == -1): + if (destination_dir_path == -1) or (source_dir_path == -1): print("Unable to parse config!") print("Example usage:") print( - " python extract_photos.py source_dir=scans/ destination_dir=photos/ tmp_dir=tmp/" + " python extract_photos.py source_dir=scans/ destination_dir=photos/" ) sys.exit(-1) @@ -136,8 +107,7 @@ def main(): print("Found scan: " + str(os.path.join(source_dir_path, path)), end=" ") sys.stdout.flush() try: - auto_crop_scan(os.path.join(source_dir_path, path), tmp_dir_path) - convert_to_avif(tmp_dir_path, destination_dir_path) + auto_crop_scan(os.path.join(source_dir_path, path), destination_dir_path) print(" → Successfully extracted photos from scan") except Exception as e: print(str(e))