Skip to content

A live bird collage card for your Home Assistant dashboard.

Allow specific recordings to be "delete protected" from disk-check.sh

ehpersonal38f59d04a7bcf8
diff --git a/homepage/images/lock.svg b/homepage/images/lock.svg
new file mode 100644
index 00000000..a3bd577a
--- /dev/null
+++ b/homepage/images/lock.svg
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ viewBox="0 0 330 330" style="enable-background:new 0 0 330 330;" xml:space="preserve">
+<g id="XMLID_504_">
+ <path id="XMLID_505_" d="M65,330h200c8.284,0,15-6.716,15-15V145c0-8.284-6.716-15-15-15h-15V85c0-46.869-38.131-85-85-85
+ S80,38.131,80,85v45H65c-8.284,0-15,6.716-15,15v170C50,323.284,56.716,330,65,330z M207.481,219.356l-42.5,42.5
+ c-2.929,2.929-6.768,4.394-10.606,4.394s-7.678-1.465-10.606-4.394l-21.25-21.25c-5.858-5.858-5.858-15.354,0-21.213
+ c5.857-5.858,15.355-5.858,21.213,0l10.644,10.643l31.894-31.893c5.857-5.858,15.355-5.858,21.213,0
+ C213.34,204.002,213.34,213.498,207.481,219.356z M110,85c0-30.327,24.673-55,55-55s55,24.673,55,55v45H110V85z"/>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+</svg>
diff --git a/homepage/images/unlock.svg b/homepage/images/unlock.svg
new file mode 100644
index 00000000..e8ddb69f
--- /dev/null
+++ b/homepage/images/unlock.svg
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ viewBox="0 0 330 330" style="enable-background:new 0 0 330 330;" xml:space="preserve">
+<g id="XMLID_516_">
+ <path id="XMLID_517_" d="M15,160c8.284,0,15-6.716,15-15V85c0-30.327,24.673-55,55-55c30.327,0,55,24.673,55,55v45h-25
+ c-8.284,0-15,6.716-15,15v170c0,8.284,6.716,15,15,15h200c8.284,0,15-6.716,15-15V145c0-8.284-6.716-15-15-15H170V85
+ c0-46.869-38.131-85-85-85S0,38.131,0,85v60C0,153.284,6.716,160,15,160z"/>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+<g>
+</g>
+</svg>
diff --git a/scripts/advanced.php b/scripts/advanced.php
index 9f67d467..657cb99f 100644
--- a/scripts/advanced.php
+++ b/scripts/advanced.php
@@ -204,7 +204,7 @@ if (file_exists('./scripts/thisrun.txt')) {
<input name="full_disk" type="radio" id="purge" value="purge" <?php if (strcmp($newconfig['FULL_DISK'], "purge") == 0) { echo "checked"; }?>>Purge</label>
<label for="keep">
<input name="full_disk" type="radio" id="keep" value="keep" <?php if (strcmp($newconfig['FULL_DISK'], "keep") == 0) { echo "checked"; }?>>Keep</label>
- <p>When the disk becomes full, you can choose to 'purge' old files to make room for new ones or 'keep' your data and stop all services instead.</p>
+ <p>When the disk becomes full, you can choose to 'purge' old files to make room for new ones or 'keep' your data and stop all services instead.<br>Note: you can exclude specific files from 'purge' on the Recordings page.</p>
<label for="rec_card">Audio Card: </label>
<input name="rec_card" type="text" value="<?php print($newconfig['REC_CARD']);?>" required/><br>
<p>Set Audio Card to 'default' to use PulseAudio (always recommended), or an ALSA recognized sound card device from the output of `aplay -L`.</p>
diff --git a/scripts/play.php b/scripts/play.php
index 87912a87..21152536 100644
--- a/scripts/play.php
+++ b/scripts/play.php
@@ -9,6 +9,43 @@ if($db == False){
header("refresh: 0;");
}
+if (file_exists('./scripts/thisrun.txt')) {
+ $config = parse_ini_file('./scripts/thisrun.txt');
+} elseif (file_exists('firstrun.ini')) {
+ $config = parse_ini_file('firstrun.ini');
+}
+
+$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
+$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
+$home = trim($home);
+
+if(isset($_GET['excludefile'])) {
+ if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")) {
+ file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end");
+ }
+ if(isset($_GET['exclude_add'])) {
+ $myfile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!");
+ $txt = $_GET['excludefile'];
+ fwrite($myfile, $txt."\n");
+ fwrite($myfile, $txt.".png\n");
+ fclose($myfile);
+ echo "OK";
+ die();
+ } else {
+ $lines = file($home."/BirdNET-Pi/scripts/disk_check_exclude.txt");
+ $search = $_GET['excludefile'];
+
+ $result = '';
+ foreach($lines as $line) {
+ if(stripos($line, $search) === false && stripos($line, $search.".png") === false) {
+ $result .= $line;
+ }
+ }
+ file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", $result);
+ echo "OK";
+ die();
+ }
+}
if(isset($_GET['bydate'])){
$statement = $db->prepare('SELECT DISTINCT(Date) FROM detections GROUP BY Date ORDER BY Date DESC');
@@ -70,9 +107,6 @@ if(isset($_GET['bydate'])){
session_unset();
$view = "choose";
}
-$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
-$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
-$home = trim($home);
?>
<html>
@@ -83,6 +117,29 @@ $home = trim($home);
</style>
</head>
+<script>
+function toggleLock(filename, type, elem) {
+ const xhttp = new XMLHttpRequest();
+ xhttp.onload = function() {
+ if(type == "add") {
+ elem.setAttribute("src","images/lock.svg");
+ elem.setAttribute("title", "This file is delete protected.");
+ elem.setAttribute("onclick", elem.getAttribute("onclick").replace("add","del"));
+ } else {
+ elem.setAttribute("src","images/unlock.svg");
+ elem.setAttribute("title", "This file is not delete protected.");
+ elem.setAttribute("onclick", elem.getAttribute("onclick").replace("del","add"));
+ }
+ }
+ if(type == "add") {
+ xhttp.open("GET", "play.php?excludefile="+filename+"&exclude_add=true", true);
+ } else {
+ xhttp.open("GET", "play.php?excludefile="+filename+"&exclude_del=true", true);
+ }
+ xhttp.send();
+}
+</script>
+
<?php
#If no specific species
if(!isset($_GET['species']) && !isset($_GET['filename'])){
@@ -104,7 +161,6 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
</div>
<?php } ?>
-
<table>
<tr>
<form action="" method="GET">
@@ -199,6 +255,7 @@ if(isset($_GET['species'])){ ?>
$sci_name = $results['Sci_Name'];
$time = $results['Time'];
$confidence = $results['Confidence'];
+ $filename_formatted = $date."/".$comname."/".$results['File_Name'];
// file was deleted by disk check, no need to show the detection in recordings
if(!file_exists($home."/BirdSongs/Extracted/".$filename)) {
@@ -206,13 +263,31 @@ if(isset($_GET['species'])){ ?>
}
$iter++;
- echo "<tr>
- <td>$date $time<br>$confidence<br>
- <a href=\"$filename\"><img src=\"$filename.png\"></a>
- </td>
- </tr>";
+ if($config["FULL_DISK"] == "purge") {
+ if(trim(shell_exec("cat ".$home."/BirdNET-Pi/scripts/disk_check_exclude.txt | grep \"".$filename_formatted."\" | wc -l")) == "0") {
+ $imageicon = "images/unlock.svg";
+ $title = "This file is not delete protected.";
+ $type = "add";
+ } else {
+ $imageicon = "images/lock.svg";
+ $title = "This file is delete protected.";
+ $type = "del";
+ }
+
+ echo "<tr>
+ <td class='relative'>$date $time<br>$confidence<br><img style='cursor:pointer' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">
+ <a href=\"$filename\"><img src=\"$filename.png\"></a>
+ </td>
+ </tr>";
+ } else {
+ echo "<tr>
+ <td class='relative'>$date $time<br>$confidence<br>
+ <a href=\"$filename\"><img src=\"$filename.png\"></a>
+ </td>
+ </tr>";
+ }
- }if($iter == 0){ echo "<tr><td><b>No recordings were found on this date.</b><br><br><span style='font-size:small'>They may have been deleted to make space for new recordings. You can modify this setting for the future in Tools -> Settings -> Advanced Settings -> Full Disk Behavior.</small></td></tr>";}echo "</table>";}
+ }if($iter == 0){ echo "<tr><td><b>No recordings were found.</b><br><br><span style='font-size:small'>They may have been deleted to make space for new recordings. You can modify this setting for the future in Tools -> Settings -> Advanced Settings -> Full Disk Behavior.</small></td></tr>";}echo "</table>";}
if(isset($_GET['filename'])){
$name = $_GET['filename'];
@@ -236,11 +311,29 @@ if(isset($_GET['filename'])){
$sci_name = $results['Sci_Name'];
$time = $results['Time'];
$confidence = $results['Confidence'];
- echo "<tr>
- <td>$date $time<br>$confidence<br>
- <a href=\"$filename\"><img src=\"$filename\"></a>
- </td>
- </tr>";
+ $filename_formatted = $date."/".$comname."/".$results['File_Name'];
+
+ if($config["FULL_DISK"] == "purge") {
+ if(trim(shell_exec("cat ".$home."/BirdNET-Pi/scripts/disk_check_exclude.txt | grep \"".$filename_formatted."\" | wc -l")) == "0") {
+ $imageicon = "images/unlock.svg";
+ $title = "This file is not delete protected.";
+ $type = "add";
+ } else {
+ $imageicon = "images/lock.svg";
+ $title = "This file is delete protected.";
+ $type = "del";
+ }
+
+ echo "<tr>
+ <td class=\"relative\"><img style='cursor:pointer' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">$date $time<br>$confidence<br>
+ <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
+ </tr>";
+ } else {
+ echo "<tr>
+ <td class=\"relative\">$date $time<br>$confidence<br>
+ <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>
+ </tr>";
+ }
}echo "</table>";}?>
</div>
diff --git a/scripts/stats.php b/scripts/stats.php
index a1369469..3f41a223 100644
--- a/scripts/stats.php
+++ b/scripts/stats.php
@@ -56,7 +56,18 @@ if(isset($_GET['species'])){
$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
$home = trim($home);
-file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "");
+if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")) {
+ file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end");
+}
+function editfile( $sourcefile, $start='##start', $end='##end', $data=array() ){
+ $lines=array_filter( file( $sourcefile , FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES ) );
+ $output=array_merge(
+ array_splice( $lines, 0, array_search( strtolower( $start ), array_map('strtolower', $lines ) ) + 1 ),
+ $data,
+ array_splice( $lines, array_search( strtolower( $end ), array_map('strtolower', $lines ) ) )
+ );
+ file_put_contents( $sourcefile, implode( PHP_EOL, $output ) );
+}
?>
<html lang="en">
@@ -151,21 +162,22 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
if($pos !== 1 && strpos($link, "upload") == true && strpos($link, "CentralAutoLogin") == false)
echo "<img src=\"$link\">";
}
-}}
+}
+}
?>
<br><br><br>
<table>
<?php
+$excludelines = [];
while($results=$result->fetchArray(SQLITE3_ASSOC))
{
$comname = preg_replace('/ /', '_', $results['Com_Name']);
$comname = preg_replace('/\'/', '', $comname);
$filename = "/By_Date/".$results['Date']."/".$comname."/".$results['File_Name'];
-$excludefile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!");
-$txt = $results['Date']."/".$comname."/".$results['File_Name']."\n".$results['Date']."/".$comname."/".$results['File_Name'].".png\n";
-fwrite($excludefile, $txt);
+array_push($excludelines, $results['Date']."/".$comname."/".$results['File_Name']);
+array_push($excludelines, $results['Date']."/".$comname."/".$results['File_Name'].".png");
?>
<tr>
<form action="" method="GET">
@@ -176,6 +188,7 @@ fwrite($excludefile, $txt);
<b>Best Recording:</b> <?php echo $results['Date']." ".$results['Time'];?><br><video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster="<?php echo $filename.".png";?>" preload="none" title="<?php echo $filename;?>"><source src="<?php echo $filename;?>" type="audio/mp3"></video></td>
</tr>
<?php
+editfile($home."/BirdNET-Pi/scripts/disk_check_exclude.txt","##start","##end",$excludelines);
}
?>
</table>