-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaaccheck
executable file
·114 lines (99 loc) · 2.28 KB
/
aaccheck
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
# for debugging
# set -x
prog=`basename $0`
# do not be verbose in output
verbose=0
# do not debug by default
debug=0
# don't be quiet by default
quiet=0
# extensions to check for
extlist=(avi mkv mp4 m4v flv)
#
# had to read http://wiki.bash-hackers.org/howto/getopts_tutorial to figure out "getopts"!
#
while getopts dfhqv opt; do
case $opt in
v) verbose=1 ;;
d) debug=1 ;;
q) quiet=1; verbose=1 ;;
h) echo "Usage: $prog # checks all files ending in: ${extlist[@]}"
echo " $prog foo.mkv bar.mkv # only check specified files"
echo " $prog -q # don't show state of every file; (implies -v)"
echo " $prog -v # spits a list of files missing aac to stdout"
echo " # in addition to the usual commented info"
exit 0
;;
esac
done
#
# remove flags from the paramater list
shift $((OPTIND-1))
found=1
if [ $# = 0 ]; then
found=0
for ext in ${extlist[@]}; do
set *.$ext
if [ "x$*" != 'x*.'"$ext" ]; then
found=1
break
fi
done
fi
if [ $found = 0 ]; then
echo "${prog}: No files specified and no files found with extension: ${extlist[@]}"
exit 2
fi
needs_converting() {
file="$1"
if [ ! -r "$file" -o -d "$file" ]; then
# return 1 for false
return 1
fi
has_ac3=0
has_aac=0
if [ $debug = 1 ]; then
echo "ffmpeg -i $file:"
ffmpeg -i "$file" 2>&1 | tee /dev/tty | grep 'Audio: ac3' > /dev/null && has_ac3=1
ffmpeg -i "$file" 2>&1 | tee /dev/tty | grep 'Audio: aac' > /dev/null && has_aac=1
echo ""
else
ffmpeg -i "$file" 2>&1 | grep 'Audio: ac3' > /dev/null && has_ac3=1
ffmpeg -i "$file" 2>&1 | grep 'Audio: aac' > /dev/null && has_aac=1
fi
needs_it=1
[ $has_ac3 = 1 -a $has_aac = 0 ] && needs_it=0
# return 0 for true and 1 for false!!!
return $needs_it
}
conversion_check() {
file="$1"
if [ ! -r "$file" -o -d "$file" ]; then
echo "# ⚠️ $file - not readable" >&2
return
fi
if needs_converting "$file"; then
if [ $verbose = 0 ]; then
echo "# ❌ $file"
else
[ $quiet == 0 ] && echo "# ❌ $file" >&2
echo "$file"
fi
else
if [ $verbose = 0 ]; then
[ $quiet == 0 ] && echo "# ✅ $file"
else
[ $quiet == 0 ] && echo "# ✅ $file" >&2
fi
fi
}
for i; do
if [ -d "$i" ]; then
for j in "$i"/*.mkv; do
conversion_check "$j"
done
else
conversion_check "$i"
fi
done