diff --git a/homepage/images/shift.svg b/homepage/images/shift.svg new file mode 100644 index 0000000..ab89871 --- /dev/null +++ b/homepage/images/shift.svg @@ -0,0 +1,74 @@ + +image/svg+xml + + + + + + + + + + + + + + + + +FREQSHIFT diff --git a/homepage/images/spinner.gif b/homepage/images/spinner.gif new file mode 100644 index 0000000..b267d17 Binary files /dev/null and b/homepage/images/spinner.gif differ diff --git a/homepage/images/unshift.svg b/homepage/images/unshift.svg new file mode 100644 index 0000000..a04eb15 --- /dev/null +++ b/homepage/images/unshift.svg @@ -0,0 +1,74 @@ + +image/svg+xml + + + + + + + + + + + + + + + + + FREQUNSHIFT diff --git a/scripts/play.php b/scripts/play.php index dc3f591..0143632 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"); } @@ -331,6 +395,8 @@ echo " $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 "
$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 " - + "; } else { echo " - + "; } @@ -388,6 +471,8 @@ echo "
$date $time
$confidence
-
+ + + + $date $time
$confidence
+ +
$date $time
$confidence
-
$date $time
$confidence +
+
$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 "
$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 " - + "; } else { echo " - + "; }
$date $time
$confidence
-
+ + + +$date $time
$confidence
+ +
$date $time
$confidence
-
$date $time
$confidence +
+