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

@mcguirepr89 I'm very happy with how this turned out! 😄
This commit is contained in:
ehpersonal38
2022-05-16 10:58:04 -04:00
parent d6bdb5c345
commit f59d04a7bc
5 changed files with 209 additions and 21 deletions
+108 -15
View File
@@ -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";
}
}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>";}
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.</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>