Last active
September 12, 2017 21:00
-
-
Save ericek111/7463aa1c2367683e51578789767a583a to your computer and use it in GitHub Desktop.
LiveATC archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/ericek111/7463aa1c2367683e51578789767a583a | |
# Check if SOX is installed | |
if ! hash "${SOX:-sox}" 2>/dev/null; then | |
echo "ERROR: SOX was not found in path ${SOX:-sox}" | |
echo "Run: sudo apt-get install sox libsox-fmt-mp3" | |
exit 1 | |
fi | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: record.sh (ICAO code) [threshold] [-t]" | |
echo " ICAO code - according to liveatc.net, airport code + mount code, e. g. KJFK_TWR" | |
echo " threshold - sox argument, static noise threshold level" | |
echo " -t - test, if the script is running and sox recording. If it isn't, start recording." | |
echo " > by ericek111: https://gist.github.com/ericek111/7463aa1c2367683e51578789767a583a" | |
exit 1 | |
fi | |
threshold="1.5%" | |
if [[ "$2" -ne "-t" ]]; then threshold="$2"; fi | |
ABSPATH=`pwd` | |
pidfile="$ABSPATH/record_${1,,}.pid" | |
spawnedpid=0 | |
mkdir -p "$ABSPATH/rec" | |
mkdir -p "$ABSPATH/pls" | |
checkifrecording(){ | |
sleep 3 | |
if ps -p $! > /dev/null; then | |
echo $! > "$pidfile" | |
else | |
echo "Not recording!!!" | |
fi | |
} | |
if [ -f "$pidfile" ]; then | |
if ps -p `cat "$pidfile"` > /dev/null; then | |
if [[ $* == *"-t"* ]]; then exit 0; fi | |
echo "Interrupting previous recording of ${1^^} (`cat "$pidfile"`) started on `date -r "$pidfile" "+%d. %m. %Y in %H:%M:%S"`" | |
kill `cat "$pidfile"` | |
else | |
echo "Previous recording of ${1^^} (`cat "$pidfile"`) started on `date -r "$pidfile" "+%d. %m. %Y in %H:%M:%S"` ended abruptly!" | |
fi | |
rm "$pidfile" | |
fi | |
plsfile="$ABSPATH/pls/${1,,}.pls" | |
if [ -f "$plsfile" ]; then | |
rm "$plsfile" | |
fi | |
wget_output=$(wget -4 -N -q -O "$plsfile" "https://www.liveatc.net/play/${1,,}.pls") | |
if [ $? -ne 0 ]; then | |
rm "$plsfile" 2> /dev/null | |
echo "ERROR: Invalid facility: ${1^^}!" | |
exit 2 | |
else | |
echo "Downloaded ${1,,}.pls: $(cat "$plsfile" |head -n2|tail -n1 | cut -c 7-)" | |
fi | |
newfilename="$ABSPATH/rec/${1^^}_$(date +%Y-%m-%d_%H-%M-%S)" | |
echo "${SOX:-sox} -t mp3 $plsfile $newfilename.mp3 silence -l 1 0.3 $threshold -1 2.0 $threshold" | |
"${SOX:-sox}" -t mp3 $plsfile "$newfilename.mp3" silence -l 1 0.3 "$threshold" -1 2.0 "$threshold" &>>"$newfilename.txt" & | |
spawnedpid=$! | |
checkifrecording & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment