#!/bin/sh
#Call me from the directory which you would like to add the lengths of video and gifs. ffmpeg is a dependency. Additional formats can be supported by adding them to the ls command.
hours=0
minutes=0
seconds=0
for line in $(ls *.webm *.mp4 *.gif)
do
  currentTime=$(ffprobe -show_format -pretty -loglevel quiet $line | grep duration | sed -e 's/duration=//' -e 's/:/ /g' -e 's/\([0-9 ]*\).*/\1/')
  echo $line
  seconds=$(echo "$seconds + $(echo $currentTime | awk '{print $3}')" | bc)
  minutes=$(echo "$minutes + $(echo $currentTime | awk '{print $2}')" | bc)
  hours=$(echo "$hours + $(echo $currentTime | awk '{print $1}')" | bc)
done
[[ $seconds -ge 60 ]] && minutes=$(echo "$minutes + $seconds/60" | bc) && seconds=$(echo "$seconds%60" | bc)
[[ $minutes -ge 60 ]] && hours=$(echo "$hours + $minutes/60" | bc) && minutes=$(echo "$minutes%60" | bc)
echo "Hours:$hours Minutes:$minutes Seconds:$seconds"
