From 355188a16647c13020e434a26f972e783d5e6fed Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Tue, 5 Oct 2021 18:25:59 -0400 Subject: [PATCH] adding small version file for now --- scripts/birdnet_stats.sh | 9 ++++++--- scripts/extract_new_birdsounds.sh | 30 ++++++++++++++++++++++-------- version | 2 ++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 version diff --git a/scripts/birdnet_stats.sh b/scripts/birdnet_stats.sh index be267ea..ec7c034 100755 --- a/scripts/birdnet_stats.sh +++ b/scripts/birdnet_stats.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash # BirdNET Stats Page -trap 'setterm --cursor on' EXIT +trap 'setterm --cursor on && exit' EXIT +trap 'rm -f "${TMP_FILE}" && exit' EXIT source /etc/birdnet/birdnet.conf setterm --cursor off +TMP_FILE="$(mktemp)" while true;do cat << "EOF" @@ -55,8 +57,9 @@ while read -r line;do else verbage=detections fi - echo -e "${DETECTIONS} $verbage for ${SPECIES//_/ } | max conf ${MAX_SCORE}%" | sort -done < ${IDFILE} + echo "${DETECTIONS} $verbage for ${SPECIES//_/ } | max conf ${MAX_SCORE}%" +done < "${IDFILE}" > ${TMP_FILE} +sort -rk1 -h "${TMP_FILE}" fi echo echo -n "Listening since "${INSTALL_DATE}"" diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh index 3131d37..baf2b12 100755 --- a/scripts/extract_new_birdsounds.sh +++ b/scripts/extract_new_birdsounds.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Exit when any command fails -set -x +#set -x set -e # Keep track of the last executed command #trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG @@ -116,10 +116,10 @@ for h in "${SCAN_DIRS[@]}";do # If there are already 20 extracted entries for a given species # for today, remove the oldest file and create the new one. - # if [[ "$(find ${NEWSPECIES_BYDATE} | wc -l)" -ge 21 ]];then + # if [[ "$(find ${NEWSPECIES_BYDATE} | wc -l)" -ge 20 ]];then # echo "20 ${SPECIES}s, already! Removing the oldest by-date and making a new one" # cd ${NEWSPECIES_BYDATE} || exit 1 - # ls -1t . | tail -n +21 | xargs -r rm -vv + # ls -1t . | tail -n +20 | xargs -r rm -vv # fi echo "Extracting audio . . . " @@ -128,34 +128,48 @@ for h in "${SCAN_DIRS[@]}";do # structured by-species, symbolic links are made to populate the new # directory. - ### TESTING longer extraction context + # This section sets the SPACER that will be used to pad the audio clip with + # context. If EXTRACTION_LENGTH is 10, for instance, 3 seconds are removed + # from that value and divided by 2, so that the 3 seconds of the call are + # within 3.5 seconds of audio context before and after. [ -z ${EXTRACTION_LENGTH} ] && EXTRACTION_LENGTH=6 SPACER=$(echo "scale=1;(${EXTRACTION_LENGTH} - 3 )/2" |bc -l) START=$(echo "scale=1;${START} - ${SPACER}"|bc -l) END=$(echo "scale=1;${END} + ${SPACER}"|bc -l) + # If the SPACER would have the START value less that 0, start at the + # beginning of the audio file. If the SPACER would make the END value + # exceed the end of the audio file, end the extraction at the end of the + # audio file. if (( $(echo "${START} < 1" | bc -l) ));then START=0;fi if (( $(echo "${END} > ${RECORDING_LENGTH}" | bc -l) ));then END=${RECORDING_LENGTH};fi ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \ -acodec copy -ss "${START}" -to "${END}"\ "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}" - if [[ "$(find ${NEWSPECIES_BY_COMMON} | wc -l)" -ge 21 ]];then + + + # Remove the oldest symbolic links that would made the directory have more + # than 20 entries. + if [[ "$(find ${NEWSPECIES_BY_COMMON} | wc -l)" -ge 20 ]];then echo "20 ${SPECIES}s, already! Removing the oldest by-species and making a new one" cd ${NEWSPECIES_BY_COMMON} || exit 1 - ls -1t . | tail -n +21 | xargs -r rm -vv + ls -1t . | tail -n +20 | xargs -r rm -vv ln -fs "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"\ "${NEWSPECIES_BY_COMMON}/${a}-${NEWFILE}" echo "Success! New extraction for ${COMMON_NAME}" else + # Make symbolic link of the extraction to add to By_Common_Name ln -fs "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"\ "${NEWSPECIES_BY_COMMON}/${a}-${NEWFILE}" fi - if [[ "$(find ${NEWSPECIES_BY_SCIENCE} | wc -l)" -ge 21 ]];then + # Remove the oldest symbolic links that would made the directory have more + # than 20 entries. + if [[ "$(find ${NEWSPECIES_BY_SCIENCE} | wc -l)" -ge 20 ]];then echo "20 ${SPECIES}s, already! Removing the oldest by-species and making a new one" cd ${NEWSPECIES_BY_SCIENCE} || exit 1 - ls -1t . | tail -n +21 | xargs -r rm -vv + ls -1t . | tail -n +20 | xargs -r rm -vv ln -fs "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"\ "${NEWSPECIES_BY_SCIENCE}/${a}-${NEWFILE}" echo "Success! New extraction for ${COMMON_NAME}" diff --git a/version b/version new file mode 100644 index 0000000..17b4d0b --- /dev/null +++ b/version @@ -0,0 +1,2 @@ +rpialpha +Tue 05 Oct 2021 06:25:48 PM EDT