-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash-cue-validator-test.sh
More file actions
65 lines (51 loc) · 2.59 KB
/
bash-cue-validator-test.sh
File metadata and controls
65 lines (51 loc) · 2.59 KB
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
#!/bin/bash
com=" CATALOG CDTEXTFILE FILE FLAGS INDEX ISRC PERFORMER POSTGAP PREGAP REM SONGWRITER TITLE TRACK "
if [ "$(echo " WAVE MP3 AIFF " | grep -o " $(grep -m1 FILE "$1" | sed -n 's/.* //p' | tr -d '\f\r') ")" ]
then
#~ General parsing
header=`head -c3 "$1" | xxd -p`
[ $(echo $header | grep -o "efbbbf") ] && echo "UTF-8 BOM detected"
[ $(echo "$header `echo $header | rev`" | grep -o "feff") ] && echo "UTF-16 BOM detected"
[ "$(head -n1 "$1" | rev | cut -c1 | xxd -p)" = "0d0a" ] ||\
echo "Non-CRLF line ending"
[ "$(grep -m1 INDEX "$1" | grep -o '..:..:..')" == "00:00:00" ] ||\
echo "Wrong start index"
tracks=$(grep -o "TRACK [0-9]\+" "$1" | cut -d" " -f2)
[ $((`echo "$tracks" | head -n1`)) -eq 1 ] || echo "First track not 01"
[ $((10#`echo "$tracks" | tail -n1`)) -gt 99 ] && echo "Tracks out of range"
[ "$(echo "$tracks" | sort -uc 2>&1)" ] && echo "Tracks not in sequence"
#~ Multiline parsing
IFS=$'\n'
for p in $(grep -o "TRACK\|INDEX 01" "$1" | tr "\n" " " | sed 's/INDEX 01 /&\n/g')
do [ "$p" = "TRACK INDEX 01 " ] || echo "Track w/o matching index"
done
for p in $(grep -o "TRACK\|PREGAP\|INDEX 00" "$1" | tr "\n" " " | sed 's/TRACK/\n&/g')
do [ "$p" = "TRACK PREGAP INDEX 00 " ] && echo "PREGAP and INDEX 00 on same track"
done
for p in $(grep -o "TRACK\|INDEX .." "$1" | tr "\n" " " | sed 's/.\?TRACK /\n/g;s/INDEX //g;s/ $//')
do [ "$(echo "$p" | tr " " "\n" | sort -uc 2>&1)" ] && echo "Indexes not in sequence"
done
unset IFS
#~ Per line parsing
while read line
do
l=$((l+1))
if [ $l != 1 ]; then
[ "$(echo "$com" | grep -o " `echo "$line" | grep -o '^[A-Z]\+'` ")" ] ||\
echo "[$l] Unknown command"
fi
[ $((`echo "$line" | sed 's/[^"]//g' | tr -d '\n' | wc -m` % 2)) -eq 0 ] ||\
echo "[$l] Non-matching quote"
fn=$(echo $line | grep -o 'FILE.*' | cut -d\" -f2)
if [ "$fn" ]; then [ -f "$fn" ] || echo "[$l] Invalid referenced file"; fi
[ $((10#`echo "$line" | grep -o "..:..:.." | cut -d: -f2`)) -gt 59 ] &&\
echo "[$l] Wrong time format [..:XX:..]"
[ $((10#`echo "$line" | grep -o "..:..:.." | cut -d: -f3`)) -gt 74 ] &&\
echo "[$l] Wrong time format [..:..:XX]"
[ "$(echo "$line" | grep -o '^FILE')" ] && [ "$IDX" == "INDEX 00" ] &&\
echo "[$l] Non-compliant cue-sheet"
IDX=$(echo $line | grep -o "INDEX ..")
done < "$1"
else
[ -f "$(grep -m1 FILE "$1" | cut -d\" -f2)" ] || echo "Invalid referenced file"
fi