Sunday, March 16, 2008

Duplicate image remover script

Instructions:

  • Gererate dup.txt with this command: findimagedupes -f=mypic.dat > dup.txt
  • Go inside the directory where dup.txt is saved, run dupless.sh
  • The script will show you 2 images, select the one you want to remove, press "d"
  • Incase you want to recover deleted images, they are just moved to ".qiv_trash"
Prerequisites:

  • apt-get install qiv findimagedupes

#!/bin/bash

input="dup.txt"
c=0
t=`cat $input | wc -l`

while read line
do
ext=`echo "$line" | awk -F "." '{print $2}' | awk '{ print $1}' | sed 's/[[:blank:]]*$//g'`
#echo $ext
n1=`echo "$line" | awk -v ext="$ext" -F "$ext" '{print $1ext}'`
#echo $n1

ext=`echo "$line" | awk -F "." '{print $NF}'` | sed 's/[[:blank:]]*$//g'
#echo $ext
n2=`echo "$line" | awk -v ext="$ext" -F "$ext" '{print $2ext}' | sed 's/^ //g'`
#echo $n2
#exit

s1=`ls -al "$n1" | awk '{print $5}'`
s2=`ls -al "$n2" | awk '{print $5}'`

if [ $s2 -gt $s1 ]
then
tmp=$n2
n2=$n1
n1=$tmp
fi

if [ -e "$n1" ] && [ -e "$n2" ]
then
echo -en "$n1\t"
qiv -t -e -W 75 -t "$n1" & 2>/dev/null
p1=$!
echo -en "[$p1]\n"

echo -en "$n2\t"
qiv -t -W 75 -t "$n2" & 2>/dev/null
p2=$!
echo -en "[$p2]\n"

#wait $p2
while [ 1 ]
do
c=`pidof -o $p2 qiv`
if [ ! "$c" ]; then
break
fi

c=`pidof -o $p1 qiv`
if [ ! "$c" ]; then
break
fi
done

killall -q -s9 qiv 2>&1 1> /dev/null
fi

c=$((c+1))
echo "[+] $c-done $((t-c))-remaining"
echo

done < $input