From 5e840ae8bb1d5f4e3ff71f41dfb653a9ac039935 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 18 Oct 2023 10:28:24 -0600 Subject: [PATCH] Support cancelling --- main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index f949256..ce77271 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import glob import os import hashlib +import time from PIL import Image, UnidentifiedImageError from imagehash import average_hash @@ -20,8 +21,8 @@ except KeyboardInterrupt: print('\nCancelled.') os._exit(0) -print('Sorting file list by size...') -filenames.sort(key=os.path.getsize, reverse=True) +print('Sorting file list by smallest size...') +filenames.sort(key=os.path.getsize, reverse=False) print('Deduplicating by md5 hash...') @@ -66,12 +67,17 @@ for filename in filenames: try: digest = get_image_hash(filename) or get_video_hash(filename) + except KeyboardInterrupt: + print('\nCancelled.') + os._exit(0) except BaseException as e: print() print('Exception', e.__class__.__name__, str(e), 'while hashing:') print(filename) continue + time.sleep(5) + if not digest: continue if digest in hashes: