Loading eyesis4pi393/footage_filter.php 100644 → 100755 +48 −62 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,8 @@ set_time_limit(0); //CONSTANTS //CONSTANTS $path="/data/footage/test"; // footage root $path="/data/footage/test"; // footage root $dest_path="trash"; // folder for collecting non-matching results $dest_path="trash"; // folder for collecting non-matching results $type = "jp4"; $N = 10; function print_help(){ function print_help(){ global $argv; global $argv; Loading @@ -34,11 +36,12 @@ function print_help(){ echo <<<"TXT" echo <<<"TXT" Help: Help: * Usage: * Usage: ~$ {$argv[0]} path=[path-to-dir] dest_path=[dest-subdir] ~$ {$argv[0]} path=[path-to-dir] trash_path=[trash-subdir] n=[N] where: where: * path-to-dir - string - work at this path + 1 dir down * path-to-dir - string - scan for images at this path * dest-subdir - string - save results to "path-to-dir/dest-subdir/" * trash-subdir - string - move filtered out images to this path * N - integer - number of images in set - optional, default: 10 * Examples: * Examples: ** Filter all images at /data/footage/test/0 puts incomplete images to '/data/footage/test/trash': ** Filter all images at /data/footage/test/0 puts incomplete images to '/data/footage/test/trash': Loading @@ -64,8 +67,12 @@ if (isset($_GET['path'])){ $path=$_GET['path']; $path=$_GET['path']; } } if (isset($_GET['dest_path'])){ if (isset($_GET['trash_path'])){ $dest_path = $_GET['dest_path']; $dest_path = $_GET['trash_path']; } if (isset($_GET['n'])){ $N = $_GET['n']; } } if (!is_dir($dest_path)) { if (!is_dir($dest_path)) { Loading @@ -77,38 +84,11 @@ if (!is_dir($dest_path)) { $filelist = scandir($path); $filelist = scandir($path); echo "<pre>\n"; foreach ($filelist as $value) { //echo $value."\n"; if ($value!=$dest_path) process_folder($value,"jp4"); } function process_folder($file,$type) { global $path; global $processing_folder; global $dest_path; $tmp_arr = Array(); $tmp_arr = Array(); $err_arr = Array(); $url = "$pre_path/$processing_folder"; foreach($filelist as $elem){ if (get_file_extension($path."/".$elem)==$type) { $ext=get_file_extension($file); // exclude "." & ".." if (substr($file,0,1)!=".") { if ($ext=="") { if (is_dir($url."/".$file)) { //echo $url." ".$file."\n"; if ($type=="") { // do nothing } else { $list = scandir($url."/".$file); // getting deeper into indexed subfodlers foreach($list as $elem){ if (get_file_extension($url."/".$file."/".$elem)==$type) { //echo $url."/".$file."/".$elem."\n"; //echo $url."/".$file."/".$elem."\n"; // initialize array // initialize array if (!isset($tmp_arr[substr($elem,0,17)])) $tmp_arr[substr($elem,0,17)] = 0; if (!isset($tmp_arr[substr($elem,0,17)])) $tmp_arr[substr($elem,0,17)] = 0; Loading @@ -117,26 +97,32 @@ function process_folder($file,$type) { $tmp_arr[substr($elem,0,17)]++; $tmp_arr[substr($elem,0,17)]++; } } } } if (count($tmp_arr)==0){ die("No images found at the path. Exit.\n"); } //do actual copying //do actual copying //print_r($tmp_arr); //print_r($tmp_arr); foreach($tmp_arr as $key=>$val){ foreach($tmp_arr as $key=>$val){ if ($val!=10) { if ($val!=$N){ for ($i=1;$i<11;$i++){ for ($i=1;$i<=$N;$i++){ if (is_file("$url/$file/{$key}_$i.$type")){ if (is_file("$path/{$key}_$i.$type")){ array_push($err_arr,"{$key}_$i.$type"); //echo "$url/$file/{$key}_$i.$type to $url/$dest_path/{$key}_$i.$type\n"; //echo "$url/$file/{$key}_$i.$type to $url/$dest_path/{$key}_$i.$type\n"; rename("$url/$file/{$key}_$i.$type","$url/$dest_path/{$key}_$i.$type"); rename("$path/{$key}_$i.$type","$dest_path/{$key}_$i.$type"); } } } } } } } } } } }else{ //do nothing if (count($err_arr)!=0){ } print("Filtered out images:\n"); } print_r($err_arr); } } print("Number of images that were filtered out is ".count($err_arr).". Done.\n"); function get_file_extension($filename) { function get_file_extension($filename) { //return substr(strrchr($filename, '.'), 1); //return substr(strrchr($filename, '.'), 1); return pathinfo($filename, PATHINFO_EXTENSION); return pathinfo($filename, PATHINFO_EXTENSION); Loading Loading
eyesis4pi393/footage_filter.php 100644 → 100755 +48 −62 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,8 @@ set_time_limit(0); //CONSTANTS //CONSTANTS $path="/data/footage/test"; // footage root $path="/data/footage/test"; // footage root $dest_path="trash"; // folder for collecting non-matching results $dest_path="trash"; // folder for collecting non-matching results $type = "jp4"; $N = 10; function print_help(){ function print_help(){ global $argv; global $argv; Loading @@ -34,11 +36,12 @@ function print_help(){ echo <<<"TXT" echo <<<"TXT" Help: Help: * Usage: * Usage: ~$ {$argv[0]} path=[path-to-dir] dest_path=[dest-subdir] ~$ {$argv[0]} path=[path-to-dir] trash_path=[trash-subdir] n=[N] where: where: * path-to-dir - string - work at this path + 1 dir down * path-to-dir - string - scan for images at this path * dest-subdir - string - save results to "path-to-dir/dest-subdir/" * trash-subdir - string - move filtered out images to this path * N - integer - number of images in set - optional, default: 10 * Examples: * Examples: ** Filter all images at /data/footage/test/0 puts incomplete images to '/data/footage/test/trash': ** Filter all images at /data/footage/test/0 puts incomplete images to '/data/footage/test/trash': Loading @@ -64,8 +67,12 @@ if (isset($_GET['path'])){ $path=$_GET['path']; $path=$_GET['path']; } } if (isset($_GET['dest_path'])){ if (isset($_GET['trash_path'])){ $dest_path = $_GET['dest_path']; $dest_path = $_GET['trash_path']; } if (isset($_GET['n'])){ $N = $_GET['n']; } } if (!is_dir($dest_path)) { if (!is_dir($dest_path)) { Loading @@ -77,38 +84,11 @@ if (!is_dir($dest_path)) { $filelist = scandir($path); $filelist = scandir($path); echo "<pre>\n"; foreach ($filelist as $value) { //echo $value."\n"; if ($value!=$dest_path) process_folder($value,"jp4"); } function process_folder($file,$type) { global $path; global $processing_folder; global $dest_path; $tmp_arr = Array(); $tmp_arr = Array(); $err_arr = Array(); $url = "$pre_path/$processing_folder"; foreach($filelist as $elem){ if (get_file_extension($path."/".$elem)==$type) { $ext=get_file_extension($file); // exclude "." & ".." if (substr($file,0,1)!=".") { if ($ext=="") { if (is_dir($url."/".$file)) { //echo $url." ".$file."\n"; if ($type=="") { // do nothing } else { $list = scandir($url."/".$file); // getting deeper into indexed subfodlers foreach($list as $elem){ if (get_file_extension($url."/".$file."/".$elem)==$type) { //echo $url."/".$file."/".$elem."\n"; //echo $url."/".$file."/".$elem."\n"; // initialize array // initialize array if (!isset($tmp_arr[substr($elem,0,17)])) $tmp_arr[substr($elem,0,17)] = 0; if (!isset($tmp_arr[substr($elem,0,17)])) $tmp_arr[substr($elem,0,17)] = 0; Loading @@ -117,26 +97,32 @@ function process_folder($file,$type) { $tmp_arr[substr($elem,0,17)]++; $tmp_arr[substr($elem,0,17)]++; } } } } if (count($tmp_arr)==0){ die("No images found at the path. Exit.\n"); } //do actual copying //do actual copying //print_r($tmp_arr); //print_r($tmp_arr); foreach($tmp_arr as $key=>$val){ foreach($tmp_arr as $key=>$val){ if ($val!=10) { if ($val!=$N){ for ($i=1;$i<11;$i++){ for ($i=1;$i<=$N;$i++){ if (is_file("$url/$file/{$key}_$i.$type")){ if (is_file("$path/{$key}_$i.$type")){ array_push($err_arr,"{$key}_$i.$type"); //echo "$url/$file/{$key}_$i.$type to $url/$dest_path/{$key}_$i.$type\n"; //echo "$url/$file/{$key}_$i.$type to $url/$dest_path/{$key}_$i.$type\n"; rename("$url/$file/{$key}_$i.$type","$url/$dest_path/{$key}_$i.$type"); rename("$path/{$key}_$i.$type","$dest_path/{$key}_$i.$type"); } } } } } } } } } } }else{ //do nothing if (count($err_arr)!=0){ } print("Filtered out images:\n"); } print_r($err_arr); } } print("Number of images that were filtered out is ".count($err_arr).". Done.\n"); function get_file_extension($filename) { function get_file_extension($filename) { //return substr(strrchr($filename, '.'), 1); //return substr(strrchr($filename, '.'), 1); return pathinfo($filename, PATHINFO_EXTENSION); return pathinfo($filename, PATHINFO_EXTENSION); Loading