This commit is contained in:
2019-10-16 03:41:42 -07:00
parent 7c96c474ee
commit 754c5a0d2e
11 changed files with 202 additions and 225 deletions

200
Yuba.php
View File

@@ -35,7 +35,7 @@ require("filetypes.php");
// Manual prefs
$wopt_steps = 8; // total number of steps
$wopt_steps = 7; // total number of steps
$wopt_currstep = 1;
if ($p['debug']) { $wopt_clear = 0; } else { $wopt_clear = 1; }
$wopt_debug_unique = 0;
@@ -307,6 +307,7 @@ $dbo->exec("CREATE TABLE files (
thumb_height INTEGER,
thumb_tool TEXT,
icon_filename TEXT,
icon_tool TEXT,
contents_filename TEXT
)");
@@ -421,6 +422,7 @@ $fids = array();
$noread = array();
$fx = new SplFixedArray($passed_file);
$splcount = 0;
$bline = array();
echo ProgressBar::start($passed_total,"Prescan (".stepString().")");
@@ -431,6 +433,8 @@ foreach ($files as $splFileInfo) {
$shellpath = escapeshellarg($splFileInfo->getPathname());
$realpath = $splFileInfo->getRealPath();
$fid = md5($splFileInfo->getSize().$splFileInfo->getMtime().$splFileInfo->getBasename());
$key = md5($pathname);
$pkey = md5($path);
@@ -444,7 +448,6 @@ foreach ($files as $splFileInfo) {
if ($splFileInfo->getType() != "dir" && $splFileInfo->getType() != "link") {
$fid = md5($splFileInfo->getSize().$splFileInfo->getMtime().$splFileInfo->getBasename());
$dx[$fid][] = $pathname;
$fx[$splcount] = array($fid, $pathname);
$family[$key]['fid'] = $fid;
@@ -473,22 +476,22 @@ foreach ($files as $splFileInfo) {
// Create batch
$line = array();
if ($p['thumbs'] || $p['icons'] || $p['meta'] || $p['hash'] || $p['contents'] || $p['spotlight']) {
$parts = array();
$parts[] = $bin_php;
$parts[] = escapeshellarg(realpath("helper2.php"));
$parts[] = escapeshellarg(realpath("helper.php"));
$parts[] = $i;
$parts[] = $passed_total;
$parts[] = $fid;
$parts[] = escapeshellarg($pathname);
$parts[] = $splFileInfo->getType();
$parts[] = escapeshellarg($bpath);
$parts[] = $mytime;
$tcmd = implode(" ",$parts);
msg($tcmd);
$line[] = $tcmd;
//msg($tcmd);
$bline[] = $tcmd;
}
@@ -508,10 +511,9 @@ foreach ($files as $splFileInfo) {
}
$batchfile = $tmpdir."/__batch.sh";
if (!empty($line)) {
file_put_contents($batchfile,implode("\n", $line));
$batchfile = $tmpdir."/batch.sh";
if (!empty($bline)) {
file_put_contents($batchfile,implode("\n", $bline));
msg("Writing batch to file");
}
@@ -591,41 +593,16 @@ $dbo->exec($stmt);
$wopt_currstep++;
// Directory Previews
// Init Spotlight DB
//////////////////////////////////////////
echo ProgressBar::start(count($fx),"Searching for directory previews (".stepString().")");
foreach ($fx as $array) {
$fid = $array[0];
$pathname = $array[1];
if (in_array(basename($pathname),$p['p_files'])) {
$dpreview[dirname($pathname)] = $fid;
}
echo ProgressBar::next();
}
echo ProgressBar::finish($wopt_clear);
if ($p['spotlight']) { $dbo->exec("CREATE TABLE mdls (id INTEGER PRIMARY KEY,".implode(",",$cbuild).")"); }
// Helper
//////////////////////////////////////////
if ($p['thumbs'] || $p['icons'] || $p['meta'] || $p['hash'] || $p['contents']) {
if (file_exists($batchfile)) {
echo ProgressBar::start($passed_file,"Creating batch (".stepString().")",1);
$batchfile = $tmpdir."/_batch.sh";
$helper = realpath("helper.php");
foreach ($fx as $count => $array) {
$fid = $array[0];
$pathname = $array[1];
$tcmd = $bin_php." ".escapeshellarg($helper)." ".$fid." ".escapeshellarg($pathname)." ".escapeshellarg($bpath)." ".$mytime."; printf '\\n".ProgressBar::next()."'";
msg($tcmd);
$line[] = $tcmd;
}
file_put_contents($batchfile,implode("\n", $line));
echo ProgressBar::finish($wopt_clear);
echo ProgressBar::start($passed_file,"Running batch (".stepString().")");
if ($p['parallel']) {
passthru($bin_parallel." < ".$batchfile);
@@ -648,101 +625,7 @@ $dbp->exec("CREATE INDEX IF NOT EXISTS mediainfo_index ON mediainfo (fid)");
$dbp->exec("CREATE INDEX IF NOT EXISTS thumbs_index ON thumbs (fid)");
$dbp->exec("CREATE INDEX IF NOT EXISTS icons_index ON icons (fid)");
// Spotlight
//////////////////////////////////////////
$mb['i'] = array( "PixelWidth",
"PixelHeight",
"Latitude",
"Longitude",
"DurationSeconds",
"UseCount",
"FSInvisible",
"NumberOfPages",
"PageHeight",
"PageWidth",
"TotalBitRate" );
$mb['t'] = array( "Title",
"ContentType",
"Creator",
"FSCreatorCode",
"Kind",
"FSTypeCode" );
$mb['a'] = array( "UserTags",
"WhereFroms",
"EncodingApplications" );
$mb['d'] = array( "DateAdded",
"LastUsedDate",
"ContentModificationDate",
"ContentCreationDate" );
$ibuild[] = ":pid, :spotlight";
$cbuild[] = "pid TEXT, spotlight TEXT";
foreach (array_merge($mb['i'],$mb['d']) as $item) {
$cbuild[] = $item." INTEGER";
$ibuild[] = ":".$item;
}
foreach (array_merge($mb['t'],$mb['a']) as $item) {
$cbuild[] = $item." TEXT";
$ibuild[] = ":".$item;
}
$dbo->exec("CREATE TABLE mdls (".implode(",",$cbuild).")");
if ($p['spotlight']) {
echo ProgressBar::start($passed_total,"Spotlight (".stepString().")");
foreach ($files as $splFileInfo) {
$path = $splFileInfo->getPathname();
msg($path);
$pid = md5($path);
$shellpath = escapeshellarg($path);
$mdls = shell_exec("mdls -plist - ".$shellpath." 2>&1");
if (substr_count(@$mdls,"\n") > 1) {
$spotlight = $parser->parseString(utf8_for_xml($mdls));
} else {
$spotlight = array();
}
$stmt = $dbo->prepare("INSERT INTO mdls VALUES (".implode(",",$ibuild).")");
foreach ($mb as $key => $list) {
foreach ($list as $item) {
if (@$spotlight["kMDItem".$item]) {
$stmt->BindValue(":pid",$pid);
$stmt->BindValue(":spotlight",$mdls);
switch($key) {
case "i":
case "t":
$stmt->BindValue(":".$item,$spotlight["kMDItem".$item]);
break;
case "a":
$stmt->BindValue(":".$item,serialize($spotlight["kMDItem".$item]));
break;
case "d":
$stmt->BindValue(":".$item,strtotime($spotlight["kMDItem".$item]));
break;
}
}
}
}
$stmt->execute();
echo ProgressBar::next(true);
}
echo ProgressBar::finish($wopt_clear);
}
$dbo->exec("CREATE INDEX IF NOT EXISTS mdls_index ON mdls (id)");
// Files
//////////////////////////////////////////
@@ -755,7 +638,7 @@ foreach ($files as $splFileInfo) {
// DB
$stmt = $dbo->prepare("INSERT INTO files VALUES (:pid, :fid, :Pathname, :Path, :Filename, :Extension, :Type, :Size, :Inode, :Perms, :Owner, :ATime, :MTime, :CTime, :LinkTarget, :RealPath, :stat, :items, :newest, :fkind, :gfi_type, :gfi_attr, :gfi_created, :has_exif, :has_mediainfo, :has_hash, :thumb_filename, :thumb_width, :thumb_height, :thumb_tool, :icon_filename, :contents_filename)");
$stmt = $dbo->prepare("INSERT INTO files VALUES (:pid, :fid, :Pathname, :Path, :Filename, :Extension, :Type, :Size, :Inode, :Perms, :Owner, :ATime, :MTime, :CTime, :LinkTarget, :RealPath, :stat, :items, :newest, :fkind, :gfi_type, :gfi_attr, :gfi_created, :has_exif, :has_mediainfo, :has_hash, :thumb_filename, :thumb_width, :thumb_height, :thumb_tool, :icon_filename, :icon_tool, :contents_filename)");
// Identify dir, file, link or bundle dir
@@ -880,9 +763,25 @@ foreach ($files as $splFileInfo) {
// Pool
if ($type == "file") {
if ($type == "dir") {
unset($fetch_exif, $fetch_media, $fetch_hash, $fetch_thumb, $yes_exif, $yes_media, $yes_hash);
unset($fetch_icon);
$fetch_icon = @$dbp->query("SELECT * FROM icons WHERE fid='".$pid."'")->fetch();
if (@$fetch_icon['relative_path']) {
$stmt->BindValue(":icon_filename",$fetch_icon['relative_path']);
$stmt->BindValue(":icon_tool",$fetch_icon['tool']);
}
} elseif ($type == "file") {
$fetch_icon = @$dbp->query("SELECT * FROM icons WHERE fid='".$fid."'")->fetch();
if (@$fetch_icon['relative_path']) {
$stmt->BindValue(":icon_filename",$fetch_icon['relative_path']);
$stmt->BindValue(":icon_tool",$fetch_icon['tool']);
}
unset($fetch_exif, $fetch_media, $fetch_hash, $fetch_thumb, $fetch_icon, $yes_exif, $yes_media, $yes_hash);
$yes_exif = $dbp->query("SELECT rowid FROM exiftool WHERE fid='".$fid."'")->fetch()[0];
$stmt->BindValue(":has_exif",$yes_exif);
@@ -896,9 +795,8 @@ foreach ($files as $splFileInfo) {
$yes_contents = $dbp->query("SELECT relative_path FROM contents WHERE fid='".$fid."'")->fetch()[0];
$stmt->BindValue(":contents_filename",$yes_contents);
if (!in_array($extension, $p['t_skip'])) {
$fetch_thumb = $dbp->query("SELECT * FROM thumbs WHERE fid='".$fid."'")->fetch();
}
$fetch_thumb = $dbp->query("SELECT * FROM thumbs WHERE fid='".$fid."'")->fetch();
if (@$fetch_thumb['relative_path']) {
$stmt->BindValue(":thumb_filename",$fetch_thumb['relative_path']);
$stmt->BindValue(":thumb_width",$fetch_thumb['width']);
@@ -907,30 +805,8 @@ foreach ($files as $splFileInfo) {
} else {
$stmt->BindValue(":thumb_filename",null);
}
$fetch_icon = $dbp->query("SELECT * FROM icons WHERE fid='".$fid."'")->fetch();
if (@$fetch_icon['relative_path']) {
$stmt->BindValue(":icon_filename",$fetch_icon['relative_path']);
} else {
$stmt->BindValue(":icon_filename",null);
}
} elseif ($type == "dir") {
if (is_array(@$dpreview) && @$dpreview[$pathname]) {
$fetch_thumb = $dbp->query("SELECT * FROM thumbs WHERE fid='".$dpreview[$pathname]."'")->fetch();
if (@$fetch_thumb['relative_path']) {
$stmt->BindValue(":thumb_filename",$fetch_thumb['relative_path']);
$stmt->BindValue(":thumb_width",$fetch_thumb['width']);
$stmt->BindValue(":thumb_height",$fetch_thumb['height']);
$stmt->BindValue(":thumb_tool",$fetch_thumb['tool']);
} else {
$stmt->BindValue(":thumb_filename",null);
}
}
}
// ------------------------------------------------ //
@@ -1109,7 +985,7 @@ while ($row_a = $loop->fetch()) {
} elseif (!$found) {
// find a single value
list($kind,$item) = explode("^",$dindex);
list($kind,$item) = @explode("^",$dindex);
if (@$m[$kind][$item]) {
$stmt->BindValue(":".$name,@sanitize($m[$kind][$item],$type));
$found = 1;