A live bird collage card for your Home Assistant dashboard.
saving changes
mcguirepr8910090f9411e1
diff --git a/scripts/birdnet_analysis.sh b/scripts/birdnet_analysis.shindex dbf0e81a..acc0a47f 100755--- a/scripts/birdnet_analysis.sh+++ b/scripts/birdnet_analysis.sh@@ -166,9 +166,9 @@ run_analysis() {--lon "${LONGITUDE}" \--week "${WEEK}" \--overlap "${OVERLAP}" \- --sensitivity "${SENSITIVITY}" \+ --sensitivity "${SENSITIVITY}" \--min_conf "${CONFIDENCE}" \- --include_list "${INCLUDE_LIST}"+ --include_list "${INCLUDE_LIST}"elif [ -f ${1}/${i} ] && [ ! -f ${INCLUDE_LIST} ] && [ -f ${EXCLUDE_LIST} ] && [ -z $BIRDWEATHER_ID ];thenecho "analyze.py \--i "${1}/${i}" \@@ -187,9 +187,9 @@ run_analysis() {--lon "${LONGITUDE}" \--week "${WEEK}" \--overlap "${OVERLAP}" \- --sensitivity "${SENSITIVITY}" \+ --sensitivity "${SENSITIVITY}" \--min_conf "${CONFIDENCE}" \- --exclude_list "${EXCLUDE_LIST}"+ --exclude_list "${EXCLUDE_LIST}"elif [ -f ${1}/${i} ] && [ -f ${INCLUDE_LIST} ] && [ -f ${EXCLUDE_LIST} ] && [ -z $BIRDWEATHER_ID ];thenecho "analyze.py \--i "${1}/${i}" \@@ -209,7 +209,7 @@ run_analysis() {--lon "${LONGITUDE}" \--week "${WEEK}" \--overlap "${OVERLAP}" \- --sensitivity "${SENSITIVITY}" \+ --sensitivity "${SENSITIVITY}" \--min_conf "${CONFIDENCE}" \--include_list "${INCLUDE_LIST}" \--exclude_list "${EXCLUDE_LIST}"@@ -231,7 +231,7 @@ run_analysis() {--lon "${LONGITUDE}" \--week "${WEEK}" \--overlap "${OVERLAP}" \- --sensitivity "${SENSITIVITY}" \+ --sensitivity "${SENSITIVITY}" \--min_conf "${CONFIDENCE}" \--birdweather_id "${BIRDWEATHER_ID}"elif [ -f ${1}/${i} ] && [ -f ${INCLUDE_LIST} ] && [ ! -f ${EXCLUDE_LIST} ] && [ ! -z $BIRDWEATHER_ID ];then@@ -253,7 +253,7 @@ run_analysis() {--lon "${LONGITUDE}" \--week "${WEEK}" \--overlap "${OVERLAP}" \- --sensitivity "${SENSITIVITY}" \+ --sensitivity "${SENSITIVITY}" \--min_conf "${CONFIDENCE}" \--include_list "${INCLUDE_LIST}" \--birdweather_id "${BIRDWEATHER_ID}"@@ -276,7 +276,7 @@ run_analysis() {--lon "${LONGITUDE}" \--week "${WEEK}" \--overlap "${OVERLAP}" \- --sensitivity "${SENSITIVITY}" \+ --sensitivity "${SENSITIVITY}" \--min_conf "${CONFIDENCE}" \--exclude_list "${EXCLUDE_LIST}" \--birdweather_id "${BIRDWEATHER_ID}"@@ -300,7 +300,7 @@ run_analysis() {--lon "${LONGITUDE}" \--week "${WEEK}" \--overlap "${OVERLAP}" \- --sensitivity "${SENSITIVITY}" \+ --sensitivity "${SENSITIVITY}" \--min_conf "${CONFIDENCE}" \--include_list "${INCLUDE_LIST}" \--exclude_list "${EXCLUDE_LIST}" \diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.shindex 7c8498cf..1eba83bb 100755--- a/scripts/clear_all_data.sh+++ b/scripts/clear_all_data.sh@@ -60,6 +60,7 @@ sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/overview.php ${EXTRACTED}sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/stats.php ${EXTRACTED}sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED}sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/history.php ${EXTRACTED}+sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/play.php ${EXTRACTED}sudo -u ${USER} ln -fs $(dirname ${my_dir})/homepage/images/favicon.ico ${EXTRACTED}sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}sudo -u ${USER} cp -f $(dirname ${my_dir})/templates/phpsysinfo.ini ${HOME}/phpsysinfo/diff --git a/scripts/config.php b/scripts/config.phpindex 8bc9a39d..4b950fef 100644--- a/scripts/config.php+++ b/scripts/config.php@@ -12,7 +12,7 @@ ini_set('display_errors',1);<body><div class="row"><div class="column first">- <form action="write_config.php" method="POST" name="normal">+ <form action="" method="POST"><?phpif (file_exists('/home/pi/BirdNET-Pi/thisrun.txt')) {$config = parse_ini_file('/home/pi/BirdNET-Pi/thisrun.txt');@@ -66,20 +66,16 @@ if (file_exists('/home/pi/BirdNET-Pi/thisrun.txt')) {<option value="labels_uk.txt">Ukrainian</option></select><br><br>- <button type="submit" name="normal" class="block"><?php-if(isset($_SESSION['success'])){+ <button type="submit" name="view" value="Settings"><?php+if(isset($_POST['status'])){echo "Success!";- unset($_SESSION['success']);} else {echo "Update Settings";}?></button></form>- <form action="advanced.php" class="form2">- <button type="submit" class="block">Advanced Settings</button>- </form>- <form action="index.html" class="form2">- <button type="submit" class="block">Tools</button>+ <form action="" method="POST">+ <button type="submit" name="view" value="Advanced">Advanced Settings</button></form></div></div>diff --git a/scripts/overview.php b/scripts/overview.phpindex d95a8a8a..e67161be 100644--- a/scripts/overview.php+++ b/scripts/overview.php@@ -28,7 +28,7 @@ if($statement2 == False) {$result2 = $statement2->execute();$todaycount = $result2->fetchArray(SQLITE3_ASSOC);-$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')');+$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == Date(\'now\', \'localtime\') AND TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')');if($statement3 == False) {echo "Database is busy";header("refresh: 0;");@@ -78,9 +78,13 @@ $speciestally = $result5->fetchArray(SQLITE3_ASSOC);</tr><tr><td><?php echo $totalcount['COUNT(*)'];?></td>- <td><a href="/By_Date/<?php echo date('Y-m-d');?>"/><?php echo $todaycount['COUNT(*)'];?></a></td>+ <form action="" method="POST">+ <td><input type="hidden" name="view" value="Extractions"><button type="submit" name="date" value="<?php echo date('Y-m-d');?>"><?php echo $todaycount['COUNT(*)'];?></button></td>+ </form><td><?php echo $hourcount['COUNT(*)'];?></td>- <td><a href="/stats.php"/><?php echo $speciestally['COUNT(DISTINCT(Com_Name))'];?></a></td>+ <form action="" method="POST">+ <td><button type="submit" name="view" value="Species Stats"><?php echo $speciestally['COUNT(DISTINCT(Com_Name))'];?></button></td>+ </form></tr></table></div>@@ -88,19 +92,23 @@ $speciestally = $result5->fetchArray(SQLITE3_ASSOC);<table><tr>- <th</th>- <th>Scientific Name</th>- <th>Common Name</th>- <th>Listen</th>- <th>Confidence</th>+ <th>Most Recent Detection</th>+ <th>Scientific Name</th>+ <th>Common Name</th>+ <th>Listen</th>+ <th>Confidence</th></tr><tr>- <th>Most Recent Detection</th>- <td><a href="https://wikipedia.org/wiki/<?php echo $scilink;?>" target="top"/><?php echo $mostrecent['Sci_Name'];?></a></td>+ <td><?php echo $mostrecent['Date']."<br>".$mostrecent['Time'];?></td>+ <td><a href="https://wikipedia.org/wiki/<?php echo $scilink;?>" target="top"/><?php echo $mostrecent['Sci_Name'];?></a></td><form action="" method="POST">- <td><input type="hidden" name="view" value="Species Stats"><button type="submit" name="species" value="<?php echo $mostrecent['Com_Name'];?>"><?php echo $mostrecent['Com_Name'];?></button></td></form>- <td><?php echo $mostrecent['Date']." ".$mostrecent['Time'];?><br><audio controls><source src="<?php echo $filename;?>"></audio></td>- <td><?php echo $mostrecent['Confidence'];?></td>+ <td>+ <input type="hidden" name="view" value="Species Stats">+ <button type="submit" name="species" value="<?php echo $mostrecent['Com_Name'];?>"><?php echo $mostrecent['Com_Name'];?></button>+ </td>+ </form>+ <td><audio controls><source src="<?php echo $filename;?>"></audio></td>+ <td><?php echo $mostrecent['Confidence'];?></td></tr></table></div>@@ -108,7 +116,7 @@ $speciestally = $result5->fetchArray(SQLITE3_ASSOC);if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart)) {echo "<img src=\"/Charts/$chart?nocache=time()\">";} else {- echo "<p>No Detections For Today</p>";+ echo "<p>No Detections For Today</p>";}?><h2>Currently Analyzing</h2>diff --git a/scripts/play.php b/scripts/play.phpindex 4f50b30d..10239b9a 100644--- a/scripts/play.php+++ b/scripts/play.php@@ -10,24 +10,16 @@ if($db == False){}if(isset($_POST['bydate'])){- $statement = $db->prepare('SELECT DISTINCT(Date), Com_Name from detections GROUP BY Date');+ $statement = $db->prepare('SELECT DISTINCT(Date), Com_Name FROM detections GROUP BY Date');if($statement == False){echo "Database is busy";header("refresh: 0;");}$result = $statement->execute();$view = "bydate";-} elseif(isset($_POST['byspecies'])) {- $statement = $db->prepare('SELECT DISTINCT(Com_Name) from detections ORDER BY Com_Name');- if($statement == False){- echo "Database is busy";- header("refresh: 0;");- }- $result = $statement->execute();- $view = "byspecies";} elseif(isset($_POST['date'])) {$date = $_POST['date'];- $statement = $db->prepare("SELECT DISTINCT(Com_Name) from detections WHERE Date == \"$date\" ORDER BY Com_Name");+ $statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name");if($statement == False){echo "Database is busy";header("refresh: 0;");@@ -36,8 +28,8 @@ if(isset($_POST['bydate'])){$view = "date";} elseif(isset($_POST['species'])) {$species = $_POST['species'];- $statement = $db->prepare("SELECT * from detections WHERE Com_Name == \"$species\" ORDER BY Com_Name");- $statement3 = $db->prepare("SELECT Date, Time, Com_Name, MAX(Confidence), File_Name from detections WHERE Com_Name == \"$species\" ORDER BY Com_Name");+ $statement = $db->prepare("SELECT * FROM detections WHERE Com_Name == \"$species\" ORDER BY Com_Name");+ $statement3 = $db->prepare("SELECT Date, Time, Com_Name, MAX(Confidence), File_Name FROM detections WHERE Com_Name == \"$species\" ORDER BY Com_Name");if($statement == False || $statement3 == False){echo "Database is busy";header("refresh: 0;");@@ -45,8 +37,15 @@ if(isset($_POST['bydate'])){$result = $statement->execute();$result3 = $statement3->execute();$view = "species";+} else {+ $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name');+ if($statement == False){+ echo "Database is busy";+ header("refresh: 0;");+ }+ $result = $statement->execute();+ $view = "byspecies";}-?><html>@@ -57,7 +56,6 @@ if(isset($_POST['bydate'])){</style></head><body>-<div class="column left"><table><?phpif(!isset($_POST['species'])){@@ -67,6 +65,7 @@ while($results=$result->fetchArray(SQLITE3_ASSOC))<tr><form action="" method="POST"><td>+ <input type="hidden" name="view" value="Extractions"><?phpif($view == "bydate"){$date = $results['Date'];@@ -82,23 +81,25 @@ while($results=$result->fetchArray(SQLITE3_ASSOC))$maxconf = $results['MAX(Confidence)'];$date = $results['Date'];$time = $results['Time'];- $comname = preg_replace('/ /', '_', $results['Com_Name']);+ $name = $results['Com_Name'];+ $comname = preg_replace('/ /', '_', $name);+ $comname = preg_replace('/\'/', '', $comname);$file = $results['File_Name'];$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];echo "<table><tr>+ <th>$name</th><th>Max Confidence: $maxconf</th></tr><tr>- <td>Most confident recording: <a href=\"$filename\" target=\"footer\">$file</a></td>+ <th>Most confident recording: </th>+ <td><audio controls><source src=\"$filename\"></audio></td></tr></table>";};};?></td></form></tr></table>-</div>-<div class="column right"><?phpif(isset($_POST['species'])){$name = $_POST['species'];@@ -110,8 +111,8 @@ while($results=$result->fetchArray(SQLITE3_ASSOC))$result2 = $statement2->execute();echo "<table><tr>- <th>Date</th>- <th>Time</th>+ <th>When</th>+ <th>Listen</th><th>Scientific Name</th><th>Common Name</th><th>Confidence</th>@@ -119,24 +120,23 @@ while($results=$result->fetchArray(SQLITE3_ASSOC))while($results=$result2->fetchArray(SQLITE3_ASSOC)){$comname = preg_replace('/ /', '_', $results['Com_Name']);+ $comname = preg_replace('/\'/', '', $comname);$date = $results['Date'];- $comlink = "/By_Date/".$date."/".$comname."/".$results['File_Name'];+ $filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];$sciname = preg_replace('/ /', '_', $results['Sci_Name']);$sci_name = $results['Sci_Name'];$time = $results['Time'];$confidence = $results['Confidence'];echo "<tr>- <td>$date</td>- <td><a href=\"$comlink\" target=\"footer\"/>$time</a></td>+ <td>$date $time</td>+ <td><audio controls><source src=\"$filename\"></audio></td><td><a href=\"https://wikipedia.org/wiki/$sciname\" target=\"top\">$sci_name</a></td>- <form action=\"/stats.php\" method=\"POST\">- <td><button type=\"submit\" name=\"species\" value=\"$name\">$name</button>+ <form action=\"\" method=\"POST\">+ <td><input type=\"hidden\" name=\"view\" value=\"Species Stats\"><button type=\"submit\" name=\"species\" value=\"$name\">$name</button></form></td><td>$confidence</td></tr>";}echo "</table>";}?>-</div>-</div></body></html>diff --git a/scripts/restart_services.sh b/scripts/restart_services.shindex 47526617..cb5384b9 100755--- a/scripts/restart_services.sh+++ b/scripts/restart_services.sh@@ -23,6 +23,6 @@ sudo systemctl restart "${i}"doneuntil grep 5050 <(netstat -tulpn 2>&1);dosudo systemctl restart birdnet_server.service-sleep 30+sleep 45donesudo systemctl restart birdnet_analysis.servicediff --git a/scripts/server.py b/scripts/server.pyindex 39165829..5ca50647 100755--- a/scripts/server.py+++ b/scripts/server.py@@ -349,6 +349,7 @@ def handle_client(conn, addr):Week = str(args.week)Sens = str(args.sensitivity)Overlap = str(args.overlap)+ Com_Name = Com_Name.replate("'", "")File_Name = Com_Name.replace(" ", "_") + '-' + Confidence + '-' + \Date.replace("/", "-") + '-birdnet-' + Time + audiofmtdiff --git a/scripts/spectrogram.php b/scripts/spectrogram.phpindex 248b9f9f..cc324bf8 100644--- a/scripts/spectrogram.php+++ b/scripts/spectrogram.php@@ -1,11 +1,4 @@<?php-if (file_exists('/home/pi/BirdNET-Pi/thisrun.txt')) {- $config = parse_ini_file('/home/pi/BirdNET-Pi/thisrun.txt');-} elseif (file_exists('/home/pi/BirdNET-Pi/firstrun.ini')) {- $config = parse_ini_file('/home/pi/BirdNET-Pi/firstrun.ini');-}-$refreshtime = $config['RECORDING_LENGTH'];-header("refresh:$refreshtime");+$time = time();+echo "<img src=\"/spectrogram.png?nocache=$time\">";?>-<body>-<img src='/spectrogram.png?nocache=<?php echo time();?>'>diff --git a/scripts/stats.php b/scripts/stats.phpindex c534dafa..98989b65 100644--- a/scripts/stats.php+++ b/scripts/stats.php@@ -76,7 +76,6 @@ $filename = "/By_Date/".$results['Date']."/".$comname."/".$results['File_Name'];$species = $_POST['species'];$str = "<div class=\"column second\"><h3>$species</h3>- <h3>Species Stats</h3><table><tr><th>Scientific Name</th>@@ -96,27 +95,29 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){$time = $results['Time'];$name = $results['Com_Name'];$sciname = $results['Sci_Name'];+ $dbsciname = preg_replace('/ /', '_', $sciname);$comname = preg_replace('/ /', '_', $results['Com_Name']);$comname = preg_replace('/\'/', '', $comname);$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];$imagelink = shell_exec("/home/pi/BirdNET-Pi/scripts/get_image.sh $dbsciname");$imagecitation = shell_exec("/home/pi/BirdNET-Pi/scripts/get_citation.sh $dbsciname");- $str= "<tr>+ echo str_pad("<tr><td><a href=\"https://wikipedia.org/wiki/$dbsciname\" target=\"top\"/>$sciname</a></td><td>$count</td><td>$maxconf</td><td>$date $time <audio controls><source src=\"$filename\"></audio></td><td><a href=\"https://allaboutbirds.org/guide/$comname\" target=\"top\"/>All About Birds</a></td></tr>- </table>";- echo str_pad($str, 4096);+ </table>", '4096');ob_flush();flush();- echo "<img class=\"center\" src=\"$imagelink\">+ echo str_pad("<img class=\"center\" src=\"$imagelink\"><pre>$imagecitation</pre></td></div></div>-</div>";+</div>", '4096');+ ob_flush();+ flush();}}?>diff --git a/scripts/viewdb.php b/scripts/viewdb.phpindex 567acc9c..05e5126e 100644--- a/scripts/viewdb.php+++ b/scripts/viewdb.php@@ -3,8 +3,6 @@ ini_set('display_errors', 1);ini_set('display_startup_errors', 1);error_reporting(E_ALL);-header("refresh: 30;");-$db = new SQLite3('/home/pi/BirdNET-Pi/scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);if($db == False){echo "Database is busy";@@ -34,7 +32,7 @@ if($statement2 == False){$result2 = $statement2->execute();$todaycount = $result2->fetchArray(SQLITE3_ASSOC);-$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')');+$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == Date(\'now\', \'localtime\') AND TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')');if($statement3 == False){echo "Database is busy";header("refresh: 0;");@@ -83,15 +81,20 @@ $speciestally = $result5->fetchArray(SQLITE3_ASSOC);</tr><tr><td><?php echo $totalcount['COUNT(*)'];?></td>- <td><a href="/By_Date/<?php echo date('Y-m-d');?>"/><?php echo $todaycount['COUNT(*)'];?></a></td>+ <form action="" method="POST">+ <td><input type="hidden" name="view" value="Extractions"><button type="submit" name="date" value="<?php echo date('Y-m-d');?>"><?php echo $todaycount['COUNT(*)'];?></button></td>+ </form><td><?php echo $hourcount['COUNT(*)'];?></td>- <td><a href="/stats.php"/><?php echo $speciestally['COUNT(DISTINCT(Com_Name))'];?></a></td>+ <form action="" method="POST">+ <td><button type="submit" name="view" value="Species Stats"><?php echo $speciestally['COUNT(DISTINCT(Com_Name))'];?></button></td>+ </form></tr></table><h2>Today's Detections</h2><table><tr><th>Time</th>+ <th>Listen</th><th>Scientific Name</th><th>Common Name</th><th>Confidence</th>@@ -100,11 +103,13 @@ $speciestally = $result5->fetchArray(SQLITE3_ASSOC);while($todaytable=$result0->fetchArray(SQLITE3_ASSOC)){$comname = preg_replace('/ /', '_', $todaytable['Com_Name']);-$comlink = "/By_Date/".date('Y-m-d')."/".$comname."/".$todaytable['File_Name'];+$comname = preg_replace('/\'/', '_', $comname);+$filename = "/By_Date/".date('Y-m-d')."/".$comname."/".$todaytable['File_Name'];$sciname = preg_replace('/ /', '_', $todaytable['Sci_Name']);?><tr>- <td><a href="<?php echo $comlink;?>" target="footer"/><?php echo $todaytable['Time'];?></a></td>+ <td><?php echo $todaytable['Time'];?></td>+ <td><audio controls><source src="<?php echo $filename;?>"></audio></td><td><a class="a2" href="https://wikipedia.org/wiki/<?php echo $sciname;?>" target="top"><?php echo $todaytable['Sci_Name'];?></a></td><td><a class="a2" href="https://allaboutbirds.org/guide/<?php echo $comname;?>" target="top"><?php echo $todaytable['Com_Name'];?></a></td><td><?php echo $todaytable['Confidence'];?></td>diff --git a/scripts/write_config.php b/scripts/write_config.phpindex f423cd53..ed5aa197 100644--- a/scripts/write_config.php+++ b/scripts/write_config.php@@ -26,25 +26,11 @@ $fh = fopen("/home/pi/BirdNET-Pi/birdnet.conf", "w");$fh2 = fopen("/home/pi/BirdNET-Pi/thisrun.txt", "w");fwrite($fh, $contents);fwrite($fh2, $contents2);-session_start();-$_SESSION['success'] = 1;-if(isset($_POST["normal"])){- header('Location:config.php');-}else{- header('Location:../../');-}$language = $_POST["language"];if ($language != "none"){$command = "sudo -upi mv /home/pi/BirdNET-Pi/model/labels.txt /home/pi/BirdNET-Pi/model/labels.txt.old && sudo -upi unzip /home/pi/BirdNET-Pi/model/labels_l18n.zip $language -d /home/pi/BirdNET-Pi/model && sudo -upi mv /home/pi/BirdNET-Pi/model/$language /home/pi/BirdNET-Pi/model/labels.txt";$command_output = `$command`;-session_start();-$_SESSION['success'] = 1;-if(isset($_POST["normal"])){- header('Location:config.php');-}else{- header('Location:../../');-}}?>