From 10bcb617197bf00346f679f09378d753327f3d63 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Fri, 3 May 2024 10:28:05 +0200 Subject: [PATCH] Update changeidenfication.sh --- .../rootfs/helpers/changeidenfication.sh | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/birdnet-pi/rootfs/helpers/changeidenfication.sh b/birdnet-pi/rootfs/helpers/changeidenfication.sh index c8dd12700..b12e59719 100755 --- a/birdnet-pi/rootfs/helpers/changeidenfication.sh +++ b/birdnet-pi/rootfs/helpers/changeidenfication.sh @@ -8,16 +8,26 @@ set +u #avoid error with apprise variables # SET VARIABLES # ################# -# shellcheck disable=SC1091 -source /etc/birdnet/birdnet.conf -OLDNAME="" #OLDNAME="Mésange_charbonnière-78-2024-05-02-birdnet-RTSP_1-18:14:08.mp3" -NEWNAME="" #NEWNAME="Lapinus atricapilla_Lapinu à tête noire" -OLDNAME="$1" -NEWNAME="$2" +# Get arguments +OLDNAME="$1" #OLDNAME="Mésange_charbonnière-78-2024-05-02-birdnet-RTSP_1-18:14:08.mp3" +NEWNAME="$2" #NEWNAME="Lapinus atricapilla_Lapinu à tête noire" + +# Fixed values LABELS_FILE="$HOME/BirdNET-Pi/model/labels.txt" DB_FILE="$HOME/BirdNET-Pi/scripts/birds.db" DETECTIONS_TABLE="detections" +# Extract the part before the _ from $NEWNAME +NEWNAME_comname="${NEWNAME#*_}" +NEWNAME_sciname="${NEWNAME%%_*}" + +# Replace spaces with underscores +NEWNAME_comname2="${NEWNAME_comname// /_}" +OLDNAME_comname2="${OLDNAME_comname// /_}" + +# Replace OLDNAME_comname2 with NEWNAME_comname2 in OLDNAME +NEWNAME_filename="${OLDNAME//$OLDNAME_comname2/$NEWNAME_comname2}" + ################### # VALIDITY CHECKS # ################### @@ -51,23 +61,12 @@ if [[ -z "$OLDNAME_sciname" ]]; then exit 1 fi -echo "This script will change the identification $OLDNAME from $OLDNAME_comname to $NEWNAME_comname" +echo "This script will change the identification $OLDNAME from $OLDNAME_comname to ${NEWNAME#*_}" ######################## # EXECUTE : MOVE FILES # ######################## -# Extract the part before the _ from $NEWNAME -NEWNAME_comname="${NEWNAME#*_}" -NEWNAME_sciname="${NEWNAME%%_*}" - -# Replace spaces with underscores -NEWNAME_comname2="${NEWNAME_comname// /_}" -OLDNAME_comname2="${OLDNAME_comname// /_}" - -# Replace OLDNAME_comname2 with NEWNAME_comname2 in OLDNAME -NEWNAME_filename="${OLDNAME//$OLDNAME_comname2/$NEWNAME_comname2}" - # Check if the file exists FILE_PATH="$HOME/BirdSongs/Extracted/By_Date/$OLDNAME_date/$OLDNAME_comname2/$OLDNAME" if [[ -f $FILE_PATH ]]; then