I had a bunch of media (videos to be precise) in a folder and I wanted to sum all the lenghts. I'll be ignoring seconds and hours for now, just to get the gist of it. I wrote this script:
sum=0
for file in *
do
curr=$(exiftool $file |
grep -i "^Duration" |
awk '{print $3}' |
cut -d':' -f 2)
((sum = sum + curr))
done
echo $sum
But it was really slow, and I wondered if I could somehow make it faster (or alter it, I'm wondering if how would you do it differently).
Logic behind it is pretty straightforward, iterate through every file in directory, grab lines with duration, isolate time (hh:mm:ss) format with awk, cut with ':' as delimiter to isolate minutes. And add the minutes together in process, and print the sum. I'm using zsh for the record.