From c6415ee90dd3af8b65f736721435a7e9f7a06b9c Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:13:35 -0400 Subject: [PATCH 1/7] adding a
to the bottom of overview --- scripts/overview.php | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/overview.php b/scripts/overview.php index d045fcb..8673a85 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -312,6 +312,7 @@ echo ""; ?>
+
From 27f217d067a959e644d39b480a66fae0277ad2a6 Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:54:48 -0400 Subject: [PATCH 2/7] better formatting --- scripts/advanced.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/advanced.php b/scripts/advanced.php index 32d5c6b..4ac18a1 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -319,13 +319,14 @@ foreach($formats as $format){
-

These allow you to show a custom image on the Overview page of your BirdNET-Pi. This can be used to show a dynamically updating picture of your garden, for example.



+

These allow you to show a custom image on the Overview page of your BirdNET-Pi. This can be used to show a dynamically updating picture of your garden, for example.

+

BirdNET-Lite Settings

From f532e9cabe4f624e30aeb047745785864dd1d899 Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:54:48 -0400 Subject: [PATCH 3/7] better Advanced Settings formatting and explanations --- scripts/advanced.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/advanced.php b/scripts/advanced.php index 32d5c6b..e42af45 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -313,19 +313,22 @@ foreach($formats as $format){

The BirdNET-Pi URL is how the main page will be reached. If you want your installation to respond to an IP address, place that here, but be sure to indicate "http://".
Example for IP: http://192.168.0.109
Example if you own your own domain: https://virginia.birdnetpi.com

>
+

This allows you to quiet the display of how many commits your installation is behind by relative to the Github repo. This number appears next to "Tools" when you're 50 or more commits behind.

>
+

This allows you to remove the axes and labels of the spectrograms that are generated by Sox for each detection for a cleaner appearance.


-

These allow you to show a custom image on the Overview page of your BirdNET-Pi. This can be used to show a dynamically updating picture of your garden, for example.



+

These allow you to show a custom image on the Overview page of your BirdNET-Pi. This can be used to show a dynamically updating picture of your garden, for example.

+

BirdNET-Lite Settings

From fbed94e2090e2e55751bb6ac87395c6170d940ba Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Wed, 15 Mar 2023 18:42:15 -0400 Subject: [PATCH 4/7] Blacklist Flickr images from the web interface --- scripts/overview.php | 60 ++++++++++++++++++++++++++++++++--- scripts/todays_detections.php | 34 ++++++++++++++++---- 2 files changed, 83 insertions(+), 11 deletions(-) diff --git a/scripts/overview.php b/scripts/overview.php index 8673a85..c213a22 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -37,6 +37,33 @@ if(isset($_GET['custom_image'])){ die(); } +if(isset($_GET['blacklistimage'])) { + if(isset($_SERVER['PHP_AUTH_USER'])) { + $submittedpwd = $_SERVER['PHP_AUTH_PW']; + $submitteduser = $_SERVER['PHP_AUTH_USER']; + if($submittedpwd == $config['CADDY_PWD'] && $submitteduser == 'birdnet'){ + + $imageid = $_GET['blacklistimage']; + $file_handle = fopen($home."/BirdNET-Pi/scripts/blacklisted_images.txt", 'a+'); + fwrite($file_handle, $imageid . "\n"); + fclose($file_handle); + unset($_SESSION['images']); + die("OK"); + } else { + header('WWW-Authenticate: Basic realm="My Realm"'); + header('HTTP/1.0 401 Unauthorized'); + echo 'You must be authenticated.'; + exit; + } + } else { + header('WWW-Authenticate: Basic realm="My Realm"'); + header('HTTP/1.0 401 Unauthorized'); + echo 'You must be authenticated.'; + exit; + } + +} + if(isset($_GET['fetch_chart_string']) && $_GET['fetch_chart_string'] == "true") { $myDate = date('Y-m-d'); $chart = "Combo-$myDate.png"; @@ -107,17 +134,21 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse } } - // Make the API call + // Read the blacklisted image ids from the file into an array + $blacklisted_ids = array_map('trim', file($home."/BirdNET-Pi/scripts/blacklisted_images.txt")); + + // Make the API call $flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=".str_replace(" ", "%20", $engname).$comnameprefix."&sort=relevance".$args."&per_page=5&media=photos&format=json&nojsoncallback=1"), true)["photos"]["photo"]; - // Find the first photo that is not blacklisted + // Find the first photo that is not blacklisted or is not the specific blacklisted id $photo = null; foreach ($flickrjson as $flickrphoto) { - if ($flickrphoto["id"] !== "4892923285") { + if ($flickrphoto["id"] !== "4892923285" && !in_array($flickrphoto["id"], $blacklisted_ids)) { $photo = $flickrphoto; break; } } + $modaltext = "https://flickr.com/photos/".$photo["owner"]."/".$photo["id"]; $authorlink = "https://flickr.com/people/".$photo["owner"]; $imageurl = 'https://farm' .$photo["farm"]. '.static.flickr.com/' .$photo["server"]. '/' .$photo["id"]. '_' .$photo["secret"]. '.jpg'; @@ -254,15 +285,18 @@ body::-webkit-scrollbar {

- +

+
diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php index 495e0f2..4a86499 100644 --- a/scripts/todays_detections.php +++ b/scripts/todays_detections.php @@ -264,13 +264,16 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { break; } } + // Read the blacklisted image ids from the file into an array + $blacklisted_ids = array_map('trim', file($home."/BirdNET-Pi/scripts/blacklisted_images.txt")); + // Make the API call $flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=".str_replace(" ", "%20", $engname).$comnameprefix."&sort=relevance".$args."&per_page=5&media=photos&format=json&nojsoncallback=1"), true)["photos"]["photo"]; - // Find the first photo that is not blacklisted + // Find the first photo that is not blacklisted or is not the specific blacklisted id $photo = null; foreach ($flickrjson as $flickrphoto) { - if ($flickrphoto["id"] !== "4892923285") { + if ($flickrphoto["id"] !== "4892923285" && !in_array($flickrphoto["id"], $blacklisted_ids)) { $photo = $flickrphoto; break; } @@ -378,16 +381,19 @@ die();
- +

