changeset 954:24f155a2e501

More work ... on faptool!
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Nov 2014 09:03:39 +0200
parents 3b18afe14e46
children f931fd35136c
files faptool.php
diffstat 1 files changed, 48 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/faptool.php	Fri Nov 28 08:57:41 2014 +0200
+++ b/faptool.php	Fri Nov 28 09:03:39 2014 +0200
@@ -93,11 +93,12 @@
   return wtExec(
     "/usr/local/bin/openmpt123"
     ,
-    "--quiet ".
+    "--force --quiet ".
     "--samplerate ".$sfreq." ".
     "--channels ".$schannels." ".
     "--playtime ".$sduration." ".
-    escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename));
+    escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename),
+    1);
 }
 
 
@@ -120,21 +121,24 @@
 }
 
 
-function wtRenderConvertEntryToSource()
+function wtRenderConvertEntryToSource($filename, $edata, &$pdata)
 {
-/*
-  if (entry is module file)
+  echo "CHECKING: ".$filename." / ".$edata["id"]."\n";
+
+  switch ($edata["class"])
   {
-    // Construct output filename
-    return wtRenderSample();
+    case EFILE_AUDIO:
+      // Construct output filename
+      $outFilename = stMakePath(FALSE, TRUE, array("output.wav"));
+      if ($edata["mime"] == "audio/x-mod")
+        return wtRenderSample($filename, $outFilename);
+      else
+        return wtConvertSample($filename, $outFilename, array());
+      break;
+    case EFILE_IMAGE:
+      // Construct output filename
+      //return wtConvertImage();
   }
-  else
-  if (entry is image file)
-  {
-    // Construct output filename
-    return wtConvertImage();
-  }
-*/
   return FALSE;
 }
 
@@ -217,6 +221,7 @@
       isset($pdata["file"]) ? $pdata["file"]["filetype"] : "",
       isset($pdata["file"]) ? $pdata["file"]["filename"] : ""
       );
+    return TRUE;
   }
   else
   if ($mode != "upd")
@@ -238,7 +243,15 @@
         ", can't attempt to generate preview.\n";
       return FALSE;
     }
-    
+
+    // Actual entry filename + path
+    $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"]));
+    if (!file_exists($filename))
+    {
+      echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n";
+      return FALSE;
+    }
+
     // Preview source file does not exist, let's see ..
     if (!isset($fileTypeData[$efile["filetype"]]))
     {
@@ -249,6 +262,7 @@
 
     $found = FALSE;
     $edata = $fileTypeData[$efile["filetype"]];
+    $edata["id"] = $efile["filetype"];
 
     if ($edata["class"] == EFILE_ARCHIVE)
     {
@@ -265,20 +279,26 @@
       while (($dentry = readdir($dir)) !== false)
       {
         $fname = $path."/".$dentry;
-        if (is_file($fname))
-        {
-          echo $fname."\n";
-          // check file type against entry's preview_type
-          // if match, render / convert / cp to as source and exit loop.
-        }
+        // check file type against entry's preview_type
+        // if match, render / convert / cp to as source and exit loop.
+        if (is_file($fname) &&
+          ($mdata = stProbeFileInfo($fname, TRUE)) !== false &&
+          $mdata["class"] == $compo["preview_type"] &&
+          ($found = wtRenderConvertEntryToSource($fname, $mdata, $pdata)) === true)
+            break;
       }
+
+      // Cleanup
       closedir($dir);
-
       wtPurgeDir($path);
-    } // archive
-//    else
-//      $found = wtRenderConvertEntryToSource();
-    
+    }
+    else
+    if ($edata["class"] == $compo["preview_type"])
+    {
+      // Single file
+      $found = wtRenderConvertEntryToSource($filename, $edata, $pdata);
+    }
+
     if (!$found)
     {
       echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n";
@@ -515,10 +535,7 @@
       die("No filename specified.\n");
 
     if (($finfo = finfo_open()) === false)
-    {
-      stLogError("Internal error. Failed to initialize finfo().");
-      return stError("Internal error, failed to probe file.");
-    }
+      die("Internal error. Failed to initialize finfo().");
 
     for ($i = 2; $i < $argc; $i++)
     {
@@ -533,7 +550,7 @@
         "Probed : ".$sdata."\n".
         "Mime   : ".$smime."\n";
 
-      if (($info = stProbeFileInfo($filename)) !== false)
+      if (($info = stProbeFileInfo($filename, TRUE)) !== false)
       {
         $tmp = array();
         foreach ($info as $ikey => $ival)