diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults index 2b6f9f3..e75cda1 100644 --- a/birdnet.conf-defaults +++ b/birdnet.conf-defaults @@ -62,6 +62,10 @@ APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection" APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence" APPRISE_NOTIFY_EACH_DETECTION=false +#---------------------- Flickr Images API Configuration -----------------------# + +FLICKR_API_KEY= + ################################################################################ #-------------------------------- Defaults ----------------------------------# ################################################################################ diff --git a/homepage/style.css b/homepage/style.css index 91547b0..0eed7bc 100644 --- a/homepage/style.css +++ b/homepage/style.css @@ -585,4 +585,36 @@ tr { input { box-shadow: 0px 0px 17px 1px rgba(0, 0, 0, 0.10); } - +dialog { + border:none; +} +dialog::backdrop { + background: repeating-linear-gradient( + 30deg, + rgba(24, 194, 236, 0.2), + rgba(24, 194, 236, 0.2) 1px, + rgba(24, 194, 236, 0.3) 1px, + rgba(24, 194, 236, 0.3) 20px + ); + backdrop-filter: blur(1px) +} +.centered_image_container { + font-size:19px !important; + display:inline-block; + position:relative; + margin-bottom:3px; +} +.centered_image_container img.img1 { + cursor:pointer; + height:95%; + position:absolute; + right:110%; + top:0px; + border-radius: 5px; +} +.centered_image_container * { + font-size:19px !important; +} +.centered_image_container form { + margin-bottom:0px; +} \ No newline at end of file diff --git a/scripts/config.php b/scripts/config.php index b925780..cabaa7e 100644 --- a/scripts/config.php +++ b/scripts/config.php @@ -10,6 +10,7 @@ $birdweather_id = $_GET["birdweather_id"]; $apprise_input = $_GET['apprise_input']; $apprise_notification_title = $_GET['apprise_notification_title']; $apprise_notification_body = $_GET['apprise_notification_body']; +$flickr_api_key = $_GET['flickr_api_key']; if(isset($_GET['apprise_notify_each_detection'])) { $apprise_notify_each_detection = 1; } else { @@ -45,6 +46,7 @@ $contents = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id" $contents = preg_replace("/APPRISE_NOTIFICATION_TITLE=.*/", "APPRISE_NOTIFICATION_TITLE=\"$apprise_notification_title\"", $contents); $contents = preg_replace("/APPRISE_NOTIFICATION_BODY=.*/", "APPRISE_NOTIFICATION_BODY=\"$apprise_notification_body\"", $contents); $contents = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents); +$contents = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents); $contents2 = file_get_contents("./scripts/thisrun.txt"); @@ -54,6 +56,8 @@ $contents2 = preg_replace("/BIRDWEATHER_ID=.*/", "BIRDWEATHER_ID=$birdweather_id $contents2 = preg_replace("/APPRISE_NOTIFICATION_TITLE=.*/", "APPRISE_NOTIFICATION_TITLE=\"$apprise_notification_title\"", $contents2); $contents2 = preg_replace("/APPRISE_NOTIFICATION_BODY=.*/", "APPRISE_NOTIFICATION_BODY=\"$apprise_notification_body\"", $contents2); $contents2 = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents2); +$contents2 = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents2); + $fh = fopen("/etc/birdnet/birdnet.conf", "w"); $fh2 = fopen("./scripts/thisrun.txt", "w"); @@ -144,6 +148,10 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
>

+

Bird Photos from Flickr

+ +
+

Set your Flickr API key to enable the display of bird images next to detections. Get your free key here.

Localization

-
- -
Confidence:
- - +
+ + + +
+ +
+ +
Confidence:

+ +
+ +

+

+ +
+
+ +

+

+ +
+

Choose a species to load images from Wikimedia Commons.

+?>

Choose a species to load images from Flickr.

fetchArray(SQLITE3_ASSOC)){ $count = $results['COUNT(*)']; $maxconf = round($results['MAX(Confidence)'],2); @@ -147,20 +170,19 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){ -

Loading Images from Wikimedia Commons

", '6096'); +

Loading Images from Flickr

", '6096'); echo ""; ob_flush(); flush(); - $imagelink = "https://commons.wikimedia.org/w/index.php?search=$linkname&title=Special:MediaSearch&go=Go&type=image"; - $homepage = file_get_contents($imagelink); - preg_match_all("{}ims", $homepage, $matches, PREG_SET_ORDER); - foreach ($matches as $val) { - $pos = strpos($val[2],"/"); - $link = substr($val[2],1,-1); - if($pos !== 1 && strpos($link, "upload") == true && strpos($link, "CentralAutoLogin") == false) - echo ""; + $flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=2158f6c5d66e89778bd0d340953f1bcf&text=\"".str_replace('_', '+', $comname)."\"&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"]; + foreach ($flickrjson as $val) { + $iter++; + $modaltext = "https://flickr.com/photos/".$val["owner"]."/".$val["id"]; + $authorlink = "https://flickr.com/people/".$val["owner"]; + $imageurl = 'http://farm' .$val["farm"]. '.static.flickr.com/' .$val["server"]. '/' .$val["id"]. '_' .$val["secret"]. '.jpg'; + echo "".$iter.""; } } } diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php index d2f5cfe..6daea3a 100644 --- a/scripts/todays_detections.php +++ b/scripts/todays_detections.php @@ -77,7 +77,15 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { ?> fetchArray(SQLITE3_ASSOC)) { $iterations++; @@ -86,13 +94,35 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { $comname = preg_replace('/\'/', '_', $comname); $filename = "/By_Date/".date('Y-m-d')."/".$comname."/".$todaytable['File_Name']; $sciname = preg_replace('/ /', '_', $todaytable['Sci_Name']); + + if (!empty($config["FLICKR_API_KEY"])) { + // if we already searched flickr for this species before, use the previous image rather than doing an unneccesary api call + $key = array_search($comname, array_column($images, 0)); + if($key !== false) { + $image = $images[$key]; + } else { + $flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=".$comname."&license=7%2C9%2C10&sort=relevance&per_page=5&orientation=landscape,square&format=json&nojsoncallback=1"), true)["photos"]["photo"][0]; + $modaltext = "https://flickr.com/photos/".$flickrjson["owner"]."/".$flickrjson["id"]; + $authorlink = "https://flickr.com/people/".$flickrjson["owner"]; + $imageurl = 'http://farm' .$flickrjson["farm"]. '.static.flickr.com/' .$flickrjson["server"]. '/' .$flickrjson["id"]. '_' .$flickrjson["secret"]. '.jpg'; + array_push($images, array($comname,$imageurl,$flickrjson["title"], $modaltext, $authorlink)); + $image = $images[count($images)-1]; + } + } ?> - @@ -132,6 +162,29 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
+ +

+

+ +
+

Number of Detections


+
+ +
+ + + + +


- Confidence:
+ Confidence:

diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh index eea92dc..0082ca2 100755 --- a/scripts/update_birdnet_snippets.sh +++ b/scripts/update_birdnet_snippets.sh @@ -50,3 +50,6 @@ if grep bash $HOME/BirdNET-Pi/templates/web_terminal.service;then sudo systemctl restart web_terminal.service fi [ -L ~/BirdSongs/Extracted/static ] || ln -sf ~/BirdNET-Pi/homepage/static ~/BirdSongs/Extracted +if ! grep FLICKR_API_KEY /etc/birdnet/birdnet.conf &>/dev/null;then + sudo -u$USER echo "FLICKR_API_KEY=" >> /etc/birdnet/birdnet.conf +fi