This commit is contained in:
2019-10-19 05:54:29 -07:00
parent 754c5a0d2e
commit 8166dfa42f
13 changed files with 245 additions and 142 deletions

View File

@@ -13,9 +13,6 @@ $p = unserialize(file_get_contents($prefs_file));
require("functions.php");
require("filetypes.php");
$redirect = "2>&1";
//$redirect = "2> /tmp/yuba/debug.log";
$dm = "";
function dfm ($string, $flag = 0) {
// dumb workaround for debug messages appearing out of order
@@ -39,6 +36,7 @@ $pathname = $argv[4];
$pid = md5($pathname);
$shellpath = escapeshellarg($pathname);
$ext = pathinfo($pathname,PATHINFO_EXTENSION);
$extl = strtolower($ext);
$file = pathinfo($pathname, PATHINFO_BASENAME);
$btype = $argv[5];
$bpath = $argv[6];
@@ -48,6 +46,13 @@ $parser = new plistParser();
$stamp = date("Y-m-d_H-i-s", $mytime);
$messages_log_file = $bpath."/".$stamp."_messages.log";
$error_log_file = $bpath."/".$stamp."_error.log";
if ($p['debug']) {
$redirect = "2>&1 | tee -a /tmp/yuba/debug.log";
} else {
$redirect = "2>> ".$error_log_file;
}
$tmpdir = "/tmp/yuba/".$mytime;
if (!is_dir($tmpdir)) { mkdir($tmpdir,0777,true); dfm("mkdir ",$tmpdir); }
@@ -58,10 +63,10 @@ $dbo = new PDO("sqlite:".$bpath."/".$stamp.".sqlite3");
$dbo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
//$dbo->query("PRAGMA page_size = 4096");
//$dbo->query("PRAGMA cache_size = 10000");
//$dbo->query("PRAGMA locking_mode = EXCLUSIVE");
//$dbo->query("PRAGMA synchronous = NORMAL");
$dbo->query("PRAGMA page_size = 4096");
$dbo->query("PRAGMA cache_size = 10000");
$dbo->query("PRAGMA synchronous = NORMAL");
$dbo->query("PRAGMA locking_mode = NORMAL");
$dbo->query("PRAGMA journal_mode = WAL");
// Pool DB
@@ -70,10 +75,10 @@ $dbp = new PDO("sqlite:".$bpath."/pool.sqlite3");
$dbp->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbp->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
//$dbp->query("PRAGMA page_size = 4096");
//$dbp->query("PRAGMA cache_size = 10000");
//$dbp->query("PRAGMA locking_mode = EXCLUSIVE");
//$dbp->query("PRAGMA synchronous = NORMAL");
$dbp->query("PRAGMA page_size = 4096");
$dbp->query("PRAGMA cache_size = 10000");
$dbp->query("PRAGMA synchronous = NORMAL");
$dbo->query("PRAGMA locking_mode = NORMAL");
$dbp->query("PRAGMA journal_mode = WAL");
$sbatch = array();
@@ -91,10 +96,11 @@ if ($p['thumbs'] && $btype == "file" && $ext != "DS_Store") {
$estring .= " THUMBS";
// "bad" filesizes from generic icons
// "bad" filesizes from generic audio file icons
$discard = array( 3953,
4977,
5019,
7133,
6059,
6616,
17393 );
@@ -105,10 +111,10 @@ if ($p['thumbs'] && $btype == "file" && $ext != "DS_Store") {
if (!is_dir(dirname($tfile))) { @mkdir(dirname($tfile),0777,true); dfm("mkdir ".dirname($tfile)); }
if ($p['thumb_mode'] != 0 && in_array($ext, $p['t_skip'])) {
if ($ext == "DS_Store") {
// file extension is in the skip list
$estring .= " ->t_skip";
dfm("file extension is in the skip list");
dfm("skipping ds_store");
goto icons;
}
@@ -152,41 +158,47 @@ if ($p['thumbs'] && $btype == "file" && $ext != "DS_Store") {
$cmd['vips'] = $bin_vips." ".$shellpath." -o ".$tfile."[Q=90,optimize_coding] --size=".$p['thumb_size'];
$cmd['sox'] = $bin_sox." ".$shellpath." -n trim 0 $(".$bin_exiftool." -s -s -s -duration# ".$shellpath." | awk '{print $1/4}') spectrogram -r -o - | ".$bin_convert." - -quality 85% ".$tfile;
$cmd['ffmpeg'] = $bin_ffmpeg." -ss $(( $(".$bin_mediainfo." --Inform='Video;%Duration%' ".$shellpath." | cut -d'.' -f1) / 10000 )) -i ".$shellpath." -vframes 1 -filter:v scale='400:-1' -q:v 3 ".$tfile;
$cmd['ffmpeg'] = $bin_ffmpeg." -ss $(( $(".$bin_mediainfo." --Inform='Video;%Duration%' ".$shellpath." | cut -d'.' -f1) / 10000 )) -i ".$shellpath." -vframes 1 -filter:v scale='".$p['thumb_size'].":-1' -q:v 3 ".$tfile;
$cmd['ql-thumbnail'] = $bin_qlthumb." ".$shellpath." ".$tfile." public.jpeg ".$p['thumb_size']." ".$p['thumb_size']." .8";
$cmd['qlmanage'] = $bin_qlmanage." -t -s ".$p['thumb_size']." -o ".dirname($tpfile)." ".$shellpath."; ".$bin_sips." -s format jpeg -s formatOptions 80 ".escapeshellarg($tpfile)." --out ".$tfile;
$external_tool = null;
foreach ($p['t_files'] as $tool => $whitelist) {
if (in_array($ext, $whitelist)) {
$external_tool = $tool;
}
}
dfm("external tool for ".$ext." = ".$external_tool);
switch ($p['thumb_mode']) {
case 0: $priority = array($external_tool,"ql-thumbnail","qlmanage"); break;
case 1: $priority = array("ql-thumbnail","qlmanage"); break;
case 2: $priority = array("ql-thumbnail"); break;
case 0: // most files
if (!empty($p['t_b'][$extl])) {
$priority = $p['t_b'][$extl];
} else {
$priority = $p['t_b']['*'];
}
break;
case 1: // some files
if (!empty($p['t_b'][$extl]) && !in_array($p['t_b']['*'],$p['t_b'][$extl])) {
$priority = $p['t_b']['*'];
} else {
$priority = null;
}
break;
}
dfm("thumb mode ".$p['thumb_mode']);
dfm("priority for ".$ext." is: ".print_r($priority,true));
dfm("priority for ".$extl." is: ".print_r($priority,true));
$stmt->BindValue(":fid",$fid);
$stmt->BindValue(":created",time());
if (!is_array($priority)) { $priority = array($priority); }
foreach ($priority as $tool) {
if (empty($cmd[$tool])) { continue; }
dfm($cmd[$tool]);
shell_exec($cmd[$tool]." 2>1");
shell_exec("( ".$cmd[$tool]." ) ".$redirect);
$estring .= " ->".$tool;
$checksize = @filesize($tfile);
if ($checksize) {
if (!empty($discard) && in_array($checksize,$discard)) {
$estring .= " ->discard";
if (in_array($checksize,$discard)) {
$estring .= " ->bdiscard";
dfm($checksize." is in the banned size array");
} else {
$estring .= " ->use";
@@ -204,7 +216,7 @@ if ($p['thumbs'] && $btype == "file" && $ext != "DS_Store") {
}
} else {
$estring .= " ->discard";
dfm($tool." produced a bad file (size=".$checksize.")");
dfm($tool." did not produce a file");
}
}
@@ -218,13 +230,14 @@ if ($p['thumbs'] && $btype == "file" && $ext != "DS_Store") {
// Icons //////////////////////////////////////////
icons:
if ($p['icons'] && ($btype == "file" || $btype == "dir") && $ext != "DS_Store") {
//if ($p['icons'] && ($btype == "file" || $btype == "dir") && $ext != "DS_Store") {
if ($p['icons'] && $ext != "DS_Store") {
dfm("ICONS",1);
$estring .= " ICONS";
if ($p['icon_mode'] != 0 && in_array($ext, $p['i_skip'])) {
if ($p['icon_mode'] != 0 && in_array($extl, $p['i_skip'])) {
$estring .= " ->i_skip";
dfm("file extension is in the skip list");
goto meta;
@@ -257,7 +270,6 @@ if ($p['icons'] && ($btype == "file" || $btype == "dir") && $ext != "DS_Store")
}
$cmd['flacdiricon'] = $bin_flacdiricon." ".$shellpath." ".$p['icon_size']." ".$tfile;
$cmd['flacicon'] = $bin_flacicon." ".$shellpath." ".$p['icon_size']." ".$tfile;
$cmd['ql-icon'] = $bin_qlicon." --input=".$shellpath." --width=".$p['icon_size']." --height=".$p['icon_size']." | ".$bin_pngquant." - -o ".$tfile;
$cmd['qltool'] = $bin_qltool." di ".$shellpath." ".$p['icon_size']." ".$p['icon_size']." | base64 --decode | ".$bin_convert." - -scale 50% - | ".$bin_pngquant." - -o ".$tfile;
@@ -266,7 +278,7 @@ if ($p['icons'] && ($btype == "file" || $btype == "dir") && $ext != "DS_Store")
dfm("icon mode 2, bypassing hash check");
$tool = "ql-icon";
shell_exec($cmd[$tool]." ".$redirect);
shell_exec("( ".$cmd[$tool]." ) ".$redirect);
$stmt->BindValue(":tool",$tool);
dfm($cmd[$tool]);
$estring .= " ->".$tool;
@@ -289,22 +301,39 @@ if ($p['icons'] && ($btype == "file" || $btype == "dir") && $ext != "DS_Store")
} else {
$gfind = array("[","]","{","}");
$greplace = array("\[","\]","\{","\}");
$globsafe = str_replace($gfind,$greplace,$pathname);
if ($btype == "dir") {
dfm($pathname." is a dir, proceeding with directory check");
$stmt->BindValue(":fid",$pid);
$tools = array("flacdiricon","qltool");
if (file_exists($pathname."/Icon\r")) {
dfm("Custom icon found, processing ".$pathname." with qltool");
$tools = array("qltool");
} elseif (glob($globsafe."/".globstring($p['album_files']),GLOB_BRACE) && $test = glob($globsafe."/".globstring($p['cover_exts'],$p['cover_files']),GLOB_BRACE)) {
dfm("Album files and cover found, processing ".$pathname." with flacdiricon");
$cmd['flacdiricon'] = $bin_flacdiricon." ".$shellpath." ".$p['icon_size']." ".escapeshellarg(array_shift($test))." ".$tfile;
$tools = array("flacdiricon");
} else {
dfm("glob ".$pathname."/".globstring($p['album_files']));
dfm("glob ".$pathname."/".globstring($p['cover_exts'],$p['cover_files']));
dfm("Nothing found, skipping ".$pathname);
$tools = array();
}
} else {
$stmt->BindValue(":fid",$fid);
if ($ext == "flac") {
if (in_array($extl, $p['i_sox'])) {
$tools = array("flacicon","ql-icon","qltool");
} else {
$tools = array("ql-icon","qltool");
}
}
unset($mytool);
$mytool = "";
foreach ($tools as $tool) {
if (!@filesize($tfile)) {
shell_exec($cmd[$tool]." ".$redirect);
shell_exec("( ".$cmd[$tool]." ) ".$redirect);
dfm($cmd[$tool]);
$estring .= " ->".$tool;
$mytool = $tool;
@@ -347,8 +376,12 @@ if ($p['icons'] && ($btype == "file" || $btype == "dir") && $ext != "DS_Store")
} else {
$estring .= " ->discard";
dfm($mytool." produced a bad file (size=".$checksize.")");
if (empty($tools)) {
$estring .= " ->gskip";
} else {
$estring .= " ->discard";
}
dfm("tool = ".$mytool." produced a bad file (size=".$checksize.")");
}
@@ -369,13 +402,13 @@ if ($p['meta'] && $btype == "file" && $ext != "DS_Store") {
$estring .= " META";
if (!in_array($ext, $p['e_files']) && !in_array($ext, $p['m_files'])) {
if (!in_array($extl, $p['e_files']) && !in_array($extl, $p['m_files'])) {
$estring .= " ->notmedia";
dfm("file extension ".$ext." is not a media file");
dfm("file extension ".$extl." is not a media file");
goto hashy;
}
if (in_array($ext, $p['e_files'])) {
if (in_array($extl, $p['e_files'])) {
$sql = "SELECT EXISTS(SELECT 1 FROM exiftool WHERE fid='".$fid."')";
dfm($sql);
$check = @$dbp->query($sql)->fetch();
@@ -398,7 +431,7 @@ if ($p['meta'] && $btype == "file" && $ext != "DS_Store") {
}
}
if (in_array($ext, $p['m_files'])) {
if (in_array($extl, $p['m_files'])) {
$sql = "SELECT EXISTS(SELECT 1 FROM mediainfo WHERE fid='".$fid."')";
dfm($sql);
$check = @$dbp->query($sql)->fetch();
@@ -406,7 +439,7 @@ if ($p['meta'] && $btype == "file" && $ext != "DS_Store") {
dfm("creating mediainfo dump");
$stmt = $dbp->prepare("INSERT INTO mediainfo VALUES (:fid, :info)");
$stmt->BindValue(":fid",$fid);
$stmt->BindValue(":info",shell_exec($bin_mediainfo." --Output=JSON ".$shellpath." ".$redirect));
$stmt->BindValue(":info",shell_exec("( ".$bin_mediainfo." --Output=JSON ".$shellpath." ) ".$redirect));
$sbatch[] = $stmt;
$estring .= " ->minfo";
} else {
@@ -462,7 +495,7 @@ if ($p['contents'] && $btype == "file") {
$cpath = $bpath."/contents/".substr($fid, 0, 2);
$cfile = $cpath."/".$fid.".zip";
if (in_array($ext, $p['c_files'])) {
if (in_array($extl, $p['c_files'])) {
$max_size = $p['contents_limit'] * 1000;
if ($ext == ".DS_Store") {
// store all DS_Store files no matter how big
@@ -496,7 +529,7 @@ if ($p['contents'] && $btype == "file") {
// Spotlight //////////////////////////////////////////
if ($p['spotlight']) {
if (@$argv[8]) {
dfm("SPOTLIGHT",1);
$estring .= " SPOTLIGHT";