-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkvdur
executable file
·57 lines (43 loc) · 1.44 KB
/
checkvdur
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env sh
# Check total duration of all videos in current directory.
ScriptName=${0##*/}
Version=1.0.0
Deps='ffmpeg bc'
HelpMessage="\033[32m$ScriptName\033[0m $Version
Alexander Chaplin Braz <contact@alexchaplinbraz.com>
Check total duration of all videos in current directory based on the passed
file extension.
\033[33mUSAGE:\033[0m
$ScriptName <EXT>
$ScriptName [FLAG]
\033[33mFLAGS:\033[0m
\033[32m-h\033[0m, \033[32m--help\033[0m Print help and exit.
\033[32m-v\033[0m, \033[32m--version\033[0m Print version and exit.
\033[33mARGS:\033[0m
\033[32m<EXT>\033[0m Video extension (without the .)
\033[33mDEPENDENCIES:\033[0m
$Deps
"
error() {
printf "\033[1;31m${2:-ERROR}\033[0m: %s.\nTry '%s --help' for more information.\n" \
"$1" "$ScriptName" 1>&2
exit 1
}
case $1 in
-h|--help|'') printf '%b' "$HelpMessage"; exit 0 ;;
-v|--version) printf '%s\n' "$Version"; exit 0 ;;
*) Ext=$1 ;;
esac
for dep in $Deps; do ! command -v $dep 1>/dev/null && MissingDeps="$MissingDeps $dep"; done
[ "$MissingDeps" ] && error "missing dependencies:$MissingDeps"
find . -maxdepth 1 | grep -q $Ext$ || error "no files with '$Ext' extension found"
env TZ=UTC+0 LC_ALL=C \
date +'%j %T.%N' --date=@$(
for i in *.$Ext; do
ffmpeg -i "$i" 2>&1 \
| awk -F: '/Duration:/{print $2*3600+$3*60+$4}';
done \
| paste -sd+ \
| bc) \
| awk '{print $1-1 "d",$2}' \
| sed 's/[.0]*$//'