A live bird collage card for your Home Assistant dashboard.
Adding feature: shifting down in frequency for earing impairment people
Louis Croisez3dfd7409441e
diff --git a/homepage/images/shift.svg b/homepage/images/shift.svgnew file mode 100644index 00000000..ab898717--- /dev/null+++ b/homepage/images/shift.svg@@ -0,0 +1,74 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<svg+ xmlns:dc="http://purl.org/dc/elements/1.1/"+ xmlns:cc="http://creativecommons.org/ns#"+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"+ xmlns:svg="http://www.w3.org/2000/svg"+ xmlns="http://www.w3.org/2000/svg"+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"+ version="1.1"+ id="Layer_1"+ x="0px"+ y="0px"+ viewBox="0 0 330 330"+ style="enable-background:new 0 0 330 330;"+ xml:space="preserve"+ sodipodi:docname="shift.svg"+ inkscape:version="1.0.1 (c497b03c, 2020-09-10)"><metadata+ id="metadata122"><rdf:RDF><cc:Work+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs+ id="defs120" /><sodipodi:namedview+ pagecolor="#ffffff"+ bordercolor="#666666"+ borderopacity="1"+ objecttolerance="10"+ gridtolerance="10"+ guidetolerance="10"+ inkscape:pageopacity="0"+ inkscape:pageshadow="2"+ inkscape:window-width="861"+ inkscape:window-height="790"+ id="namedview118"+ showgrid="false"+ inkscape:zoom="1.7878788"+ inkscape:cx="165"+ inkscape:cy="165"+ inkscape:window-x="0"+ inkscape:window-y="25"+ inkscape:window-maximized="0"+ inkscape:current-layer="Layer_1" />+++++++++++++++++<text+ xml:space="preserve"+ style="font-style:normal;font-weight:normal;font-size:73.2664px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.83166"+ x="83.402275"+ y="106.78013"+ id="text126"+ transform="scale(0.82239993,1.2159534)"><tspan+ sodipodi:role="line"+ x="83.402275"+ y="106.78013"+ id="tspan128"+ style="stroke-width:1.83166">FREQ</tspan><tspan+ sodipodi:role="line"+ x="83.402275"+ y="198.36314"+ id="tspan130"+ style="stroke-width:1.83166">SHIFT</tspan></text></svg>diff --git a/homepage/images/spinner.gif b/homepage/images/spinner.gifnew file mode 100644index 00000000..b267d172Binary files /dev/null and b/homepage/images/spinner.gif differdiff --git a/homepage/images/unshift.svg b/homepage/images/unshift.svgnew file mode 100644index 00000000..a04eb159--- /dev/null+++ b/homepage/images/unshift.svg@@ -0,0 +1,74 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<svg+ xmlns:dc="http://purl.org/dc/elements/1.1/"+ xmlns:cc="http://creativecommons.org/ns#"+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"+ xmlns:svg="http://www.w3.org/2000/svg"+ xmlns="http://www.w3.org/2000/svg"+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"+ version="1.1"+ id="Layer_1"+ x="0px"+ y="0px"+ viewBox="0 0 330 330"+ style="enable-background:new 0 0 330 330;"+ xml:space="preserve"+ sodipodi:docname="unshift.svg"+ inkscape:version="1.0.1 (c497b03c, 2020-09-10)"><metadata+ id="metadata122"><rdf:RDF><cc:Work+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs+ id="defs120" /><sodipodi:namedview+ pagecolor="#ffffff"+ bordercolor="#666666"+ borderopacity="1"+ objecttolerance="10"+ gridtolerance="10"+ guidetolerance="10"+ inkscape:pageopacity="0"+ inkscape:pageshadow="2"+ inkscape:window-width="861"+ inkscape:window-height="790"+ id="namedview118"+ showgrid="false"+ inkscape:zoom="1.7878788"+ inkscape:cx="165"+ inkscape:cy="165"+ inkscape:window-x="0"+ inkscape:window-y="25"+ inkscape:window-maximized="0"+ inkscape:current-layer="Layer_1" />+++++++++++++++++<text+ xml:space="preserve"+ style="font-style:normal;font-weight:normal;font-size:73.2664px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.83166"+ x="39.195156"+ y="115.05988"+ id="text126"+ transform="scale(0.82239993,1.2159534)"><tspan+ sodipodi:role="line"+ x="39.195156"+ y="115.05988"+ id="tspan128"+ style="stroke-width:1.83166"> FREQ</tspan><tspan+ sodipodi:role="line"+ x="39.195156"+ y="206.64288"+ id="tspan130"+ style="stroke-width:1.83166">UNSHIFT</tspan></text></svg>diff --git a/scripts/play.php b/scripts/play.phpindex dc3f591c..01436320 100644--- a/scripts/play.php+++ b/scripts/play.php@@ -97,6 +97,31 @@ if(isset($_GET['excludefile'])) {}}+$shifted_path = $home."/BirdSongs/Extracted/By_Date/shifted/";++if(isset($_GET['shiftfile'])) {+ $filename = $_GET['shiftfile'];+ if(isset($_GET['shiftfreq'])) {+ $pp = pathinfo($filename);+ $dir = $pp['dirname'];+ $fn = $pp['filename'];+ $ext = $pp['extension'];+ $pi = $home."/BirdSongs/Extracted/By_Date/";+ $cmd = "/usr/bin/nohup /usr/bin/ffmpeg -y -i \"".$pi.$filename."\" -af \"rubberband=pitch=2500/6000\" \"".$shifted_path.$filename."\"";+ shell_exec("mkdir -p ".$shifted_path.$dir." && echo \"".$cmd."\" > /tmp/shift.sh && chmod +x /tmp/shift.sh");+ shell_exec("/tmp/shift.sh");+ shell_exec("rm -f /tmp/shift.sh");+ } else {+ $cmd = "rm -f " . $shifted_path.$dir.$filename;+ shell_exec("echo \"".$cmd."\" > /tmp/rmshift.sh && chmod +x /tmp/rmshift.sh");+ shell_exec("/tmp/rmshift.sh");+ shell_exec("rm -f /tmp/rmshift.sh");+ }++ echo "OK";+ die();+}+if(isset($_GET['bydate'])){$statement = $db->prepare('SELECT DISTINCT(Date) FROM detections GROUP BY Date ORDER BY Date DESC');if($statement == False){@@ -208,6 +233,45 @@ function toggleLock(filename, type, elem) {xhttp.open("GET", "play.php?excludefile="+filename+"&exclude_del=true", true);}xhttp.send();+ elem.setAttribute("src","images/spinner.gif");+}++function toggleShiftFreq(filename, shiftAction, elem) {+ const xhttp = new XMLHttpRequest();+ xhttp.onload = function() {+ if(this.responseText == "OK"){+ if(shiftAction == "shift") {+ elem.setAttribute("src","images/unshift.svg");+ elem.setAttribute("title", "This file has been shifted down in frequency.");+ elem.setAttribute("onclick", elem.getAttribute("onclick").replace("shift","unshift"));+ console.log("shifted freqs of " + filename);+ video=elem.parentNode.getElementsByTagName("video")[0];+ video.setAttribute("title", video.getAttribute("title").replace("/By_Date/","/By_Date/shifted/"));+ source = video.getElementsByTagName("source")[0];+ source.setAttribute("src", source.getAttribute("src").replace("/By_Date/","/By_Date/shifted/"));+ video.load();+ } else {+ elem.setAttribute("src","images/shift.svg");+ elem.setAttribute("title", "This file is not shifted in frequency.");+ elem.setAttribute("onclick", elem.getAttribute("onclick").replace("unshift","shift"));+ console.log("unshifted freqs of " + filename);+ video=elem.parentNode.getElementsByTagName("video")[0];+ video.setAttribute("title", video.getAttribute("title").replace("/By_Date/shifted/","/By_Date/"));+ source = video.getElementsByTagName("source")[0];+ source.setAttribute("src", source.getAttribute("src").replace("/By_Date/shifted/","/By_Date/"));+ video.load();+ }+ }+ }+ if(shiftAction == "shift") {+ console.log("shifting freqs of " + filename);+ xhttp.open("GET", "play.php?shiftfile="+filename+"&shiftfreq=true", true);+ } else {+ console.log("unshifting freqs of " + filename);+ xhttp.open("GET", "play.php?shiftfile="+filename, true);+ }+ xhttp.send();+ elem.setAttribute("src","images/spinner.gif");}</script>@@ -331,6 +395,8 @@ echo "<table>$comname = preg_replace('/\'/', '', $comname);$date = $results['Date'];$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];+ $filename_shifted = "/By_Date/shifted/".$date."/".$comname."/".$results['File_Name'];+ $filename_png = $filename . ".png";$sciname = preg_replace('/ /', '_', $results['Sci_Name']);$sci_name = $results['Sci_Name'];$time = $results['Time'];@@ -357,14 +423,31 @@ echo "<table>$type = "del";}+ if(file_exists($shifted_path.$filename_formatted)) {+ $shiftImageIcon = "images/unshift.svg";+ $shiftTitle = "This file has been shifted down in frequency.";+ $shiftAction = "unshift";+ $filename = $filename_shifted;+ } else {+ $shiftImageIcon = "images/shift.svg";+ $shiftTitle = "This file is not shifted in frequency.";+ $shiftAction = "shift";+ }+echo "<tr>- <td class=\"relative\"><img style='cursor:pointer;right:45px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'> <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>+ <td class=\"relative\">++<img style='cursor:pointer;right:90px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'>+<img style='cursor:pointer;right:45px' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">+<img style='cursor:pointer' onclick='toggleShiftFreq(\"".$filename_formatted."\",\"".$shiftAction."\", this)' class=\"copyimage\" width=25 title=\"".$shiftTitle."\" src=\"".$shiftImageIcon."\"> $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<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'><br>- <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>+ <td class=\"relative\">$date $time<br>$confidence+<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\")' class=\"copyimage\" width=25 title='Delete Detection'><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>";}@@ -388,6 +471,8 @@ echo "<table>$comname = preg_replace('/\'/', '', $comname);$date = $results['Date'];$filename = "/By_Date/".$date."/".$comname."/".$results['File_Name'];+ $filename_shifted = "/By_Date/shifted/".$date."/".$comname."/".$results['File_Name'];+ $filename_png = $filename . ".png";$sciname = preg_replace('/ /', '_', $results['Sci_Name']);$sci_name = $results['Sci_Name'];$time = $results['Time'];@@ -411,14 +496,31 @@ echo "<table>$type = "del";}+ if(file_exists($shifted_path.$filename_formatted)) {+ $shiftImageIcon = "images/unshift.svg";+ $shiftTitle = "This file has been shifted down in frequency.";+ $shiftAction = "unshift";+ $filename = $filename_shifted;+ } else {+ $shiftImageIcon = "images/shift.svg";+ $shiftTitle = "This file is not shifted in frequency.";+ $shiftAction = "shift";+ }+echo "<tr>- <td class=\"relative\"><img style='cursor:pointer;right:45px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'> <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>+ <td class=\"relative\">++<img style='cursor:pointer;right:90px' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'>+<img style='cursor:pointer;right:45px' onclick='toggleLock(\"".$filename_formatted."\",\"".$type."\", this)' class=\"copyimage\" width=25 title=\"".$title."\" src=\"".$imageicon."\">+<img style='cursor:pointer' onclick='toggleShiftFreq(\"".$filename_formatted."\",\"".$shiftAction."\", this)' class=\"copyimage\" width=25 title=\"".$shiftTitle."\" src=\"".$shiftImageIcon."\">$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<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'><br>- <video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename.png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video></td>+ <td class=\"relative\">$date $time<br>$confidence+<img style='cursor:pointer' src='images/delete.svg' onclick='deleteDetection(\"".$filename_formatted."\", true)' class=\"copyimage\" width=25 title='Delete Detection'><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>";}