Motion Scripts

From MidsouthMakers - Memphis Area Hackerpace
Jump to navigation Jump to search

Motion Scripts

We use two bash scripts to manage motion data. One simply copies the last snapshot to the live web server for the main domain to link to.

  • imagedelay.sh
cp /motion/1.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-1.jpg
cp /motion/2.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-2.jpg
cp /motion/3.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-3.jpg
cp /motion/4.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-4.jpg
cp /motion/5.camera.midsouthmakers.org/lastsnap.jpg /motion/camera.midsouthmakers.org/delayed-5.jpg

Our second script rotates the previous day's images into it's own archive folder and copies an easy to view gallery.

  • archivemotion.sh
#!/bin/bash
DATE=`date -d '1 day ago' +%Y-%m-%d`
echo $DATE
PATH1="/motion/1.camera.midsouthmakers.org/$DATE"
echo $PATH1
mkdir $PATH1
mv /motion/1.camera.midsouthmakers.org/$DATE-* $PATH1/.
cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/1.camera.midsouthmakers.org/$DATE/index.php
#
PATH2="/motion/2.camera.midsouthmakers.org/$DATE"
echo $PATH2
mkdir $PATH2
mv /motion/2.camera.midsouthmakers.org/$DATE-* $PATH2/.
cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/2.camera.midsouthmakers.org/$DATE/index.php
#
PATH3="/motion/3.camera.midsouthmakers.org/$DATE"
echo $PATH3
mkdir $PATH3
mv /motion/3.camera.midsouthmakers.org/$DATE-* $PATH3/.
cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/3.camera.midsouthmakers.org/$DATE/index.php
#
PATH4="/motion/4.camera.midsouthmakers.org/$DATE"
echo $PATH4
mkdir $PATH4
mv /motion/4.camera.midsouthmakers.org/$DATE-* $PATH4/.
cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/4.camera.midsouthmakers.org/$DATE/index.php
#
PATH5="/motion/5.camera.midsouthmakers.org/$DATE"
echo $PATH5
mkdir $PATH5
mv /motion/5.camera.midsouthmakers.org/$DATE-* $PATH5/.
cp /motion/1.camera.midsouthmakers.org/galleryarchive.php /motion/5.camera.midsouthmakers.org/$DATE/index.php

Gallery Sciprts

We use 2 gallery scripts, one lists folders to be placed in the root of the individual camera folder, the other is to be copied into each archived folder.

  • gallery.php
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
function folderlist(){
  $startdir = './';
  $ignoredDirectory[] = '.'; 
  $ignoredDirectory[] = '..';
   if (is_dir($startdir)){
       if ($dh = opendir($startdir)){
           while (($folder = readdir($dh)) !== false){
               if (!(array_search($folder,$ignoredDirectory) > -1)){
                 if (filetype($startdir . $folder) == "dir"){
                       $directorylist[$startdir . $folder]['name'] = $folder;
                       $directorylist[$startdir . $folder]['path'] = $startdir;
                   }
               }
           }
           closedir($dh);
       }
   }
return($directorylist);
}
echo("<table><tr><td>Past Archives</td></tr>");
$folders = folderlist();
  foreach ($folders as $folder){
    $path = $folder['path'];
    $name = $folder['name'];

    echo '<tr><td><a href="'. $path . $name .'">' . $name . '</a></td></tr>';
  }
echo("</table>");  
// open the current directory by opendir
$handle=opendir(".");
	$images = array();
	$videos = array();
	$imagestring = ".jpg";
	$videostring = ".mov";
while (($file = readdir($handle))!==false) {
if ($file == "." || $file == ".."){
	//nothing
} else {
	
	//echo "$file <br>";
	if(strstr($file,$imagestring)) {
		//echo "found it.";
		//echo("$file : " . date ("Ymd Gis", filemtime($file)) . "<BR>");
		$imagedate = date("Ymd Gis", filemtime($file));
		$images["$imagedate"][] = "<img src=\"" . $file . "\">";
		//$images[] = $file;
	} else {
		//echo "not found.";
	}
	if(strstr($file,$videostring)) {
		//echo "found it.";
		$videos[] = $file;
	} else {
		//echo "not found.";
	}
}
}
sort($images);
//ksort($videos);
//echo("<pre>"); print_r($images); echo("

");

foreach ($images as $imagelink) { //echo("$imagelink"); foreach ($imagelink as $key=>$temptwo) {

     echo "$temptwo", "\n";
   }

} closedir($handle); ?>

  • galleryarchive.php
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
function folderlist(){
  $startdir = './';
  $ignoredDirectory[] = '.'; 
  $ignoredDirectory[] = '..';
   if (is_dir($startdir)){
       if ($dh = opendir($startdir)){
           while (($folder = readdir($dh)) !== false){
               if (!(array_search($folder,$ignoredDirectory) > -1)){
                 if (filetype($startdir . $folder) == "dir"){
                       $directorylist[$startdir . $folder]['name'] = $folder;
                       $directorylist[$startdir . $folder]['path'] = $startdir;
                   }
               }
           }
           closedir($dh);
       }
   }
return($directorylist);
}
  
// open the current directory by opendir
$handle=opendir(".");
	$images = array();
	$videos = array();
	$imagestring = ".jpg";
	$videostring = ".mov";
while (($file = readdir($handle))!==false) {
if ($file == "." || $file == ".."){
	//nothing
} else {
	
	//echo "$file <br>";
	if(strstr($file,$imagestring)) {
		//echo "found it.";
		//echo("$file : " . date ("Ymd Gis", filemtime($file)) . "<BR>");
		$imagedate = date("Ymd Gis", filemtime($file));
		$images["$imagedate"][] = "<img src=\"" . $file . "\">";
		//$images[] = $file;
	} else {
		//echo "not found.";
	}
	if(strstr($file,$videostring)) {
		//echo "found it.";
		$videos[] = $file;
	} else {
		//echo "not found.";
	}
}
}
sort($images);
//ksort($videos);
//echo("<pre>"); print_r($images); echo("

");

foreach ($images as $imagelink) { //echo("$imagelink"); foreach ($imagelink as $key=>$temptwo) {

     echo "$temptwo", "\n";
   }

} closedir($handle); ?>