Support cancelling
This commit is contained in:
parent
80fd7f844b
commit
5e840ae8bb
10
main.py
10
main.py
|
@ -1,6 +1,7 @@
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import time
|
||||||
from PIL import Image, UnidentifiedImageError
|
from PIL import Image, UnidentifiedImageError
|
||||||
|
|
||||||
from imagehash import average_hash
|
from imagehash import average_hash
|
||||||
|
@ -20,8 +21,8 @@ except KeyboardInterrupt:
|
||||||
print('\nCancelled.')
|
print('\nCancelled.')
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
print('Sorting file list by size...')
|
print('Sorting file list by smallest size...')
|
||||||
filenames.sort(key=os.path.getsize, reverse=True)
|
filenames.sort(key=os.path.getsize, reverse=False)
|
||||||
|
|
||||||
print('Deduplicating by md5 hash...')
|
print('Deduplicating by md5 hash...')
|
||||||
|
|
||||||
|
@ -66,12 +67,17 @@ for filename in filenames:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
digest = get_image_hash(filename) or get_video_hash(filename)
|
digest = get_image_hash(filename) or get_video_hash(filename)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('\nCancelled.')
|
||||||
|
os._exit(0)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
print()
|
print()
|
||||||
print('Exception', e.__class__.__name__, str(e), 'while hashing:')
|
print('Exception', e.__class__.__name__, str(e), 'while hashing:')
|
||||||
print(filename)
|
print(filename)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
if not digest: continue
|
if not digest: continue
|
||||||
|
|
||||||
if digest in hashes:
|
if digest in hashes:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user