remove convert functionality from extract script

This commit is contained in:
Hendrik Schutter 2023-12-25 21:11:38 +01:00
parent 8c856dfad5
commit 2d7e380476

View File

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