This commit is contained in:
2018-09-05 00:26:26 -07:00
parent bae448657b
commit ca7a7a8a58
4 changed files with 147 additions and 42 deletions

View File

@@ -3,7 +3,7 @@
// Yuba
// //
//////////////////////////////////////////
$version = "0.7.4";
$version = "0.7.5";
ini_set('memory_limit', '4096M');
date_default_timezone_set("America/Los_Angeles");
@@ -213,6 +213,7 @@ $dbo->exec("CREATE TABLE files (
Filename TEXT,
Extension TEXT,
Type TEXT,
Size INTEGER,
Inode INTEGER,
Perms INTEGER,
Owner TEXT,
@@ -227,7 +228,6 @@ $dbo->exec("CREATE TABLE files (
gfi_type TEXT,
gfi_attr TEXT,
gfi_created TEXT,
Size INTEGER,
has_exif INTEGER,
has_mediainfo INTEGER,
has_hash INTEGER,
@@ -833,6 +833,7 @@ foreach ($files as $splFileInfo) {
$stmt->BindValue(":Filename",$filename);
$stmt->BindValue(":Extension",$extension);
//stat
$stmt->BindValue(":stat",$sty[$j]);
if ($type == "link") {
@@ -864,8 +865,6 @@ foreach ($files as $splFileInfo) {
if ($type == "file") {
$fid = md5($splFileInfo->getSize().$splFileInfo->getMtime().$splFileInfo->getBasename());
$stmt->BindValue(":fid",$fid);
} else {
$stmt->BindValue(":fid",null);
}
// Size
@@ -886,8 +885,6 @@ foreach ($files as $splFileInfo) {
if ($type == "dir" || $type == "bundle" ) {
$items = chop(@shell_exec("find ".$shellpath." \( ! -regex '.*/\..*' \) | wc -l 2>&1"))-1;
$stmt->BindValue(":items",@$items);
} else {
$items = null;
}
// ------------------------------------------------ //
@@ -897,8 +894,6 @@ foreach ($files as $splFileInfo) {
if ($type == "dir") {
$newest = @filemtime(chop(shell_exec("find ".$shellpath." -type f -not -path '*/\.*' -print0 | xargs -0 stat -f \"%m %N\" | sort -rn 2>&1 | head -1 | cut -f2- -d\" \"")));
$stmt->BindValue(":newest",@$newest);
} else {
$newest = null;
}
// ------------------------------------------------ //
@@ -1027,6 +1022,20 @@ if (file_exists($error_log_file)) { echo file_get_contents($error_log_file); }
$seconds = floor($time = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]);
$dbo->exec("UPDATE _skim SET status='completed_in_".$seconds."'");
// rsync
if ($p['rsync_dest']) {
echo "\nrsync...\n";
$command = "rsync -avv -e ssh ".$bpath." ".$p['rsync_dest'];
$count = trim(shell_exec("find ".escapeshellarg($bpath)." | wc -l"));
echo ProgressBar::start($count,"rsync");
$pipe = popen($command, "r");
while(fgets($pipe, 2048)) { echo ProgressBar::next(); }
pclose($pipe);
echo ProgressBar::finish();
}
echo "Finished in ".$seconds." seconds\n\n";
unset($dbo, $dbp, $files, $family, $fx);

View File

@@ -9,7 +9,7 @@ class ProgressBar {
protected static $total = 0;
public static function display($message = null) {
$string = "PROGRESS:".round((self::$done/self::$total)*100,2);
$string = "PROGRESS:".floor((self::$done/self::$total)*100);
if ($message) {
return "\n".$string."\n".$message;
} elseif (!strpos(__FILE__,".app")) {
@@ -50,6 +50,10 @@ function getParents($zpath, $pathname) {
}
*/
function stringPrint($string) {
echo $string.@str_repeat(" ", (10-strlen($string)));
}
function shortlabel($pathname, $max = 99, $pad = false) {
$basename = basename($pathname);
$suffix = "(...).".pathinfo($basename,PATHINFO_EXTENSION);
@@ -58,6 +62,9 @@ function shortlabel($pathname, $max = 99, $pad = false) {
} else {
$return = $basename;
}
if ($pad) {
$return = $return.@str_repeat(" ", ($max-strlen($return)));
}
return $return;
}

View File

@@ -185,7 +185,7 @@
else
{
$collapse = !($level+1<=1 || $title===true || (is_string($title) && substr($title,0,1)=='*'));
$collapse = false; // hack
$collapse = false;
$result .= "\n<div style='".($collapse?'height:12px':'').";margin-top:2px;margin-bottom:2px;border:1px solid grey;padding:3px;margin-left:15px;background-color:rgb(".(255-($level*10)).",".(255-($level*10)).",".(255-($level*10)).");overflow:hidden;'>\n<div id='tree' style='background-color:silver;font-size:9px;cursor:pointer;float:right;border:1px solid black;width:10px;height:10px;text-align:center;padding:0px;overflow:hidden;' onclick=\"if(this.parentNode.style.height=='12px'){this.parentNode.style.height='';this.innerHTML='-'}else{this.parentNode.style.height='12px';this.innerHTML='+'}\">".($collapse?'+':'-')."</div>";
}
$result .= debug ($value, $title, $plain, $limit, $level+1);

View File

@@ -1,9 +1,10 @@
<?
/////////////////////////////////////////////////////////////////
// Yuba RTC Browser
// Skim RTC Browser
/////////////////////////////////////////////////////////////////
require "togggle.php";
require "lib/debug.php";
$db_dir = "skim";
@@ -16,11 +17,15 @@ $pad = 28;
<head>
<style>
html { word-wrap: break-word; }
html { font-family: Helvetica; word-wrap: break-word; }
div.container { display: flex; flex-flow: row wrap; justify-content: center; }
div.item { width: <?=$icon_size+$pad;?>px; height: <?=$icon_size+$pad;?>px; padding: <?=$pad;?>px; }
div.item { font-family: Helvetica; font-size: 11px; }
div.item { font-size: 11px; }
div.flexfill { width: <?=$icon_size+($pad*3);?>px; height: 1px; }
div.size { color: grey; margin-top: 3px; }
img.thumb { padding: 6px; border: 1px solid gainsboro; }
img { margin-bottom: 8px; }
@@ -33,20 +38,50 @@ img { margin-bottom: 8px; }
// Functions
function XML2Array(SimpleXMLElement $parent)
{
$array = array();
foreach ($parent as $name => $element) {
($node = & $array[$name])
&& (1 === count($node) ? $node = array($node) : 1)
&& $node = & $node[];
$node = $element->count() ? XML2Array($element) : trim($element);
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
return $array;
}
class plistParser extends XMLReader {
public function parseString($string) { $this->XML($string); return $this->process(); }
private function process() {
$this->read();
if($this->nodeType !== XMLReader::DOC_TYPE || $this->name !== "plist") { throw new Exception(sprintf("Error parsing plist. nodeType: %d -- Name: %s", $this->nodeType, $this->name), 2); }
if(!$this->next("plist") || $this->nodeType !== XMLReader::ELEMENT || $this->name !== "plist") { throw new Exception(sprintf("Error parsing plist. nodeType: %d -- Name: %s", $this->nodeType, $this->name), 3); }
$plist = array(); while($this->read()) { if($this->nodeType == XMLReader::ELEMENT) { $plist[] = $this->parse_node(); } }
if(count($plist) == 1 && $plist[0]) { return $plist[0]; } else { return $plist; }
}
private function parse_node() {
if($this->nodeType !== XMLReader::ELEMENT) return;
switch($this->name) {
case 'data': return base64_decode($this->getNodeText()); break;
case 'real': return floatval($this->getNodeText()); break;
case 'string': return $this->getNodeText(); break;
case 'integer': return intval($this->getNodeText()); break;
case 'date': return $this->getNodeText(); break;
case 'true': return true; break;
case 'false': return false; break;
case 'array': return $this->parse_array(); break;
case 'dict': return $this->parse_dict(); break;
default: throw new Exception(sprintf("Not a valid plist. %s is not a valid type", $this->name), 4);
}
}
private function parse_dict() {
$array = array(); $this->nextOfType(XMLReader::ELEMENT);
do { if($this->nodeType !== XMLReader::ELEMENT || $this->name !== "key") { if(!$this->next("key")) { return $array; } } $key = $this->getNodeText(); $this->nextOfType(XMLReader::ELEMENT); $array[$key] = $this->parse_node(); $this->nextOfType(XMLReader::ELEMENT, XMLReader::END_ELEMENT); }
while($this->nodeType && !$this->isNodeOfTypeName(XMLReader::END_ELEMENT, "dict")); return $array;
}
private function parse_array() {
$array = array(); $this->nextOfType(XMLReader::ELEMENT);
do { $array[] = $this->parse_node(); $this->nextOfType(XMLReader::ELEMENT, XMLReader::END_ELEMENT); }
while($this->nodeType && !$this->isNodeOfTypeName(XMLReader::END_ELEMENT, "array")); return $array;
}
private function getNodeText() { $string = $this->readString(); $this->nextOfType(XMLReader::END_ELEMENT); return $string; }
private function nextOfType() { $types = func_get_args(); $this->read(); while($this->nodeType && !(in_array($this->nodeType, $types))) { $this->read(); } }
private function isNodeOfTypeName($type, $name) { return $this->nodeType === $type && $this->name === $name; }
}
function breadcrumbs($zpath, $pathname) {
if (!$pathname) {
@@ -98,6 +133,7 @@ function findicon($filename) {
$db_file = $_GET['db'];
$pid = $_GET['pid'];
$search = $_POST['query'];
if ($db_file) {
@@ -107,7 +143,9 @@ if ($db_file) {
if (!is_readable($db_file)) { echo "can't read db file"; die; }
$dbo = new PDO("sqlite:".$db_file);
$dbx = new PDO("sqlite:".dirname($db_file)."/pool.sqlite3");
$dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$dbx->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// Get zpath
@@ -129,14 +167,20 @@ if ($db_file) {
// Breadcrumbs
$crumb = breadcrumbs($zpath,$view['Pathname']);
$xc = "";
foreach ($crumb as $myparts) {
if ($myparts[0] === null) {
echo $myparts[1];
$xc .= $myparts[1];
} else {
echo "<a href='?db=".$db_file."&pid=".$myparts[0]."'>".$myparts[1]."</a> > ";
$xc .= "<a href='?db=".$db_file."&pid=".$myparts[0]."'>".$myparts[1]."</a> > ";
}
}
if (!$search) { echo $xc; echo "<hr>"; }
// Search
echo "<form action='' method='post'><input type='text' name='query' size='50' value='".$search."'><input type='submit' value='query'></form>";
echo "<hr>";
@@ -144,7 +188,7 @@ if ($db_file) {
$children = unserialize($array);
if (!$children) {
if (!$children && !$search) {
/////////////////////////////////////////////////////////////////
@@ -155,6 +199,8 @@ if ($db_file) {
echo "<td valign='top'>";
$row_a = $dbo->query("SELECT * FROM files WHERE (pid='".$pid."')")->fetchAll()[0];
$row_b = $dbo->query("SELECT * FROM mdls WHERE (pid='".$pid."')")->fetchAll()[0];
$row_c = $dbx->query("SELECT * FROM exiftool WHERE (fid='".$row_a['fid']."')")->fetchAll()[0];
$row_d = $dbx->query("SELECT * FROM mediainfo WHERE (fid='".$row_a['fid']."')")->fetchAll()[0];
if ($row_a['thumb_filename']) {
$width = $row_a['thumb_width'];
@@ -162,7 +208,7 @@ if ($db_file) {
$realfile = dirname($db_file).$row_a['thumb_filename'];
$icon = "<img src='".$realfile."' width='".$width."' height='".$height."'>";
} else {
$icon = "<img src='".findicon($row_a['Filename'])."' width='".$icon_size."' height='".$icon_size."'>";
$icon = "<img src='".findicon($row_a['Filename'])."' width='512' height='512'>";
}
echo $icon;
@@ -170,13 +216,24 @@ if ($db_file) {
echo "</td>";
echo "<td valign='top'>";
debug($row_a,"file");
echo "</td>";
//$row_b['spotlight'] = simplexml_load_string($row_b['spotlight'],LIBXML_NSCLEAN);
debug(array($row_a),"file");
if ($row_b) {
$parser = new plistParser();
$row_b['spotlight'] = $parser->parseString($row_b['spotlight']);
debug(array($row_b),"mdls");
}
echo "</td><td valign='top'>";
if ($row_c) {
debug(array(unserialize($row_c['tags'])),"exiftool");
}
if ($row_d) {
debug(array(json_decode(json_encode(simplexml_load_string($row_d['info'])))),"mediainfo");
}
echo "<td valign='top'>";
debug($row_b,"mdls");
echo "</td>";
echo "</tr></table>";
@@ -185,7 +242,7 @@ if ($db_file) {
// Dir view
} else {
} elseif (!$search) {
echo "<table><tr><td valign='top'>";
echo "<div class='container'>";
@@ -194,10 +251,14 @@ if ($db_file) {
echo "<div class='item'>";
$row_a = $dbo->query("SELECT * FROM files WHERE (pid='".$item."')")->fetchAll()[0];
//$row_b = $dbo->query("SELECT * FROM mdls WHERE (pid='".$item."')")->fetchAll()[0];
/////////////////////////
$row_a = $dbo->query("SELECT * FROM files WHERE (rowid='".$item."')")->fetchAll()[0];
$row_b = $dbo->query("SELECT * FROM mdls WHERE (rowid='".$item."')")->fetchAll()[0];
//$row_c = $dbo->query("SELECT * FROM milk WHERE (pid='".$item."')")->fetchAll()[0];
/////////////////////////
if ($row_a['thumb_filename']) {
$aspect = $row_a['thumb_width']/$row_a['thumb_height'];
if ($aspect > 1) {
@@ -213,9 +274,17 @@ if ($db_file) {
$icon = "<img class='icon' src='".findicon($row_a['Filename'])."' width='".$icon_size."' height='".$icon_size."'>";
}
$name = htmlentities(shortlabel($row_a['Filename']));
echo "\n<a href='?db=".$db_file."&pid=".$row_a['pid']."'>".$icon."</a>";
echo "\n<a href='?db=".$db_file."&pid=".$row_a['pid']."'>".$icon."</a><br>".$name;
echo "<div class='title'>".htmlentities(shortlabel($row_a['Filename']))."</div>";
if ($row_a['Size']) {
echo "<div class='size'>".human_filesize($row_a['Size'])."</div>";
}
if ($row_a['type'] == "dir" && $row_a['items']) {
echo "<div class='size'>".$row_a['items']." items</div>";
}
echo "</div>";
echo "<br>";
@@ -228,6 +297,24 @@ if ($db_file) {
debug($view,$view['Pathname']);
echo "</td></tr></table>";
} else {
/////////////////////////////////////////////////////////////////
// Search
$result = $dbo->query("SELECT * FROM files WHERE (Filename LIKE '%".$search."%')")->fetchAll();
if (count($result)) {
echo count($result)." results<br>";
foreach ($result as $row) {
$pathbold = str_ireplace($search,"<b>".$search."</b>",$row['Pathname']);
echo "\n<a href='?db=".$db_file."&pid=".$row['pid']."'>".$pathbold."</a><br>";
}
} else {
echo "No results for ".$search;
}
}
} else {
@@ -247,6 +334,8 @@ if ($db_file) {
echo $dbo->query("SELECT type FROM _skim")->fetch()['type'].", ";
echo $dbo->query("SELECT passed_total FROM _skim")->fetch()['passed_total']." files, ";
echo $dbo->query("SELECT status FROM _skim")->fetch()['status'];
$spotlight_status = $dbo->query("SELECT mdutil FROM _skim")->fetch()['mdutil'];
if (strpos($spotlight_status,"disabled")) { echo " (no spotlight)"; }
echo "<br>";
}
}