From aa1566eb67d99de3fc118f9cdbfa3fece497ae4c Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 28 Apr 2025 13:55:03 -0400 Subject: [PATCH] forreal flag on get_dups.sh to move files. --- 0.jpg => dups/0.jpg | Bin 1.jpg => dups/1.jpg | Bin get_dups.sh | 33 +++++++++++++++++++++++---------- 3 files changed, 23 insertions(+), 10 deletions(-) rename 0.jpg => dups/0.jpg (100%) rename 1.jpg => dups/1.jpg (100%) diff --git a/0.jpg b/dups/0.jpg similarity index 100% rename from 0.jpg rename to dups/0.jpg diff --git a/1.jpg b/dups/1.jpg similarity index 100% rename from 1.jpg rename to dups/1.jpg diff --git a/get_dups.sh b/get_dups.sh index 07a4e94..862b3c3 100755 --- a/get_dups.sh +++ b/get_dups.sh @@ -3,15 +3,22 @@ # License: MIT source myenv/bin/activate +# Remove trailing slash +path="${1%/}" + # Check if the first argument is a directory -if [ ! -d "$1" ]; then - echo "Error: '$1' is not a directory." +if [ ! -d "$path" ]; then + echo "Error: '$path' is not a directory." exit 1 fi +if [ "$2" = "forreal" ]; then + mkdir "$path/dups" +fi + # Get list of images shopt -s nullglob -pushd "$1" || exit 1 +pushd "$path" || exit 1 images=(*.jpg *.png) popd || exit 1 @@ -30,33 +37,39 @@ for ((i = 0; i < ${#images[@]}; i++)); do inner_image="${images[$j]}" echo -e "\nCompairing files: $outer_image TO $inner_image" - python3 dedup.py "$1/$outer_image" "$1/$inner_image" "$2" + python3 dedup.py "$path/$outer_image" "$path/$inner_image" "$2" exit_code=$? if [ $exit_code -eq 1 ]; then - echo "$1/$outer_image # $inner_image" >> dups.txt + echo "$path/$outer_image # $inner_image" >> dups.txt + if [ "$2" = "forreal" ]; then + mv "$path/$outer_image" "$path/dups" + fi break # No need to check more once found duplicate fi if [ $exit_code -eq 2 ]; then - echo "$1/$outer_image # $inner_image" >> alike.txt + echo "$path/$outer_image # $inner_image" >> alike.txt break # No need to check more once found close match to duplicate fi if [ $exit_code -eq 4 ]; then break # Skip Invaild inner Image fi if [ $exit_code -eq 5 ]; then - echo "$1/$outer_image # $inner_image" >> sameGPS.txt + echo "$path/$outer_image # $inner_image" >> sameGPS.txt break # No need to check more once found matching GPS image fi if [ $exit_code -eq 6 ]; then - echo "$1/$outer_image # $inner_image" >> sameGPSmile.txt + echo "$path/$outer_image # $inner_image" >> sameGPSmile.txt break # No need to check more once found matching GPS image fi if [ $exit_code -eq 8 ]; then - echo "$1/$outer_image" >> invalid.txt + echo "$path/$outer_image" >> invalid.txt + if [ "$2" = "forreal" ]; then + echo "To remove bad image run: rm $path/$outer_image" + fi break # No need to check more once found bad image fi if [ $exit_code -eq 9 ]; then - echo "$1/$outer_image" >> size.txt + echo "$path/$outer_image" >> size.txt break # No need to check more once found image too Small or Large fi