From 13351f3e579c936405ce8720fa0f2b6d199d8104 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sat, 25 Nov 2023 19:40:39 +0100 Subject: [PATCH] indeel script --- .scripts/indeel | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 .scripts/indeel diff --git a/.scripts/indeel b/.scripts/indeel new file mode 100755 index 0000000..4d18ed5 --- /dev/null +++ b/.scripts/indeel @@ -0,0 +1,64 @@ +#!/bin/bash +# Watch this folder for incoming files +# Rename each file to a hash of some kind +# Put each file into a folder of the old name + +[[ -v 1 ]] && DIR=$1 || DIR=$PWD +cd $DIR + +while true; do + for f in *.*; do + # Check if we need to skip + [ -e "$f" ] || continue + [ -e "$f.part" ] && continue + [ ${f##*.} == "part" ] && continue + [ ${f##*.} == "sh" ] && continue + + # Print some file info, and check file validity + FILEINFO=`file $f` + echo $FILEINFO + if echo "$FILEINFO" | grep -q empty; then + continue + fi + + # Handle webp as a special case, and defer to next iteration + if [ ${f##*.} == "webp" ] + then + if [ `identify $f | wc -l` -gt 1 ] + then + echo "Animated webp. Converting to gif..." + convert $f ${f%.*}.gif + rm $f + continue + else + echo "Picture webp. Converting to jpg..." + convert $f ${f%.*}.jpg + rm $f + continue + fi + fi + + # Determine phash and destination folder + # If you don't have your own phash algorithm at home, + # you might consider using md5sum + # NAME=`md5sum $f | awk '{print $1}'` + NAME=`dctfilename $f` + FOLDER=${f%.*} + FOLDER=${FOLDER%\(*} + + # Check for duplicate phashes in the .known-files file + if fgrep -q $NAME .known-files; then + echo "$NAME is a duplicate file" + mkdir -p duplicates + mv -f $f "duplicates/$NAME.${f##*.}" + else + echo $NAME >> .known-files + mkdir -p $FOLDER + echo "$f" + echo `dctfilename $f -v` + mv -f $f "$FOLDER/$NAME.${f##*.}" + fi + echo '------' + done + sleep 1 +done