added 12/24h timestamp formatting as birdnet.conf variable

defaults to 24h timestamps

working on species_notifier.sh
This commit is contained in:
Patrick McGuire
2021-09-30 14:19:35 -04:00
parent c2bb057999
commit 50d6a56ae5
6 changed files with 94 additions and 22 deletions
+8 -2
View File
@@ -2,15 +2,21 @@
set -x
source /etc/birdnet/birdnet.conf
if [ "${TIMESTAMP_FORMAT}" == "12" ];then
STAMP="%I:%M:%S%P"
else
STAMP="%H:%M:%S"
fi
if pgrep arecord &> /dev/null ;then
echo "Recording"
else
if [ -z ${REC_CARD} ];then
arecord -f S16_LE -c${CHANNELS} -r48000 -t wav --max-file-time 9\
--use-strftime ${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-%I:%M:%S%P.wav
--use-strftime ${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-${STAMP}.wav
else
arecord -f S16_LE -c${CHANNELS} -r48000 -t wav --max-file-time 9\
-D "${REC_CARD}" --use-strftime \
${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-%I:%M:%S%P.wav
${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-${STAMP}.wav
fi
fi
+34 -4
View File
@@ -31,6 +31,17 @@ get_DO_EXTRACTIONS() {
done
}
get_TIMESTAMP_FORMAT() {
read -n2 -p "Would you like recordings to be time stamped in 12-hour AM/PM
or 24-hour format? " TIMESTAMP_FORMAT
echo
case $TIMESTAMP_FORMAT in
12 ) ;;
24 ) ;;
* ) TIMESTAMP_FORMAT=24;;
esac
}
get_DO_RECORDING() {
while true; do
read -n1 -p "Is this device also doing the recording? " DO_RECORDING
@@ -144,7 +155,7 @@ get_INSTALL_NOMACHINE() {
}
get_CHANNELS() {
REC_CARD="\$(sudo -u pi aplay -L \
REC_CARD="$(sudo -u pi aplay -L \
| grep dsnoop \
| cut -d, -f1 \
| grep -ve 'vc4' -e 'Head' -e 'PCH' \
@@ -158,8 +169,8 @@ get_CHANNELS() {
| uniq)"
script -c "arecord -D ${SOUND_CARD} --dump-hw-params" -a "${SOUND_PARAMS}" &> /dev/null
CHANNELS=$(awk '/CHANN/ { print $2 }' "${SOUND_PARAMS}" | sed 's/\r$//')
[ ! -z REC_CARD ] || REC_CARD=default
[ ! -z CHANNELS ] || CHANNELS=2
[ -z REC_CARD ] || REC_CARD=default
[ -z CHANNELS ] || CHANNELS=2
echo "REC_CARD variable set to ${REC_CARD}"
echo "Number of channels available: ${CHANNELS}"
}
@@ -171,6 +182,7 @@ configure() {
get_LONGITUDE
get_DO_EXTRACTIONS
get_DO_RECORDING
get_TIMESTAMP_FORMAT
get_REMOTE
get_EXTRACTIONS_URL
get_PUSHED
@@ -220,14 +232,32 @@ DO_EXTRACTIONS=${DO_EXTRACTIONS}
################################################################################
#----------------------------- Recording Service ----------------------------#
#_______________The two variables below can be set to enable __________________#
#________________________the birdnet_recording.service ________________________#
# Keep this EMPTY if you do not want this device to perform the recording. #
## DO_RECORDING is simply a setting for enabling the 24/7 birdnet_recording.service.
## DO_RECORDING is simply a setting for enabling the 24/7
## birdnet_recording.service.
## Set this to Y or y to enable recording.
DO_RECORDING=${DO_RECORDING}
## TIMESTAMP_FORMAT is the format the recording service will use to name its
## files. Setting this variable to "12" will name the recorded (and extracted)
## files using the 12-hour AM/PM time format. Setting this variable to "24"
## will name the files using the 24-hour time format. See examples below:
#
## TIMESTAMP_FORMAT=12
## example filename: 236-Northern_Cardinal-86%2021-09-30-birdnet-01:00:19pm.wav
#
## TIMESTAMP_FORMAT=24
## example filename: 236-Northern_Cardinal-86%2021-09-30-birdnet-13:00:19.wav
TIMESTAMP_FORMAT=${TIMESTAMP_FORMAT}
################################################################################
#----------------- Mounting a remote directory with systemd -----------------#
#_______________The four variables below can be set to enable a_______________#
+1 -1
View File
@@ -421,7 +421,7 @@ install_selected_services() {
install_livestream_service
fi
if [ ! -z "${INSTALL_NOMACHINE}" ];then
if [[ "${INSTALL_NOMACHINE}" =~ [Yy] ]];then
install_nomachine
fi
+9 -6
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Sends a notification if a new species is detected
# set -x
#set -x
trap 'rm -f $TMPFILE' SIGINT SIGHUP EXIT
source /etc/birdnet/birdnet.conf
@@ -12,11 +12,14 @@ cat "${IDFILE}" > "${TMPFILE}"
/usr/local/bin/update_species.sh &> /dev/null
if ! diff "${IDFILE}" "${TMPFILE}"; then
SPECIES=("$(diff "${IDFILE}" "${TMPFILE}" \
| awk '/</ {print $2" "$3}')")
NOTIFICATION="New Species Detected: ${SPECIES[@]}"
if ! diff "${IDFILE}" "${TMPFILE}" &> /dev/null; then
SPECIES=("$(diff "${IDFILE}" "${TMPFILE}" \
| grep "Common Name" \
| sort \
| awk '{for(i=4;i<=NF;++i)printf $i""FS ; print ""}')")
NOTIFICATION="New Species Detection: "${SPECIES[@]}""
echo "${NOTIFICATION}" && exit
sudo systemctl restart birdnet_analysis && sleep 30
sudo systemctl start extraction