# HG changeset patch # User Matti Hamalainen # Date 1417121157 -7200 # Node ID 7fdf03e6a80d0df8d5c6a0f6cd669b6f9ce946a7 # Parent 0db85a37aa96adc5312985a9bf2a4573c8bc3657 More work on faptool. diff -r 0db85a37aa96 -r 7fdf03e6a80d faptool.php --- a/faptool.php Thu Nov 27 22:41:49 2014 +0200 +++ b/faptool.php Thu Nov 27 22:45:57 2014 +0200 @@ -175,7 +175,7 @@ // Create temporary directory wtPurgeDir($path); - stMakeDir($path, 0700); + wtMakeDir($path, 0700); if (!is_dir($path) || chdir($path) === false) { @@ -278,38 +278,57 @@ // First, check if we have a source preview file if (!isset($pdata["file"])) { -/* - if (previewSourceFile does not exist) - { - if (entry is module file) + // No source preview, check if we have entry file either? + if ($efile === false) + { + echo + "INFO: No entry file for ".wtNiceName($compo, $entry, $efile). + ", can't attempt to generate preview.\n"; + return FALSE; + } + + // Preview source file does not exist, let's see .. + if (!isset($fileTypeData[$efile["filetype"]])) { - render sample + echo + "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; + return FALSE; + } + + $edata = $fileTypeData[$efile["filetype"]]; + + if ($edata["class"] == EFILE_ARCHIVE) + { + // Entry is an archive file .. + $done = false; + /* + wtScanArchive( + $efile, + stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"]), + "wtCheckOneArchiveFile", $compo["preview_type"]); + + unpack to tempdir + if compo preview type is image, scan archive for images .. + */ } else - if (entry is image file) + $done = wtHandleSingleEntryPreview($compo, $entry, $efile, $edata, $pdata); + + if (!$done) { - convert image - } - else - if (entry is archive) - { - if compo preview type is image, scan archive for images .. + echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n"; + return FALSE; } } - if (previewFiles older than previewSourceFile) - { - if (source == audio) - convert via avconv - else - if (source == image) - convert via imagick - } + // Either we now have a sourcefile or generated file +/* + if (source == audio) + convert via avconv + else + if (source == image) + convert via imagick - // Based on compo / entry preview type .. - - // Convert preview image file, if any - // Create thumbnail for it, too wtConvertImage($inFilename, $outFilename, "previewImageSize", "previewImageType", "previewImageQuality", FALSE); @@ -318,7 +337,6 @@ "previewThumbSize", "previewThumbType", "previewThumbQuality", TRUE); */ - } return TRUE; } @@ -331,7 +349,7 @@ // // Create directories // -function stMakeDir($path, $perm) +function wtMakeDir($path, $perm) { if (!file_exists($path)) { @@ -342,30 +360,28 @@ } -function stInitializeDirs() +function wtInitializeDirs() { global $setEntryPath, $setPreviewPath, $setThumbDir, $setEntryPathPerms, $setPrevPathPerms; echo "Checking for missing directories ...\n"; - stMakeDir($setEntryPath, $setEntryPathPerms); - stMakeDir($setPreviewPath, $setPrevPathPerms); + wtMakeDir($setEntryPath, $setEntryPathPerms); + wtMakeDir($setPreviewPath, $setPrevPathPerms); foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) { - stMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); - stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); - stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); + wtMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); + wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); + wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); } } -// -// Main program starts -// -if ($argc < 2) +function wtShowHelp() { + global $argv; echo "faptool - Do stuff with FAPWeb database\n". "(C) Copyright 2014 ccr/TNSP\n". @@ -407,9 +423,18 @@ " and adds generated infofile.txt to packages.\n". */ "\n"; +} + +// +// Main program starts +// +if ($argc < 2) +{ + wtShowHelp(); exit; } + // Try to connect to database $spec = stGetSetting("sqlDB"); if (($db = stConnectSQLDBSpec($spec)) === false) @@ -440,17 +465,21 @@ // Act according to specified command switch (substr(stCArgLC(1), 0, 3)) { + case "-?": case "--h": + wtShowHelp(); + exit; + break; + case "ini": // // Initialize the data directories etc // - stInitializeDirs(); + wtInitializeDirs(); break; case "pro": { - $filename = stCArg(2); - if ($filename == "") + if ($argc < 2) die("No filename specified.\n"); if (($finfo = finfo_open()) === false) @@ -459,16 +488,30 @@ return stError("Internal error, failed to probe file."); } - $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); - $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); - finfo_close($finfo); + for ($i = 2; $i < $argc; $i++) + { + $filename = $argv[$i]; + + $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); + $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); - echo - "Probed: ".$sdata."\n". - "Mime : '".$smime."'\n"; + echo + "\n". + "File : ".$filename."\n". + "Probed : ".$sdata."\n". + "Mime : ".$smime."\n"; - if (($finfo = stProbeFileInfo($filename)) !== false) - print_r($finfo); + if (($info = stProbeFileInfo($filename)) !== false) + { + $tmp = array(); + foreach ($info as $ikey => $ival) + $tmp[] = $ikey."='".$ival."'"; + + echo "Data : ".implode(", ", $tmp)."\n"; + } + } + + finfo_close($finfo); } break; @@ -478,7 +521,7 @@ if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) { printf( - "==%'=-".($setTermWidth-2)."s\n". + "==%'=-".($setTermWidth-2)."s\n", sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) ); echo str_repeat("-", $setTermWidth)."\n"; @@ -487,7 +530,7 @@ { foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) { - if ($efile["delete"] != 0) + if ($efile["deleted"] != 0) { echo "X"; }