- + +
From 865fba64f2cd716dc22d56f98e33f407bcc0edf0 Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Thu, 16 Mar 2023 13:50:49 -0400 Subject: [PATCH 5/7] Add license URL to Flickr images --- scripts/overview.php | 27 +++++++++++++++++++++++---- scripts/todays_detections.php | 33 ++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/scripts/overview.php b/scripts/overview.php index c213a22..c2f62bd 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -84,6 +84,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse } $iterations = 0; $lines; + $licenses_urls = array(); // hopefully one of the 5 most recent detections has an image that is valid, we'll use that one as the most recent detection until the newer ones get their images created while($mostrecent = $result4->fetchArray(SQLITE3_ASSOC)) { $comname = preg_replace('/ /', '_', $mostrecent['Com_Name']); @@ -122,6 +123,19 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse if($key !== false) { $image = $_SESSION['images'][$key]; } else { + // Get license information if we haven't already + if (empty($licenses_urls)) { + $licenses_url = "https://api.flickr.com/services/rest/?method=flickr.photos.licenses.getInfo&api_key=".$config["FLICKR_API_KEY"]."&format=json&nojsoncallback=1"; + $licenses_response = file_get_contents($licenses_url); + $licenses_data = json_decode($licenses_response, true)["licenses"]["license"]; + foreach ($licenses_data as $license) { + $license_id = $license["id"]; + $license_name = $license["name"]; + $license_url = $license["url"]; + $licenses_urls[$license_id] = $license_url; + } + } + // only open the file once per script execution if(!isset($lines)) { $lines = file($home."/BirdNET-Pi/model/labels_flickr.txt"); @@ -149,10 +163,15 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse } } + $license_url = "https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=".$config["FLICKR_API_KEY"]."&photo_id=".$photo["id"]."&format=json&nojsoncallback=1"; + $license_response = file_get_contents($license_url); + $license_info = json_decode($license_response, true)["photo"]["license"]; + $license_url = $licenses_urls[$license_info]; + $modaltext = "https://flickr.com/photos/".$photo["owner"]."/".$photo["id"]; $authorlink = "https://flickr.com/people/".$photo["owner"]; $imageurl = 'https://farm' .$photo["farm"]. '.static.flickr.com/' .$photo["server"]. '/' .$photo["id"]. '_' .$photo["secret"]. '.jpg'; - array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink)); + array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink, $license_url)); $image = $_SESSION['images'][count($_SESSION['images'])-1]; } } @@ -182,7 +201,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
0) { ?> - +
@@ -323,9 +342,9 @@ body::-webkit-scrollbar { } - function setModalText(iter, title, text, authorlink, photolink) { + function setModalText(iter, title, text, authorlink, photolink, licenseurl) { document.getElementById('modalHeading').innerHTML = "Photo: \""+decodeURIComponent(title.replaceAll("+"," "))+"\" Attribution"; - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
"; + document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; last_photo_link = text; showDialog(); } diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php index 4a86499..2a91ba2 100644 --- a/scripts/todays_detections.php +++ b/scripts/todays_detections.php @@ -213,6 +213,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { } $iterations = 0; $lines; + $licenses_urls = array(); if (file_exists('./scripts/thisrun.txt')) { $config = parse_ini_file('./scripts/thisrun.txt'); @@ -221,7 +222,6 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { } - while($todaytable=$result0->fetchArray(SQLITE3_ASSOC)) { $iterations++; @@ -253,6 +253,19 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { if($key !== false) { $image = $_SESSION['images'][$key]; } else { + // Get license information if we haven't already + if (empty($licenses_urls)) { + $licenses_url = "https://api.flickr.com/services/rest/?method=flickr.photos.licenses.getInfo&api_key=".$config["FLICKR_API_KEY"]."&format=json&nojsoncallback=1"; + $licenses_response = file_get_contents($licenses_url); + $licenses_data = json_decode($licenses_response, true)["licenses"]["license"]; + foreach ($licenses_data as $license) { + $license_id = $license["id"]; + $license_name = $license["name"]; + $license_url = $license["url"]; + $licenses_urls[$license_id] = $license_url; + } + } + // only open the file once per script execution if(!isset($lines)) { $lines = file($home."/BirdNET-Pi/model/labels_flickr.txt"); @@ -278,10 +291,16 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { break; } } + + $license_url = "https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=".$config["FLICKR_API_KEY"]."&photo_id=".$photo["id"]."&format=json&nojsoncallback=1"; + $license_response = file_get_contents($license_url); + $license_info = json_decode($license_response, true)["photo"]["license"]; + $license_url = $licenses_urls[$license_info]; + $modaltext = "https://flickr.com/photos/".$photo["owner"]."/".$photo["id"]; $authorlink = "https://flickr.com/people/".$photo["owner"]; $imageurl = 'https://farm' .$photo["farm"]. '.static.flickr.com/' .$photo["server"]. '/' .$photo["id"]. '_' .$photo["secret"]. '.jpg'; - array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink)); + array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink, $license_url)); $image = $_SESSION['images'][count($_SESSION['images'])-1]; } } @@ -293,7 +312,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
0) { ?> - +
@@ -308,7 +327,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
0) { ?> - +
@@ -420,12 +439,12 @@ die(); } - function setModalText(iter, title, text, authorlink, photolink) { + function setModalText(iter, title, text, authorlink, photolink, licenseurl) { document.getElementById('modalHeading').innerHTML = "Photo: \""+decodeURIComponent(title.replaceAll("+"," "))+"\" Attribution"; - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
"; + document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
"; + document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; last_photo_link = text; showDialog(); From c7151427add282b38b0f7d8bbf0c6ce6ac1de86f Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Thu, 16 Mar 2023 18:48:34 -0400 Subject: [PATCH 6/7] Change default Apprise notification body text Co-Authored-By: Bee Ostrowsky --- birdnet.conf-defaults | 2 +- scripts/install_config.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults index 8cc19f0..d2cacea 100644 --- a/birdnet.conf-defaults +++ b/birdnet.conf-defaults @@ -71,7 +71,7 @@ RTSP_STREAM= #----------------------- Apprise Miscellanous Configuration -------------------# APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection" -APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence" +APPRISE_NOTIFICATION_BODY="A \$comname (\$sciname) was just detected with a confidence of \$confidence" APPRISE_NOTIFY_EACH_DETECTION=0 APPRISE_NOTIFY_NEW_SPECIES=0 APPRISE_WEEKLY_REPORT=1 diff --git a/scripts/install_config.sh b/scripts/install_config.sh index f60c077..e6dc4c4 100755 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -99,7 +99,7 @@ RTSP_STREAM= #----------------------- Apprise Miscellanous Configuration -------------------# APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection" -APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence" +APPRISE_NOTIFICATION_BODY="A \$comname (\$sciname) was just detected with a confidence of \$confidence" APPRISE_NOTIFY_EACH_DETECTION=0 APPRISE_NOTIFY_NEW_SPECIES=0 APPRISE_WEEKLY_REPORT=1 From 61a67c517e0fa037eee239fee8cc84812fda7154 Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Fri, 17 Mar 2023 17:05:09 -0400 Subject: [PATCH 7/7] Wrap CUSTOM_IMAGE_TITLE in quotes --- scripts/advanced.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/advanced.php b/scripts/advanced.php index e42af45..e225442 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -222,8 +222,8 @@ if(isset($_GET['submit'])) { if(isset($_GET["custom_image_label"])) { $custom_image_label = $_GET["custom_image_label"]; if(strcmp($custom_image_label,$config['CUSTOM_IMAGE_TITLE']) !== 0) { - $contents = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=$custom_image_label", $contents); - $contents2 = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=$custom_image_label", $contents2); + $contents = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=\"$custom_image_label\"", $contents); + $contents2 = preg_replace("/CUSTOM_IMAGE_TITLE=.*/", "CUSTOM_IMAGE_TITLE=\"$custom_image_label\"", $contents2); } }