From c2bb05799999fb31c1c5225fab1e1954d49caa82 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Thu, 30 Sep 2021 12:07:47 -0400 Subject: [PATCH] tweaking a few fixes --- scripts/birdnet_analysis.sh | 6 ++---- scripts/birdnet_stats.sh | 8 +++++++- scripts/extract_new_birdsounds.sh | 22 ++++++++++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/scripts/birdnet_analysis.sh b/scripts/birdnet_analysis.sh index eedae8b..2ff4a37 100755 --- a/scripts/birdnet_analysis.sh +++ b/scripts/birdnet_analysis.sh @@ -4,8 +4,6 @@ source /etc/birdnet/birdnet.conf CUSTOM_LIST="/home/pi/BirdNET-Lite/custom_species_list.txt" DAYS=( -"2 days ago" -"yesterday" "today" ) @@ -33,8 +31,8 @@ move_analyzed() { mkdir -vvvvvvvp "${1}-Analyzed" && echo "'Analyzed' directory created" fi echo "Moving analyzed files to new directory" - mv -vv "${1}/${i}" "${1}-Analyzed/" - mv -vv "${1}/${j}" "${1}-Analyzed/" + mv "${1}/${i}" "${1}-Analyzed/" + mv "${1}/${j}" "${1}-Analyzed/" fi done } diff --git a/scripts/birdnet_stats.sh b/scripts/birdnet_stats.sh index 9b5ff88..28737dc 100755 --- a/scripts/birdnet_stats.sh +++ b/scripts/birdnet_stats.sh @@ -23,14 +23,20 @@ else a=0 fi echo -SOFAR=$(($(wc -l ${IDFILE}| cut -d' ' -f1)/2)) +if [ "${a}" -ge "1" ];then + SOFAR=$(($(wc -l ${IDFILE}| cut -d' ' -f1)/2)) +else + SOFAR=0 +fi echo " -$a detections so far" echo echo " -$SOFAR species identified so far" echo +if [ ${a} -ge 1 ];then while read -r line;do echo " | $line" done < <(awk -v n=2 '1; NR % n == 0 {print ""}' ${IDFILE}) +fi echo echo -n "Listening since "${INSTALL_DATE}"" sleep 180 diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh index 9dd4967..7dd34bf 100755 --- a/scripts/extract_new_birdsounds.sh +++ b/scripts/extract_new_birdsounds.sh @@ -34,7 +34,6 @@ fi echo "Starting numbering at ${a}" for h in "${SCAN_DIRS[@]}";do - echo "Creating the TMPFILE" # The TMPFILE is created from each .csv file BirdNET creates # within each "Analyzed" directory # Field 1: Start (s) @@ -42,6 +41,14 @@ for h in "${SCAN_DIRS[@]}";do # Field 3: Scientific name # Field 4: Common name # Field 5: Confidence + + # Removes old directories + if echo "${h}" | grep $(date --date="yesterday" "+%A") &> /dev/null;then + echo "Removing old directories" + rm -df "${h}" + rm -df "$(echo ${h} | cut -d'-' -f1-3)" + continue + fi # Iterates over each "Analyzed" directory for i in $(find ${h} -name '*csv' | sort );do # Iterates over each '.csv' file found in each "Analyzed" directory @@ -87,24 +94,20 @@ for h in "${SCAN_DIRS[@]}";do fi - echo "Checking for ${h}/${OLDFILE}" # Before extracting the "Selection," the script checks to be sure the # original WAVE file still exists. [[ -f "${h}/${OLDFILE}" ]] || continue - echo "Checking for ${NEWSPECIES_BYDATE}" # If a directory does not already exist for the species (by date), # it is created [[ -d "${NEWSPECIES_BYDATE}" ]] || mkdir -p "${NEWSPECIES_BYDATE}" - echo "Checking for ${NEWSPECIES_BY_COMMON}" # If a directory does not already exist for the species (by-species), # it is created. [[ -d "${NEWSPECIES_BY_COMMON}" ]] || mkdir -p "${NEWSPECIES_BY_COMMON}" - echo "Checking for ${NEWSPECIES_BY_SCIENCE}" # If a directory does not already exist for the species (by-species), # it is created. [[ -d "${NEWSPECIES_BY_SCIENCE}" ]] || mkdir -p "${NEWSPECIES_BY_SCIENCE}" @@ -124,7 +127,7 @@ for h in "${SCAN_DIRS[@]}";do # structured by-species, symbolic links are made to populate the new # directory. - ffmpeg -hide_banner -loglevel 52 -nostdin -i "${h}/${OLDFILE}" \ + 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 @@ -158,7 +161,7 @@ for h in "${SCAN_DIRS[@]}";do done < "${TMPFILE}" - echo -e "\n\n\nFINISHED!!! Processed extractions for ${h}" + echo -e "\n\n\nFINISHED!!! Processed extractions for ${h:19}" # Once each line of the TMPFILE has been processed, the TMPFILE is emptied # for the next iteration of the for loop. >"${TMPFILE}" @@ -167,7 +170,7 @@ for h in "${SCAN_DIRS[@]}";do # next extraction. [[ -d "${PROCESSED}" ]] || mkdir "${PROCESSED}" echo "Moving processed files to ${PROCESSED}" - mv -v ${h}/* ${PROCESSED} || continue + mv ${h}/* ${PROCESSED} &> /dev/null || continue done echo "Linking Processed files to "${EXTRACTED}/Processed" web directory" @@ -180,5 +183,4 @@ fi # That's all! -echo "Finished -- the extracted sections are in: -$(find -L ${EXTRACTED} -maxdepth 1)" +echo "Finished -- the extracted sections are in ${EXTRACTED}"