Merge branch 'ebird'

This commit is contained in:
frederik
2024-06-01 09:22:04 +02:00
7 changed files with 6617 additions and 32 deletions
+37 -15
View File
@@ -89,6 +89,20 @@ function debug_log($message) {
error_log($message . "\n", 3, $_SERVER['DOCUMENT_ROOT'] . "/debug_log.log");
}
function get_com_en_name($sci_name) {
if (!isset($_labels_flickr)) {
$_labels_flickr = file(get_home() . "/BirdNET-Pi/model/labels_flickr.txt");
}
$engname = null;
foreach ($_labels_flickr as $label) {
if (strpos($label, $sci_name) !== false) {
$engname = trim(explode("_", $label)[1]);
break;
}
}
return $engname;
}
define('DB', './scripts/flickr.db');
class Flickr {
@@ -186,7 +200,7 @@ class Flickr {
}
private function get_from_flickr($sci_name) {
$engname = $this->get_com_en_name($sci_name);
$engname = get_com_en_name($sci_name);
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=" . $this->flickr_api_key . "&text=" . str_replace(" ", "%20", $engname) . $this->comnameprefix . "&sort=relevance" . $this->args . "&per_page=5&media=photos&format=json&nojsoncallback=1"), true)["photos"]["photo"];
// could be null!!
@@ -245,18 +259,26 @@ class Flickr {
$this->set_uid_in_db($uid);
}
private function get_com_en_name($sci_name) {
if ($this->labels_flickr === null) {
$this->labels_flickr = file(get_home() . "/BirdNET-Pi/model/labels_flickr.txt");
}
$engname = null;
foreach ($this->labels_flickr as $label) {
if (strpos($label, $sci_name) !== false) {
$engname = trim(explode("_", $label)[1]);
break;
}
}
return $engname;
}
}
function get_info_url($sciname){
$engname = get_com_en_name($sciname);
$config = get_config();
if ($config['INFO_SITE'] === 'EBIRD'){
require 'scripts/ebird.php';
$ebird = $ebirds[$sciname];
debug_log($ebird);
$language = $config['DATABASE_LANG'];
$url = "https://ebird.org/species/$ebird?siteLanguage=$language";
$url_title = "eBirds";
} else {
$engname_url = str_replace("'", '', str_replace(' ', '_', $engname));
$url = "https://allaboutbirds.org/guide/$engname_url";
$url_title = "All About Birds";
}
$ret = array(
'URL' => $url,
'TITLE' => $url_title
);
return $ret;
}
+29
View File
@@ -62,6 +62,7 @@ if(isset($_GET["latitude"])){
$flickr_api_key = $_GET['flickr_api_key'];
$flickr_filter_email = $_GET["flickr_filter_email"];
$language = $_GET["language"];
$info_site = $_GET["info_site"];
$timezone = $_GET["timezone"];
$model = $_GET["model"];
$sf_thresh = $_GET["sf_thresh"];
@@ -154,6 +155,7 @@ if(isset($_GET["latitude"])){
$contents = preg_replace("/APPRISE_WEEKLY_REPORT=.*/", "APPRISE_WEEKLY_REPORT=$apprise_weekly_report", $contents);
$contents = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents);
$contents = preg_replace("/DATABASE_LANG=.*/", "DATABASE_LANG=$language", $contents);
$contents = preg_replace("/INFO_SITE=.*/", "INFO_SITE=$info_site", $contents);
$contents = preg_replace("/FLICKR_FILTER_EMAIL=.*/", "FLICKR_FILTER_EMAIL=$flickr_filter_email", $contents);
$contents = preg_replace("/APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES=.*/", "APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES=$minimum_time_limit", $contents);
$contents = preg_replace("/MODEL=.*/", "MODEL=$model", $contents);
@@ -604,6 +606,33 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
<p>! Only modify this at initial setup !</p>
</td></tr></table>
<br>
<table class="settingstable"><tr><td>
<h2>Additional Info </h2>
<label for="info_site">Site to pull additional species info from: </label>
<select name="info_site">
<?php
$info_site = array(
'ALLABOUTBIRDS' => 'allaboutbirds.org',
"EBIRD" => "ebird.org"
);
// Create options for each site
foreach($info_site as $infoTag => $infoName){
$isSelected = "";
if($config['INFO_SITE'] == $infoTag){
$isSelected = 'selected="selected"';
}
echo "<option value='{$infoTag}' $isSelected>$infoName</option>";
}
?>
</select>
<p>allaboutbirds.org default
<br>ebirds.org has more European species</p>
</td></tr></table><br>
<script>
function handleChange(checkbox) {
// this disables the input of manual date and time if the user wants to use the internet time
+6526
View File
File diff suppressed because it is too large Load Diff
+6
View File
@@ -117,6 +117,12 @@ APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2=""
FLICKR_API_KEY=
FLICKR_FILTER_EMAIL=
#---------------------- Site to pull info from Images ------------------------#
## ALLABOUTBIRDS or EBIRD
## default ALLABOUTBIRDS, EBIRD better for eurasian locations
INFO_SITE="ALLABOUTBIRDS"
################################################################################
#-------------------------------- Defaults ----------------------------------#
################################################################################
+7 -15
View File
@@ -151,7 +151,7 @@ function setModalText(iter, title, text, authorlink) {
<?php if(isset($_GET['species'])){
$species = $_GET['species'];
$iter=0;
$lines;
$config = get_config();
while($results=$result3->fetchArray(SQLITE3_ASSOC)){
$count = $results['COUNT(*)'];
$maxconf = round((float)round($results['MAX(Confidence)'],2) * 100 ) . '%';
@@ -164,13 +164,18 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
$comname = preg_replace('/\'/', '', $comname);
$linkname = preg_replace('/_/', '+', $dbsciname);
$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];
$engname = get_com_en_name($sciname);
$info_url = get_info_url($results['Sci_Name']);
$url = $info_url['URL'];
$url_title = $info_url['TITLE'];
echo str_pad("<h3>$species</h3>
<table><tr>
<td class=\"relative\"><a target=\"_blank\" href=\"index.php?filename=".$results['File_Name']."\"><img title=\"Open in new tab\" class=\"copyimage\" width=25 src=\"images/copy.png\"></a> <a href=\"https://wikipedia.org/wiki/$dbsciname\" target=\"top\"/><i>$sciname</i></a><br>
<b>Occurrences: </b>$count<br>
<b>Max Confidence: </b>$maxconf<br>
<b>Best Recording: </b>$date $time<br>
<a href=\"https://allaboutbirds.org/guide/$comname\" target=\"top\"/>All About Birds</a><br>
<a href=\"$url\" target=\"top\"/>$url_title</a><br>
<video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" title=\"$filename\"><source src=\"$filename\"></video></td>
</tr>
</table>
@@ -180,21 +185,8 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
ob_flush();
flush();
$config = get_config();
if (! empty($config["FLICKR_API_KEY"])) {
// only open the file once per script execution
if(!isset($lines)) {
$lines = file($home."/BirdNET-Pi/model/labels_flickr.txt");
}
// convert sci name to English name
foreach($lines as $line){
if(strpos($line, $results['Sci_Name']) !== false){
$engname = trim(explode("_", $line)[1]);
break;
}
}
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=\"".str_replace(' ', '%20', $engname)."\"&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"];
foreach ($flickrjson as $val) {
+8 -2
View File
@@ -195,6 +195,12 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
$filename = "/By_Date/".date('Y-m-d')."/".$comname."/".$todaytable['File_Name'];
$filename_formatted = $todaytable['Date']."/".$comname."/".$todaytable['File_Name'];
$sciname = preg_replace('/ /', '_', $todaytable['Sci_Name']);
$engname = get_com_en_name($todaytable['Sci_Name']);
$engname_url = str_replace("'", '', str_replace(' ', '_', $engname));
$info_url = get_info_url($todaytable['Sci_Name']);
$url = $info_url['URL'];
$url_title = $info_url['TITLE'];
if (!empty($config["FLICKR_API_KEY"]) && (isset($_GET['display_limit']) || isset($_GET['hard_limit']) || $_GET['kiosk'] == true) ) {
if ($flickr === null) {
@@ -230,7 +236,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
<?php } ?>
<?php echo $todaytable['Time'];?><br>
<b><a class="a2" href="https://allaboutbirds.org/guide/<?php echo $comname;?>" target="top"><?php echo $todaytable['Com_Name'];?></a></b><img style="height: 1em;cursor:pointer" title="View species stats" onclick="generateMiniGraph(this, '<?php echo $comname; ?>')" width=25 src="images/chart.svg"><br>
<b><a class="a2" href="<?php echo $url;?>" target="top"><?php echo $todaytable['Com_Name'];?></a></b><img style="height: 1em;cursor:pointer" title="<?php echo $url_title;?>" onclick="generateMiniGraph(this, '<?php echo $comname; ?>')" width=25 src="images/chart.svg"><br>
<a class="a2" href="https://wikipedia.org/wiki/<?php echo $sciname;?>" target="top"><i><?php echo $todaytable['Sci_Name'];?></i></a><br>
<b>Confidence:</b> <?php echo round((float)round($todaytable['Confidence'],2) * 100 ) . '%';?><br></div><br>
<video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster="<?php echo $filename.".png";?>" preload="none" title="<?php echo $filename;?>"><source preload="none" src="<?php echo $filename;?>"></video>
@@ -246,7 +252,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
<?php } ?>
</div>
<div>
<b><a class="a2" <?php if($_GET['kiosk'] == false){?>href="https://allaboutbirds.org/guide/<?php echo $comname;?>"<?php } else {echo "style='color:blue;'";} ?> target="top"><?php echo $todaytable['Com_Name'];?></a></b>
<b><a class="a2" <?php if($_GET['kiosk'] == false){?>href="<?php echo $url;?>"<?php } else {echo "style='color:blue;'";} ?> target="top"><?php echo $todaytable['Com_Name'];?></a></b>
<?php
//If on mobile, add in a icon to link off to the recording so the user can see more info
if (isset($_GET['mobile'])) {
+4
View File
@@ -86,6 +86,10 @@ SRC='^APPRISE_NOTIFICATION_BODY="A \$comname \(\$sciname\) was just detected wi
DST='APPRISE_NOTIFICATION_BODY="A \$comname (\$sciname) was just detected with a confidence of \$confidence (\$reason)"'
sed -i -E "s/$SRC/$DST/" /etc/birdnet/birdnet.conf
if ! grep -E '^INFO_SITE=' /etc/birdnet/birdnet.conf &>/dev/null;then
echo "INFO_SITE=\"ALLABOUTBIRDS\"" >> /etc/birdnet/birdnet.conf
fi
[ -d $RECS_DIR/StreamData ] || sudo_with_user mkdir -p $RECS_DIR/StreamData
[ -L ${EXTRACTED}/spectrogram.png ] || sudo_with_user ln -sf ${RECS_DIR}/StreamData/spectrogram.png ${EXTRACTED}/spectrogram.png