changeset 941:f3c6c56098ed

And moar.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Nov 2014 00:49:47 +0200
parents 2acb03b775fe
children 7fa6c39ef851
files faptool.php
diffstat 1 files changed, 97 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/faptool.php	Fri Nov 28 00:47:24 2014 +0200
+++ b/faptool.php	Fri Nov 28 00:49:47 2014 +0200
@@ -6,30 +6,6 @@
 stCheckCLIExec();
 
 
-function wtExec($exe, $args, $expect = 0)
-{
-  echo "@@EXEC: ".$exe." ".$args."\n";
-  exec(escapeshellcmd($exe)." ".$args, $output, $code);
-  if ($code !== $expect)
-  {
-    echo
-      "Error executing ".$exe.": ".$code."\n".$args."\n".
-      "------------------------------------------------\n".
-      implode("\n", $output).
-      "------------------------------------------------\n";
-    return FALSE;
-  }
-  return TRUE;
-}
-
-
-function wtExecOrDie($exe, $args)
-{
-  if (wtExec($exe, $args) === false)
-    die();
-}
-
-
 function wtConvertImage($inFilename, $inFileType, $outFilename, $setDim, $setFormat, $setQuality, $thumb)
 {
   global $setPreviewPath;
@@ -144,13 +120,22 @@
 }
 
 
-function wtPurgeDir($path)
+function wtRenderConvertEntryToSource()
 {
-  if (file_exists($path))
+/*
+  if (entry is module file)
   {
-    echo "PURGING: ".$path."\n";
-    //wtExecOrDie("/bin/echo", "-fR ".escapeshellarg($path));
+    // Construct output filename
+    return wtRenderSample();
   }
+  else
+  if (entry is image file)
+  {
+    // Construct output filename
+    return wtConvertImage();
+  }
+*/
+  return FALSE;
 }
 
 
@@ -195,48 +180,6 @@
 }
 
 
-function wtScanArchive($efile, $filename)
-{
-  global $setEntryPath;
-
-  $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $filename));
-
-  echo "Attempting to scan archive file '".$filename."' ...\n";
-
-  if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === false)
-    return FALSE;
-
-  // Scan through files ...
-  $res = FALSE;
-  $dir = opendir($path);
-  while (($dentry = readdir($dir)) !== false)
-  {
-    $fname = $path."/".$dentry;
-  }
-  closedir($dir);
-
-  wtPurgeDir($path);
-  return $res;
-}
-
-
-function wtHandleSingleEntryPreview($compo, $entry, &$efile, $edata, $pdata)
-{
-/*
-  if (entry is module file)
-  {
-    render sample
-  }
-  else
-  if (entry is image file)
-  {
-    convert image
-  }
-*/
-  return FALSE;
-}
-
-
 function wtNiceName($compo, $entry, $efile = FALSE)
 {
   return sprintf(
@@ -250,7 +193,7 @@
 
 function wtHandleEntryPreview($compo, $entry, $mode)
 {
-  global $fileTypeData;
+  global $fileTypeData, $setEntryPath;
 
   // Get current preview file(s) data
   if (!stGetPreviewFileData($compo, $entry, $pdata))
@@ -304,24 +247,36 @@
       return FALSE;
     }
 
+    $done = 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"]),
-        "wtHandleSingleEntryPreviewDispatch", array($compo, $entry, $pdata));
+      $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $filename));
+
+      echo "Attempting to scan archive file '".$filename."' ...\n";
+
+      if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === false)
+        return FALSE;
 
-      unpack to tempdir
-      if compo preview type is image, scan archive for images ..
-      */
+      // Scan through files ...
+      $done = FALSE;
+      $dir = opendir($path);
+      while (($dentry = readdir($dir)) !== false)
+      {
+        $fname = $path."/".$dentry;
+        if (is_file($fname))
+        {
+          echo $fname."\n";
+        }
+      }
+      closedir($dir);
+
+      wtPurgeDir($path);
     }
-    else
-      $done = wtHandleSingleEntryPreview($compo, $entry, $efile, $edata, $pdata);
+//    else
+//      $done = wtRenderConvertEntryToSource();
     
     if (!$done)
     {
@@ -333,18 +288,22 @@
   // Either we now have a sourcefile or generated file
 /*
   if (source == audio)
-    convert via avconv
+  {
+    wtConvertSample();
+  }
   else
   if (source == image)
-    convert via imagick
+  {
+    wtConvertImage($inFilename,
+      stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)),
+      "previewImageSize", "previewImageType",
+      "previewImageQuality", FALSE);
 
-  wtConvertImage($inFilename, $outFilename,
-    "previewImageSize", "previewImageType",
-    "previewImageQuality", FALSE);
-
-  wtConvertImage($inFilename, $outFilename,
-    "previewThumbSize", "previewThumbType",
-    "previewThumbQuality", TRUE);
+    wtConvertImage($inFilename,
+      stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $setThumbPath, $filename)),
+      "previewThumbSize", "previewThumbType",
+      "previewThumbQuality", TRUE);
+  }
 */
   return TRUE;
 }
@@ -356,8 +315,42 @@
 
 
 //
-// Create directories
+// Misc helper functions
 //
+function wtExec($exe, $args, $expect = 0)
+{
+  echo "@@EXEC: ".$exe." ".$args."\n";
+  exec(escapeshellcmd($exe)." ".$args, $output, $code);
+  if ($code !== $expect)
+  {
+    echo
+      "Error executing ".$exe.": ".$code."\n".$args."\n".
+      "------------------------------------------------\n".
+      implode("\n", $output).
+      "------------------------------------------------\n";
+    return FALSE;
+  }
+  return TRUE;
+}
+
+
+function wtExecOrDie($exe, $args)
+{
+  if (wtExec($exe, $args) === false)
+    die();
+}
+
+
+function wtPurgeDir($path)
+{
+  if (file_exists($path))
+  {
+    echo "PURGING: ".$path."\n";
+    //wtExecOrDie("/bin/echo", "-fR ".escapeshellarg($path));
+  }
+}
+
+
 function wtMakeDir($path, $perm)
 {
   if (!file_exists($path))
@@ -612,10 +605,13 @@
             "PrevType : %s\n",
             sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)),
             $previewTypeList[$compo["preview_type"]][0]);
-          
-          printf(" %-3s | %-3s | %-40s |\n",
-            "#ID", "FLG", "Entry name/author");
-          
+
+          if ($mode == "sta")
+          {
+            printf(" %-3s | %-3s | %-40s |\n",
+              "#ID", "FLG", "Entry name/author");
+          }
+
           echo str_repeat("-", $setTermWidth)."\n";
 
           foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
@@ -643,4 +639,9 @@
     break;
 }
 
+/* Dummy
+{
+  
+}
+*/
 ?>
\ No newline at end of file