-
Notifications
You must be signed in to change notification settings - Fork 0
/
linker.sh
executable file
·45 lines (33 loc) · 1.36 KB
/
linker.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
#!/usr/bin/env bash
# Ensure that the JSON exists
if [ ! -f "arguments.json" ]; then
echo "arguments.json not found"
exit 1
fi
# Get a list of every case ID that has no transcript
cases=( $(jq '.[] | select(has("transcript") | not) | .case_id' arguments.json | sed -e 's/"//g') )
# Get a list of all transcript files
transcripts=( $(ls transcripts/*.srt | xargs -n 1 basename |sed -e 's/\.srt$//') )
# Get a list of all transcript files that show signs of being wrong
blacklist=( $(cat problems.txt |sed -e 's/transcripts\///' |sed -e 's/\.srt$//') )
# Remove blacklisted transcripts
new_transcripts=()
for f in "${transcripts[@]}"; do
if [[ ! " ${blacklist[@]} " =~ " ${f} " ]]; then
new_transcripts+=("$f")
fi
done
transcripts=("${new_transcripts[@]}")
# Iterate through a list of all cases without transcripts
for case in "${cases[@]}"; do
# See if we have a transcript for that case
for transcript in "${transcripts[@]}"; do
if [ "$transcript" == "$case" ]; then
# Update this stanza to include the URL for the transcript
tmp=$(mktemp)
jq "map(if .case_id == \"$case\" then . + {\"transcript\": \"/transcripts/$case.srt\"} else . end)" arguments.json > "$tmp" && mv "$tmp" arguments.json
echo "Added $case transcript URL to arguments.json"
break
fi
done
done