From 69c4a6d3b134ddf6333be3dba748d9c1988f4808 Mon Sep 17 00:00:00 2001 From: jaredb7 Date: Tue, 9 May 2023 20:29:57 +1000 Subject: [PATCH] Move remaining files to use new code Include and Exclude list updated to use the calculated path to their respective x_species_list.txt files Move play.php over to also use the new calculated paths to disk_check_exclude Spectrogram.php remove unused code & replace setting save code with new function Stats.php removed old code, update paths to use calculated path. Rename setSetting func to saveSetting Remove old code from other pages --- homepage/index.php | 37 ++----------------- homepage/views.php | 1 + scripts/advanced.php | 56 ++++++++++++++-------------- scripts/birdnetpi_request.php | 12 +++--- scripts/birdweather_request.php | 12 +++--- scripts/common.php | 20 +++++----- scripts/config.php | 36 +++++++++--------- scripts/history.php | 10 ++--- scripts/include_list.php | 2 +- scripts/overview.php | 37 +++++-------------- scripts/play.php | 26 ++++++++----- scripts/spectrogram.php | 35 ++++-------------- scripts/stats.php | 65 ++++++--------------------------- scripts/weekly_report.php | 13 +++---- 14 files changed, 129 insertions(+), 233 deletions(-) diff --git a/homepage/index.php b/homepage/index.php index eeae423..bfbd6fa 100644 --- a/homepage/index.php +++ b/homepage/index.php @@ -1,34 +1,10 @@ <?php echo $site_name; ?> @@ -53,11 +29,6 @@ echo " = 99) {?> diff --git a/scripts/advanced.php b/scripts/advanced.php index dd03e67..85cdbe5 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -25,142 +25,142 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) { if(isset($_GET['submit'])) { if(isset($_GET["caddy_pwd"])) { $caddy_pwd = $_GET["caddy_pwd"]; - setSetting('CADDY_PWD', "\"$caddy_pwd\"",'update_caddyfile'); + saveSetting('CADDY_PWD', "\"$caddy_pwd\"",'update_caddyfile'); } if(isset($_GET["ice_pwd"])) { $ice_pwd = $_GET["ice_pwd"]; - setSetting('ICE_PWD', $ice_pwd); + saveSetting('ICE_PWD', $ice_pwd); } if(isset($_GET["birdnetpi_url"])) { $birdnetpi_url = $_GET["birdnetpi_url"]; // remove trailing slash to prevent conf from becoming broken $birdnetpi_url = rtrim($birdnetpi_url, '/'); - setSetting('BIRDNETPI_URL', $birdnetpi_url,'update_caddyfile'); + saveSetting('BIRDNETPI_URL', $birdnetpi_url,'update_caddyfile'); } if(isset($_GET["rtsp_stream"])) { $rtsp_stream = str_replace("\r\n", ",", $_GET["rtsp_stream"]); - setSetting('RTSP_STREAM', "\"$rtsp_stream\"", ['restart birdnet_recording', 'restart livestream']); + saveSetting('RTSP_STREAM', "\"$rtsp_stream\"", ['restart birdnet_recording', 'restart livestream']); } if (isset($_GET["rtsp_stream_to_livestream"])) { $rtsp_stream_selected = trim($_GET["rtsp_stream_to_livestream"]); - setSetting('RTSP_STREAM_TO_LIVESTREAM', "\"$rtsp_stream_selected\"", 'restart livestream'); + saveSetting('RTSP_STREAM_TO_LIVESTREAM', "\"$rtsp_stream_selected\"", 'restart livestream'); } if(isset($_GET["overlap"])) { $overlap = $_GET["overlap"]; - setSetting('OVERLAP', $overlap); + saveSetting('OVERLAP', $overlap); } if(isset($_GET["confidence"])) { $confidence = $_GET["confidence"]; - setSetting('CONFIDENCE', $confidence); + saveSetting('CONFIDENCE', $confidence); } if(isset($_GET["sensitivity"])) { $sensitivity = $_GET["sensitivity"]; - setSetting('SENSITIVITY', $sensitivity); + saveSetting('SENSITIVITY', $sensitivity); } if(isset($_GET["freqshift_hi"]) && is_numeric($_GET['freqshift_hi'])) { $freqshift_hi = $_GET["freqshift_hi"]; - setSetting('FREQSHIFT_HI', $freqshift_hi); + saveSetting('FREQSHIFT_HI', $freqshift_hi); } if(isset($_GET["freqshift_lo"]) && is_numeric($_GET['freqshift_lo'])) { $freqshift_lo = $_GET["freqshift_lo"]; - setSetting('FREQSHIFT_HI', $freqshift_hi); + saveSetting('FREQSHIFT_HI', $freqshift_hi); } if(isset($_GET["freqshift_pitch"]) && is_numeric($_GET['freqshift_pitch'])) { $freqshift_pitch = $_GET["freqshift_pitch"]; - setSetting('FREQSHIFT_PITCH', $freqshift_pitch); + saveSetting('FREQSHIFT_PITCH', $freqshift_pitch); } if(isset($_GET["freqshift_tool"])) { $freqshift_tool = $_GET["freqshift_tool"]; - setSetting('FREQSHIFT_TOOL', $freqshift_tool); + saveSetting('FREQSHIFT_TOOL', $freqshift_tool); } if(isset($_GET["full_disk"])) { $full_disk = $_GET["full_disk"]; - setSetting('FULL_DISK', $full_disk); + saveSetting('FULL_DISK', $full_disk); } if(isset($_GET["privacy_threshold"])) { $privacy_threshold = $_GET["privacy_threshold"]; - setSetting('PRIVACY_THRESHOLD', $privacy_threshold,'restart_services'); + saveSetting('PRIVACY_THRESHOLD', $privacy_threshold,'restart_services'); } if(isset($_GET["rec_card"])) { $rec_card = trim($_GET["rec_card"]); - setSetting('REC_CARD', "\"$rec_card\""); + saveSetting('REC_CARD', "\"$rec_card\""); } if(isset($_GET["channels"])) { $channels = $_GET["channels"]; - setSetting('CHANNELS', $channels); + saveSetting('CHANNELS', $channels); } if(isset($_GET["recording_length"])) { $recording_length = $_GET["recording_length"]; - setSetting('RECORDING_LENGTH', $recording_length); + saveSetting('RECORDING_LENGTH', $recording_length); } if(isset($_GET["extraction_length"])) { $extraction_length = $_GET["extraction_length"]; - setSetting('EXTRACTION_LENGTH', $extraction_length); + saveSetting('EXTRACTION_LENGTH', $extraction_length); } if(isset($_GET["audiofmt"])) { $audiofmt = $_GET["audiofmt"]; - setSetting('AUDIOFMT', $audiofmt); + saveSetting('AUDIOFMT', $audiofmt); } if(isset($_GET["silence_update_indicator"])) { $silence_update_indicator = 1; - setSetting('SILENCE_UPDATE_INDICATOR', $silence_update_indicator); + saveSetting('SILENCE_UPDATE_INDICATOR', $silence_update_indicator); } else { - setSetting('SILENCE_UPDATE_INDICATOR', 0); + saveSetting('SILENCE_UPDATE_INDICATOR', 0); } if(isset($_GET["raw_spectrogram"])) { $raw_spectrogram = 1; - setSetting('RAW_SPECTROGRAM', $raw_spectrogram); + saveSetting('RAW_SPECTROGRAM', $raw_spectrogram); } else { - setSetting('RAW_SPECTROGRAM', 0); + saveSetting('RAW_SPECTROGRAM', 0); } if(isset($_GET["custom_image"])) { $custom_image = $_GET["custom_image"]; - setSetting('CUSTOM_IMAGE', $custom_image); + saveSetting('CUSTOM_IMAGE', $custom_image); } if(isset($_GET["custom_image_label"])) { $custom_image_label = $_GET["custom_image_label"]; - setSetting('CUSTOM_IMAGE_TITLE', "\"$custom_image_label\""); + saveSetting('CUSTOM_IMAGE_TITLE', "\"$custom_image_label\""); } if (isset($_GET["LogLevel_BirdnetRecordingService"])) { $birdnet_recording_service_log_level = trim($_GET["LogLevel_BirdnetRecordingService"]); - setSetting('LogLevel_BirdnetRecordingService', "\"$birdnet_recording_service_log_level\"",'restart birdnet_recording'); + saveSetting('LogLevel_BirdnetRecordingService', "\"$birdnet_recording_service_log_level\"",'restart birdnet_recording'); } if (isset($_GET["LogLevel_SpectrogramViewerService"])) { $spectrogram_viewer_service_log_level = trim($_GET["LogLevel_SpectrogramViewerService"]); - setSetting('LogLevel_SpectrogramViewerService', "\"$spectrogram_viewer_service_log_level\"",'restart spectrogram_viewer'); + saveSetting('LogLevel_SpectrogramViewerService', "\"$spectrogram_viewer_service_log_level\"",'restart spectrogram_viewer'); } if (isset($_GET["LogLevel_LiveAudioStreamService"])) { $livestream_audio_service_log_level = trim($_GET["LogLevel_LiveAudioStreamService"]); - setSetting('LogLevel_LiveAudioStreamService', "\"$livestream_audio_service_log_level\"",['restart livestream','restart icecast2']); + saveSetting('LogLevel_LiveAudioStreamService', "\"$livestream_audio_service_log_level\"",['restart livestream','restart icecast2']); } } diff --git a/scripts/birdnetpi_request.php b/scripts/birdnetpi_request.php index 968c174..6cfa606 100644 --- a/scripts/birdnetpi_request.php +++ b/scripts/birdnetpi_request.php @@ -1,10 +1,10 @@ $value) { diff --git a/scripts/birdweather_request.php b/scripts/birdweather_request.php index a8b82ab..add8e76 100644 --- a/scripts/birdweather_request.php +++ b/scripts/birdweather_request.php @@ -1,10 +1,10 @@ $value) { diff --git a/scripts/common.php b/scripts/common.php index 1766e33..dbb14cf 100644 --- a/scripts/common.php +++ b/scripts/common.php @@ -104,10 +104,6 @@ function connect_to_birdsdb() try { $DB_CONN = new SQLite3(getFilePath('birds.db'), SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); if ($DB_CONN == False) { - if (!$api_incl) { - echo "connect_to_birdsdb:: Database is busy"; - header("refresh: 0;"); - } birdnet_error_log("connect_to_birdsdb:: birds.db database is busy"); } } catch (Exception $sql_exec) { @@ -445,10 +441,10 @@ function getDetectionsBySpecies($species_name = null, $sort = null) //Rearrange data $newReturnData = []; - $newReturnData['species'] = $speciesDetections; + $newReturnData['species'] = $speciesDetections['data']; //Check to see if we have to get max confidence results for the species also if (isset($speciesDetections_MaxConf)) { - $newReturnData['species_MaxConf'] = $speciesDetections_MaxConf; + $newReturnData['species_MaxConf'] = $speciesDetections_MaxConf['data']; } $speciesDetections['data'] = $newReturnData; @@ -1040,9 +1036,9 @@ function getDirectory($dir) } else if ($dir == "extracted") { $extracted_dir_setting = $config['EXTRACTED']; return getDirectory('recs_dir') . str_replace('${RECS_DIR}', '', $extracted_dir_setting); - } elseif ($dir == "extracted_bydate") { + } elseif ($dir == "extracted_bydate" || $dir == "extracted_by_date") { return getDirectory('extracted') . '/By_Date'; - } elseif ($dir == "shifted_audio") { + } elseif ($dir == "shifted_audio" || $dir == "shifted_dir") { return getDirectory('home') . '/BirdSongs/Extracted/By_Date/shifted'; } elseif ($dir == "database") { // NOT USED @@ -1094,6 +1090,12 @@ function getFilePath($filename) } else if ($filename == "disk_check_exclude.txt") { return getDirectory('scripts') . "/disk_check_exclude.txt"; // + } else if ($filename == "email_template") { + return getDirectory('scripts') . "/email_template"; + // + } else if ($filename == "email_template2") { + return getDirectory('scripts') . "/email_template2"; + // } else if ($filename == "exclude_species_list.txt") { return getDirectory('scripts') . "/exclude_species_list.txt"; // @@ -1149,7 +1151,7 @@ function getFilePath($filename) * @param $post_save_command string CommaAnd to execute after saving * @return void */ -function setSetting($setting_name, $setting_value, $post_save_command = null) +function saveSetting($setting_name, $setting_value, $post_save_command = null) { global $config; diff --git a/scripts/config.php b/scripts/config.php index b73cb63..9bb8858 100644 --- a/scripts/config.php +++ b/scripts/config.php @@ -95,24 +95,24 @@ if(isset($_GET["latitude"])){ changeLanguage($model, $language); - setSetting('SITE_NAME', "\"$site_name\""); - setSetting('LATITUDE', $latitude); - setSetting('LONGITUDE', $longitude); - setSetting('BIRDWEATHER_ID', $birdweather_id); - setSetting('APPRISE_NOTIFICATION_TITLE', "\"$apprise_notification_title\""); - setSetting('APPRISE_NOTIFICATION_BODY', "'$apprise_notification_body'"); - setSetting('APPRISE_NOTIFY_EACH_DETECTION', $apprise_notify_each_detection); - setSetting('APPRISE_NOTIFY_NEW_SPECIES', $apprise_notify_new_species); - setSetting('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY', $apprise_notify_new_species_each_day); - setSetting('APPRISE_WEEKLY_REPORT', $apprise_weekly_report); - setSetting('FLICKR_API_KEY', $flickr_api_key); - setSetting('DATABASE_LANG', $language); - setSetting('FLICKR_FILTER_EMAIL', $flickr_filter_email); - setSetting('APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES', $minimum_time_limit); - setSetting('MODEL', $model); - setSetting('SF_THRESH', $sf_thresh); - setSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES', "\"$only_notify_species_names\""); - setSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2', "\"$only_notify_species_names_2\""); + saveSetting('SITE_NAME', "\"$site_name\""); + saveSetting('LATITUDE', $latitude); + saveSetting('LONGITUDE', $longitude); + saveSetting('BIRDWEATHER_ID', $birdweather_id); + saveSetting('APPRISE_NOTIFICATION_TITLE', "\"$apprise_notification_title\""); + saveSetting('APPRISE_NOTIFICATION_BODY', "'$apprise_notification_body'"); + saveSetting('APPRISE_NOTIFY_EACH_DETECTION', $apprise_notify_each_detection); + saveSetting('APPRISE_NOTIFY_NEW_SPECIES', $apprise_notify_new_species); + saveSetting('APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY', $apprise_notify_new_species_each_day); + saveSetting('APPRISE_WEEKLY_REPORT', $apprise_weekly_report); + saveSetting('FLICKR_API_KEY', $flickr_api_key); + saveSetting('DATABASE_LANG', $language); + saveSetting('FLICKR_FILTER_EMAIL', $flickr_filter_email); + saveSetting('APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES', $minimum_time_limit); + saveSetting('MODEL', $model); + saveSetting('SF_THRESH', $sf_thresh); + saveSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES', "\"$only_notify_species_names\""); + saveSetting('APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2', "\"$only_notify_species_names_2\""); if($site_name != $config["SITE_NAME"]) { diff --git a/scripts/history.php b/scripts/history.php index 27f4448..b59b870 100644 --- a/scripts/history.php +++ b/scripts/history.php @@ -1,5 +1,9 @@ $lines";} diff --git a/scripts/overview.php b/scripts/overview.php index 848a025..7a34e58 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -1,32 +1,13 @@ 0) { - echo "

Your system is currently processing a backlog of audio. This can take several hours before normal functionality of your BirdNET-Pi resumes.

"; + if($processed_detections == 0) { + echo "

Your system is currently processing a backlog of audio. This can take several hours before normal functionality of your BirdNET-Pi resumes.

"; + } } else { echo "

No Detections For Today.

"; } - } die(); } diff --git a/scripts/play.php b/scripts/play.php index a47d8c8..7a48b4c 100644 --- a/scripts/play.php +++ b/scripts/play.php @@ -1,5 +1,9 @@ ";} } @@ -304,7 +308,7 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){ $birds = array(); foreach ($result as $species_bird_name) { $name = $species_bird_name['Com_Name']; - if (realpath($home . "/BirdSongs/Extracted/By_Date/" . $date . "/" . str_replace(" ", "_", $name)) !== false) { + if (realpath(getDirectory('extracted_by_date') . "/" . $date . "/" . str_replace(" ", "_", $name)) !== false) { $birds[] = $name; } } @@ -367,10 +371,11 @@ if(isset($_GET['species'])){ ?> $iter++; // file was deleted by disk check, no need to show the detection in recordings - if(!file_exists($home."/BirdSongs/Extracted/".$filename)) { + if(!file_exists(getDirectory('extracted') . "/" . $filename)) { continue; } if(!in_array($filename_formatted, $disk_check_exclude_arr) && isset($_GET['only_excluded'])) { @@ -476,7 +481,8 @@ echo " }if($iter == 0){ echo "";}echo "
No recordings were found.

They may have been deleted to make space for new recordings. You can prevent this from happening in the future by clicking the icon in the top right of a recording.
You can also modify this behavior globally under \"Full Disk Behavior\" here.
";} if(isset($_GET['filename'])){ - $name = $_GET['filename']; + $disk_check_exclude_path = getFilePath('disk_check_exclude.txt'); + $name = $_GET['filename']; $result2_data = getDetectionsByFilename($name); if($result2_data['success'] == False){ echo $result2_data['message']; @@ -502,9 +508,9 @@ echo " $filename_formatted = $date."/".$comname."/".$results['File_Name']; // add disk_check_exclude.txt lines into an array for grepping - $fp = @fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", 'r'); + $fp = @fopen($disk_check_exclude_path, 'r'); if ($fp) { - $disk_check_exclude_arr = explode("\n", fread($fp, filesize($home."/BirdNET-Pi/scripts/disk_check_exclude.txt"))); + $disk_check_exclude_arr = explode("\n", fread($fp, filesize($disk_check_exclude_path))); } if($config["FULL_DISK"] == "purge") { diff --git a/scripts/spectrogram.php b/scripts/spectrogram.php index 9bbbbcc..f03e485 100644 --- a/scripts/spectrogram.php +++ b/scripts/spectrogram.php @@ -1,22 +1,14 @@ @@ -432,15 +419,7 @@ h1 { //maybe the list of streams has been modified //This isn't the ideal for this, but needed a way to fix this setting without calling the advanced setting page if (array_key_exists($config['RTSP_STREAM_TO_LIVESTREAM'], $RTSP_Stream_Config) === false) { - $contents = file_get_contents('/etc/birdnet/birdnet.conf'); - $contents2 = file_get_contents('./scripts/thisrun.txt'); - $contents = preg_replace("/RTSP_STREAM_TO_LIVESTREAM=.*/", "RTSP_STREAM_TO_LIVESTREAM=\"0\"", $contents); - $contents2 = preg_replace("/RTSP_STREAM_TO_LIVESTREAM=.*/", "RTSP_STREAM_TO_LIVESTREAM=\"0\"", $contents2); - $fh = fopen("/etc/birdnet/birdnet.conf", "w"); - $fh2 = fopen("./scripts/thisrun.txt", "w"); - fwrite($fh, $contents); - fwrite($fh2, $contents2); - exec("sudo systemctl restart livestream.service"); + saveSetting('RTSP_STREAM_TO_LIVESTREAM',"\"0\"",'restart livestream"'); } //Print out the dropdown list for the RTSP streams diff --git a/scripts/stats.php b/scripts/stats.php index 6c240f3..9a81842 100644 --- a/scripts/stats.php +++ b/scripts/stats.php @@ -1,31 +1,14 @@ prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC'); -// if($statement == False) { -// echo "Database busy"; -// header("refresh: 0;"); -// } -// $result = $statement->execute(); -// -// $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC'); -// if($statement == False) { -// echo "Database busy"; -// header("refresh: 0;"); -// } -// -// $result2 = $statement2->execute(); - - $sort = "occurrences"; + $sort = "occurrences"; $result2_data = getSpeciesBestRecordingList($sort); if ($result2_data['success'] == False) { @@ -34,21 +17,6 @@ if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") { } $result2 = $result2_data['data']; } else { - -// $statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC'); -// if($statement == False) { -// echo "Database busy"; -// header("refresh: 0;"); -// } -// $result = $statement->execute(); -// -// $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC'); -// if($statement == False) { -// echo "Database busy"; -// header("refresh: 0;"); -// } -// $result2 = $statement2->execute(); - $result2_data = getSpeciesBestRecordingList(); if ($result2_data['success'] == False) { @@ -62,12 +30,6 @@ if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") { if(isset($_GET['species'])){ $selection = $_GET['species']; -// $statement3 = $db->prepare("SELECT Com_Name, Sci_Name, COUNT(*), MAX(Confidence), File_Name, Date, Time from detections WHERE Com_Name = \"$selection\""); -// if($statement3 == False) { -// echo "Database busy"; -// header("refresh: 0;"); -// } -// $result3 = $statement3->execute(); $result3_data = getBestRecordingsForSpecies($selection); if($result3_data['success'] == False){ echo $result3_data['message']; @@ -76,12 +38,9 @@ if(isset($_GET['species'])){ $result3 = $result3_data['data']; } -//$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd"); -//$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd"); -//$home = trim($home); -if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(file_get_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt"),"##start") === false) { - file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", ""); - file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end\n"); +if(!file_exists($disk_check_exclude_path) || strpos(file_get_contents($disk_check_exclude_path),"##start") === false) { + file_put_contents($disk_check_exclude_path, ""); + file_put_contents($disk_check_exclude_path, "##start\n##end\n"); } ?> @@ -276,8 +235,8 @@ array_push($excludelines, $results['Date']."/".$comname."/".$results['File_Name'
diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php index b5ad344..fe74108 100644 --- a/scripts/weekly_report.php +++ b/scripts/weekly_report.php @@ -1,5 +1,9 @@