diff --git a/scripts/common.php b/scripts/common.php index 71fb692..fc05fcd 100644 --- a/scripts/common.php +++ b/scripts/common.php @@ -93,32 +93,12 @@ function debug_log($message) { function get_com_en_name($sci_name) { if (!isset($_labels_flickr)) { - $_labels_flickr = file(get_home() . "/BirdNET-Pi/model/labels_flickr.txt"); - } - $engname = null; - foreach ($_labels_flickr as $label) { - if (trim(explode("_", $label)[0]) === $sci_name) { - $engname = trim(explode("_", $label)[1]); - break; - } + $_labels_flickr = json_decode(file_get_contents(get_home() . "/BirdNET-Pi/model/l18n/labels_en.json"), true); } + $engname = $_labels_flickr[$sci_name]; return $engname; } -function get_sci_name($com_name) { - if (!isset($_labels)) { - $_labels = file(get_home() . "/BirdNET-Pi/model/labels.txt"); - } - $sciname = null; - foreach ($_labels as $label) { - if (trim(explode("_", $label)[1]) === $com_name) { - $sciname = trim(explode("_", $label)[0]); - break; - } - } - return $sciname; -} - function get_label($record, $sort_by, $date=null) { $name = $record["Com_Name"]; if ($sort_by == "confidence") { diff --git a/scripts/play.php b/scripts/play.php index 6aa3d54..1b52079 100644 --- a/scripts/play.php +++ b/scripts/play.php @@ -639,8 +639,9 @@ echo " $statement2 = $db->prepare("SELECT * FROM detections where File_name == \"$name\" ORDER BY Date DESC, Time DESC"); ensure_db_ok($statement2); $result2 = $statement2->execute(); - $comname = str_replace("_", " ", strtok($name, '-')); - $sciname = get_sci_name($comname); + $results = $result2->fetchArray(SQLITE3_ASSOC); + $sciname = $results['Sci_Name']; + $result2->reset(); $info_url = get_info_url($sciname); $url = $info_url['URL']; echo "
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh index 2c80db3..01b809c 100755 --- a/scripts/update_birdnet_snippets.sh +++ b/scripts/update_birdnet_snippets.sh @@ -253,10 +253,10 @@ AUTH=$(grep basicauth /etc/caddy/Caddyfile) [ -n "${CADDY_PWD}" ] && [ -z "${AUTH}" ] && sudo /usr/local/bin/update_caddyfile.sh > /dev/null 2>&1 set -x -if ! [ -L $HOME/BirdNET-Pi/model/labels_flickr.txt ]; then - sudo_with_user ln -sf labels_nm/labels_en.txt $HOME/BirdNET-Pi/model/labels_flickr.txt +if [ -L $HOME/BirdNET-Pi/model/labels_flickr.txt ]; then + rm $HOME/BirdNET-Pi/model/labels_flickr.txt fi -if ! [ -L $HOME/BirdNET-Pi/model/labels.txt ]; then +if [ -L $HOME/BirdNET-Pi/model/labels.txt ]; then sudo_with_user install_language_label.sh fi