-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.sh
executable file
·99 lines (79 loc) · 2.5 KB
/
process.sh
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
# TODO fold all this into the single ruby script?
# option parsing cargo-culted from /usr/share/getopt/getopt-parse.bash
TEMP=`getopt -o efmo:sw:x --long outline,force,montage,outputdir:,scaling,window:,spiky \
-n 'cdcover.process' -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
OUTDIR="png"
NO_SCALING=1
GRAPH_TYPE="normal"
MV_WINDOW=5
while true ; do
case "$1" in
-o|--outputdir) OUTDIR=$2; shift 2;;
-s|--scaling) unset NO_SCALING; shift;;
-m|--montage) MONTAGE=1; shift;;
-w|--window) MV_WINDOW=$2; shift 2;;
-f|--force) FORCE_OUT=1; shift;;
-x|--spiky) GRAPH_TYPE='spikey'; shift;;
-e|--outline) GRAPH_TYPE='outline'; shift;;
--) shift; break;;
*) echo "Internal error with getopt"; exit 1;;
esac
done
mkdir -p "$OUTDIR"
x=1
max_samples=1
track_length () {
# Samples read: 12582912
sox "$1" -n stat 2>&1 | sed -ne 's/^Samples read: *//p'
}
if [ ! $NO_SCALING ]; then
for i in "$@"; do
samples=$(track_length "$i")
# echo "$i = $samples"
if [ $samples -gt $max_samples ]; then
max_samples=$samples
fi
done
fi
tmpfile=$(mktemp)
for i in "$@"; do
j=$(basename "$i")
k="${j%.*}"
if [ ! $NO_SCALING ]; then
samples=$(track_length "$i")
else
samples=1
fi
# magically extract track information to set the title
a=$(mp3info -p '%n/%t' "$i")
trk=${a%/*}; trk="${trk:- }"
ttl=${a#*/}; ttl="${ttl:-$k}"
if [ "$DEBUG_CDCOVER" ]; then
echo "[$a]"
echo "[$trk]"
echo "[$ttl]"
fi
### THIS IS HORRIBLE
# force all the output filenames to have no spaces because montage is dumb
t_png=$(printf "%s.png" "$k")
png="${t_png// /_}"
# echo ruby cdcover.rb "$i" "$trk" "$ttl" "$OUTDIR/$png" $max_samples $samples $MV_WINDOW
update_file=0
if [ $FORCE_OUT ]; then update_file=1; fi
if [ "$i" -nt "$OUTDIR/$png" ]; then update_file=1; fi
if [ $update_file -gt 0 ]; then
if [ "$DEBUG_CDCOVER" ]; then
echo ruby cdcover.rb "$i" "$trk" "$ttl" "$OUTDIR/$png" $max_samples $samples $GRAPH_TYPE $MV_WINDOW
fi
ruby cdcover.rb "$i" "$trk" "$ttl" "$OUTDIR/$png" $max_samples $samples $GRAPH_TYPE $MV_WINDOW
fi
echo "$OUTDIR/$png" >> "$tmpfile"
x=$((x+1))
done
if [ $MONTAGE ]; then
montage -tile 4x4 -geometry 150x150 @"$tmpfile" "$OUTDIR/montage.png"
fi
rm -f "$tmpfile"