Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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