Commit e4977e1e authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. docs 2. tested

parent fb3710ba
...@@ -27,6 +27,8 @@ set_time_limit(0); ...@@ -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;
...@@ -34,11 +36,12 @@ function print_help(){ ...@@ -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':
...@@ -64,8 +67,12 @@ if (isset($_GET['path'])){ ...@@ -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)) {
...@@ -77,38 +84,11 @@ if (!is_dir($dest_path)) { ...@@ -77,38 +84,11 @@ if (!is_dir($dest_path)) {
$filelist = scandir($path); $filelist = scandir($path);
echo "<pre>\n"; $tmp_arr = Array();
$err_arr = Array();
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(); foreach($filelist as $elem){
if (get_file_extension($path."/".$elem)==$type) {
$url = "$pre_path/$processing_folder";
$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;
...@@ -116,27 +96,33 @@ function process_folder($file,$type) { ...@@ -116,27 +96,33 @@ function process_folder($file,$type) {
//if (!strstr($elem,"_9.")&&!strstr($elem,"_10.")) //if (!strstr($elem,"_9.")&&!strstr($elem,"_10."))
$tmp_arr[substr($elem,0,17)]++; $tmp_arr[substr($elem,0,17)]++;
} }
} }
//do actual copying
//print_r($tmp_arr); if (count($tmp_arr)==0){
foreach($tmp_arr as $key=>$val){ die("No images found at the path. Exit.\n");
if ($val!=10) { }
for ($i=1;$i<11;$i++){
if (is_file("$url/$file/{$key}_$i.$type")){ //do actual copying
//print_r($tmp_arr);
foreach($tmp_arr as $key=>$val){
if ($val!=$N){
for ($i=1;$i<=$N;$i++){
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment