Skip to content

Instantly share code, notes, and snippets.

@loentar
Created June 12, 2022 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loentar/08913e49844d130d9d0b68c515208dec to your computer and use it in GitHub Desktop.
Save loentar/08913e49844d130d9d0b68c515208dec to your computer and use it in GitHub Desktop.
Calculate total drawing time in Krita. run: krita-drawing-time.sh /path/to/your/kra-files
#!/bin/bash
if [ -n "$1" ]
then
cd "$1"
fi
readableTime() {
value=$1
res="$(($value % 60))s"
value=$((value / 60))
if [ $value -gt 0 ]
then
res="$(($value % 60))m $res"
value=$((value / 60))
if [ $value -gt 0 ]
then
res="$(($value % 24))h $res"
value=$((value / 24))
if [ $value -gt 0 ]
then
res="${value}d $res"
fi
fi
fi
echo "$res"
}
getTagValue() {
sed "/<$1>/"'!d'";s/.*>\(.*\)<.*/\\1/" <<< "$doc"
}
declare -a timings
for filename in $(find * -type f -name '*.kra')
do
doc=$(unzip -p "$filename" documentinfo.xml)
title=$(getTagValue title)
creationDate="$(getTagValue creation-date | sed 's/[^0-9]//g')"
editingTime="$(getTagValue editing-time)"
[ -n "$editingTime" ] || editingTime=0
echo -e "$filename\t$title\t$creationDate\t$editingTime\t($(readableTime $editingTime))"
existingTime="${timings[$creationDate]:-0}"
if [ -z "$existingTime" -o "$existingTime" -lt "$editingTime" ]
then
timings[$creationDate]=$editingTime
fi
done
total=0
for key in ${timings[@]}
do
total=$(($total + $key))
done
echo -e "total time spent=$total seconds ($(readableTime $total))"
@loentar
Copy link
Author

loentar commented Jun 12, 2022

Calculates total time for all drawings in directory. If directory name is omitted current directory will be used.

bash krita-drawing-time.sh ~/Pictures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment