diff options
author | Timmy Keller <tjk@tjkeller.xyz> | 2021-10-26 02:25:17 -0500 |
---|---|---|
committer | Timmy Keller <tjk@tjkeller.xyz> | 2021-10-26 02:25:17 -0500 |
commit | d75d53fe79ee7cf0d2efd30d5e191def8c746056 (patch) | |
tree | 1eb44a422da9c32022f61e01f7b2f215adee37d5 /video/rmduppic | |
parent | 6b0cb35fd2383caff09c46996087ddd9b28f9d0a (diff) | |
download | scripts-d75d53fe79ee7cf0d2efd30d5e191def8c746056.tar.xz scripts-d75d53fe79ee7cf0d2efd30d5e191def8c746056.zip |
changed a bunch of video scripts and added my first and possibly last python script, although it was fun
Diffstat (limited to 'video/rmduppic')
-rwxr-xr-x | video/rmduppic | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/video/rmduppic b/video/rmduppic new file mode 100755 index 0000000..6fdc18d --- /dev/null +++ b/video/rmduppic @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import os +import subprocess + +def sizeinbytes(size, unit): + mag = {'KiB' : 1, 'MiB': 2, 'GiB' : 3} + return float(size) * (1000 ** mag[unit]) + +# Run czkawka_cli on the current directory +cwd = os.getcwd() +print("Running czkawa for directory ", cwd, "...", sep="") +czkawka = ["czkawka_cli", "image", "-d", cwd] +czkawkadata = subprocess.run(czkawka, stdout=subprocess.PIPE) +czkawkadata = czkawkadata.stdout.decode('utf-8').splitlines() # Convert to a normal string and split into lines +if not czkawkadata: + print("All images in", cwd, "are unique. Exiting...") + exit() + +# Get number of images total and remove first line since it would cause issues +numimages = int(czkawkadata[0].split()[1]) +print ("Done!", numimages, "duplicate images found...") +czkawkadata.pop(0) + +# Split czkawkadata by the delimeter used by czkawka_cli +czkawkadata = [i.split(' - ') for i in czkawkadata] + +# Make keep store the images we want to keep +largest = 0 +i = 0 +dups = 0 +keep = [None] * numimages +for image in czkawkadata: + if not image[0]: + largest = 0 + i += 1 + continue + dups += 1 + size = image[2].split() + size = sizeinbytes(size[0], size[1]) # Convert to bytes so we can easily compate kb vs mb vs gb + if size > largest: + largest = size + keep[i] = image + +# Remove all empty entries from czkawkadata +czkawkadata[:] = [x for x in czkawkadata if x[0]] + +# Remove any images we're keeping from czkawkadata to be left with only the duplicates +for image in keep: + czkawkadata.remove(image) + +# User actions +confirmation = None +message = "Are you sure you want to delete all " + str(dups - len(keep)) + " duplicate images? (Yes/No/Show) " +while not confirmation: + confirmation = input(message) + if (confirmation == "yes"): + for image in czkawkadata: + os.remove(image[0]) + print("Removed image", image[0]) + elif (confirmation == "no"): + exit() + elif (confirmation == "show"): + for image in czkawkadata: + print(image) + confirmation = None # Prompt again + else: + confirmation = None |