From 9ede00566c0373a23021c788adc8deb83d9b0f65 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Fri, 1 Oct 2021 18:44:00 -0400 Subject: [PATCH] added EXTRACTION_LENGTH for testing --- scripts/birdnet_analysis.sh | 12 ++++++++---- scripts/extract_new_birdsounds.sh | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/birdnet_analysis.sh b/scripts/birdnet_analysis.sh index 7e58fb5..dd91ad2 100755 --- a/scripts/birdnet_analysis.sh +++ b/scripts/birdnet_analysis.sh @@ -10,7 +10,7 @@ CUSTOM_LIST="/home/pi/BirdNET-Lite/custom_species_list.txt" get_files() { echo "get_files() for ${1:19}" files=($( find ${1} -maxdepth 1 -name '*wav' \ - | sort \ + | sort -r \ | awk -F "/" '{print $NF}' )) [ -n "${files[1]}" ] && echo "Files loaded" } @@ -39,11 +39,16 @@ move_analyzed() { # - {DIRECTORY} run_analysis() { echo "Starting run_analysis() for ${1:19}" - WEEK=$(date --date="${2}" +"%U") + WEEK=$(date +"%U") cd ${HOME}/BirdNET-Lite || exit 1 for i in "${files[@]}";do if [ -f ${1}/${i} ] && [ ! -f ${CUSTOM_LIST} ];then + FILE_LENGTH="$(ffmpeg -i ${1}/${i} 2>&1 \ + | awk -F. '/Duration/ {print $1}' \ + | cut -d':' -f3-4)" set -x + [ ${RECORDING_LENGTH} == 60 ] && RECORDING_LENGTH=01:00 + [ "${FILE_LENGTH}" == "${RECORDING_LENGTH}" ] || continue python3 analyze.py \ --i "${1}/${i}" \ --o "${1}/${i}.csv" \ @@ -72,9 +77,8 @@ run_analysis() { } # The three main functions -# Requires 2 arguments: +# Takes one argument: # - {DIRECTORY} -# - {"today", "yesterday", "2 days ago",...} run_birdnet() { echo "Starting run_birdnet() for \"${1:19}\"" get_files "${1}" diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh index 0952a21..f3561d8 100755 --- a/scripts/extract_new_birdsounds.sh +++ b/scripts/extract_new_birdsounds.sh @@ -128,6 +128,16 @@ for h in "${SCAN_DIRS[@]}";do # structured by-species, symbolic links are made to populate the new # directory. + ### TESTING longer extraction context + set -x + SPACER=$(echo "(${EXTRACTION_LENGTH} - 3 )/2" |bc -l) + START=$(echo "${START} - ${SPACER}"|bc -l) + END=$(echo "${END} + ${SPACER}"|bc -l) + + if (( $(echo "${START} < 0" | bc -l) ));then START=0;fi + if (( $(echo "${END} > ${RECORDING_LENGTH}" | bc -l) ));then END=${RECORDING_LENGTH};fi + + set +x ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \ -acodec copy -ss "${START}" -to "${END}"\ "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"