mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-17 11:30:32 +02:00
Update changeidenfication.sh
This commit is contained in:
@@ -1,31 +1,46 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Check if there are at least 2 arguments
|
# This scripts allows to change the identification of a Birdnet-pi detection
|
||||||
if [ $$ -lt 2 ]; then
|
|
||||||
echo "This script requires at least two arguments!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set +u #avoid error with apprise variables
|
set +u #avoid error with apprise variables
|
||||||
|
|
||||||
|
#################
|
||||||
|
# SET VARIABLES #
|
||||||
|
#################
|
||||||
|
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
source /etc/birdnet/birdnet.conf
|
source /etc/birdnet/birdnet.conf
|
||||||
|
OLDNAME="" #OLDNAME="Mésange_charbonnière-78-2024-05-02-birdnet-RTSP_1-18:14:08.mp3"
|
||||||
#OLDNAME="Mésange_charbonnière-78-2024-05-02-birdnet-RTSP_1-18:14:08.mp3"
|
NEWNAME="" #NEWNAME="Lapinus atricapilla_Lapinu à tête noire"
|
||||||
#NEWNAME="Lapinus atricapilla_Lapinu à tête noire"
|
|
||||||
OLDNAME=""
|
|
||||||
NEWNAME=""
|
|
||||||
OLDNAME="$1"
|
OLDNAME="$1"
|
||||||
NEWNAME="$2"
|
NEWNAME="$2"
|
||||||
LABELS_FILE="$HOME/BirdNET-Pi/model/labels.txt"
|
LABELS_FILE="$HOME/BirdNET-Pi/model/labels.txt"
|
||||||
DB_FILE="$HOME/BirdNET-Pi/scripts/birds.db"
|
DB_FILE="$HOME/BirdNET-Pi/scripts/birds.db"
|
||||||
DETECTIONS_TABLE="detections"
|
DETECTIONS_TABLE="detections"
|
||||||
|
|
||||||
|
###################
|
||||||
|
# VALIDITY CHECKS #
|
||||||
|
###################
|
||||||
|
|
||||||
|
# Check if arguments are valid
|
||||||
|
if [[ "$1" != *".mp3" ]]; then
|
||||||
|
echo "The first argument should be a filename starting with the common name of the bird and finishing by mp3!"
|
||||||
|
exit 1
|
||||||
|
elif [[ "$2" != *"_"* ]]; then
|
||||||
|
echo "The second argument should be in the format : \"scientific name_common name\""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if $NEWNAME is found in the file $LABELS_FILE
|
# Check if $NEWNAME is found in the file $LABELS_FILE
|
||||||
if ! grep -q "$NEWNAME" "$LABELS_FILE"; then
|
if ! grep -q "$NEWNAME" "$LABELS_FILE"; then
|
||||||
echo "Error: $NEWNAME not found in $LABELS_FILE"
|
echo "Error: $NEWNAME not found in $LABELS_FILE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##################
|
||||||
|
# EXECUTE SCRIPT #
|
||||||
|
##################
|
||||||
|
|
||||||
# Get the line where the column "File_Name" matches exactly $OLDNAME
|
# Get the line where the column "File_Name" matches exactly $OLDNAME
|
||||||
IFS='|' read -r OLDNAME_sciname OLDNAME_comname OLDNAME_date < <(sqlite3 "$DB_FILE" "SELECT Sci_Name, Com_Name, Date FROM $DETECTIONS_TABLE WHERE File_Name = '$OLDNAME';")
|
IFS='|' read -r OLDNAME_sciname OLDNAME_comname OLDNAME_date < <(sqlite3 "$DB_FILE" "SELECT Sci_Name, Com_Name, Date FROM $DETECTIONS_TABLE WHERE File_Name = '$OLDNAME';")
|
||||||
|
|
||||||
@@ -36,6 +51,10 @@ 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_comname"
|
||||||
|
|
||||||
|
########################
|
||||||
|
# EXECUTE : MOVE FILES #
|
||||||
|
########################
|
||||||
|
|
||||||
# Extract the part before the _ from $NEWNAME
|
# Extract the part before the _ from $NEWNAME
|
||||||
NEWNAME_comname="${NEWNAME#*_}"
|
NEWNAME_comname="${NEWNAME#*_}"
|
||||||
NEWNAME_sciname="${NEWNAME%%_*}"
|
NEWNAME_sciname="${NEWNAME%%_*}"
|
||||||
@@ -63,6 +82,10 @@ else
|
|||||||
echo "Error: File $FILE_PATH does not exist"
|
echo "Error: File $FILE_PATH does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
###################################
|
||||||
|
# EXECUTE : UPDATE DATABASE FILES #
|
||||||
|
###################################
|
||||||
|
|
||||||
# Update the database
|
# Update the database
|
||||||
sqlite3 "$DB_FILE" "UPDATE $DETECTIONS_TABLE SET Sci_Name = '$NEWNAME_sciname', Com_Name = '$NEWNAME_comname', File_Name = '$NEWNAME_filename' WHERE File_Name = '$OLDNAME';"
|
sqlite3 "$DB_FILE" "UPDATE $DETECTIONS_TABLE SET Sci_Name = '$NEWNAME_sciname', Com_Name = '$NEWNAME_comname', File_Name = '$NEWNAME_filename' WHERE File_Name = '$OLDNAME';"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user