changeset 898:750b3b57ec61

More prototyping.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 26 Nov 2014 22:36:28 +0200
parents d8fa2aecadcc
children 0cc1d87cdca1
files faptool.php
diffstat 1 files changed, 85 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/faptool.php	Wed Nov 26 21:55:24 2014 +0200
+++ b/faptool.php	Wed Nov 26 22:36:28 2014 +0200
@@ -74,45 +74,39 @@
 }
 
 
-function wtRenderSample()
+function wtRenderSample($inFilename, $outFilename)
 {
-  $sfreq     = intval(stGetSetting("sampleFreq", 44100));
-  $sduration = intval(stGetSetting("sampleDuration", 30));
-  $schannels = intval(stGetSetting("sampleChannels", 1));
+  $sfreq     = intval(stGetSetting("sampleFreq"));
+  $sduration = intval(stGetSetting("sampleDuration"));
+  $schannels = intval(stGetSetting("sampleChannels"));
 
   wtExecOrDie(
-    "/usr/local/bin/openmpt123",
-    
+    "/usr/local/bin/openmpt123"
+    ,
     "--quiet --render ".
     "--samplerate ".$sfreq." ".
     "--channels ".$schannels." ".
     "--playtime ".$sduration." ".
-    escapeshellarg($filename)." -o ".escapeshellarg($sampleFile));
+    escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename));
 }
 
 
-function wtConvertSample()
+function wtConvertSample($inFilename, $outFilename, $opts)
 {
-  $sfreq     = intval(stGetSetting("sampleFreq", 44100));
-  $sduration = intval(stGetSetting("sampleDuration", 30));
-  $schannels = intval(stGetSetting("sampleChannels", 1));
+  $sfreq     = intval(stGetSetting("sampleFreq"));
+  $sduration = intval(stGetSetting("sampleDuration"));
+  $schannels = intval(stGetSetting("sampleChannels"));
 
-  // Convert to desired formats
-  // avconv -t 35 -i xxx_sample.wav -f ogg -c:a vorbis -b:a 95 -ac 1 -map_metadata -1 xxx_sample.ogg
-  $exe = "/usr/local/bin/avconv";
-/*
-  foreach (...)
-  {
-    $args =
-      "-y -t ".intval($sduration)." ".
-      "-i ".escapeshellarg($filename)." ".
-      
-      "-f ".$format." -c:a ".$codec." ".$qualityopt." ".$qualityvalue." ".
-      "-ac ".$schannels." ".
-      "-map_metadata -1 ".
-      escapeshellarg($outFilename);
-  }
-*/
+  foreach ($opts as $okey => $oval)
+    $optStr .= $okey." ".$oval." ";
+  
+  wtExecOrDie(
+    "/usr/local/bin/avconv",
+    "-y -t ".intval($sduration)." ".
+    "-i ".escapeshellarg($inFilename).
+    " ".$optStr." -ac ".$schannels.
+    " -map_metadata -1 ".
+    escapeshellarg($outFilename));
 }
 
 
@@ -144,8 +138,14 @@
       $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename);
       break;
 
+    case "RAR":
+      $exe = "/usr/bin/rar";
+      $args = "e ".escapeshellarg($filename);
+      break;
+
     default:
-      die("Unsupported archive file type: ".$efile["id"]."\n");
+      echo "Unsupported archive file type: ".$efile["id"]."\n";
+      return FALSE;
   }
 
   // Create temporary directory
@@ -171,8 +171,33 @@
 
 function wtHandleEntryPreview($compo, $entry, $mode)
 {
+  // Get current preview file data
+  if (!stGetPreviewFileData($compo, $entry, $pdata))
+    return FALSE;
+
+  if ($entry["file_id"] != 0)
+    $efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"]);
+  else
+    $efile = FALSE;
+
+  // Check preview file(s) status
+  if ($mode == "sta")
+  {
+    printf(" %03d | %s%s%s | %-40s | %-5s | %s\n",
+      $entry["id"],
+      ($efile !== false) ? "1" : ".",
+      isset($pdata["file"]) ? "2" : ".",
+      $pdata["valid"] ? "3" : ".",
+      $entry["name"]." by ".$entry["author"],
+      isset($pdata["file"]) ? $pdata["file"]["filetype"] : "",
+      isset($pdata["file"]) ? $pdata["file"]["filename"] : ""
+      );
+  }
+  else
+  if ($mode == "upd")
+  {
 /*
-  if (previewFile does not exist || previewFile older than entryFile)
+  if (previewSourceFile does not exist)
   {
     if (entry is module file)
     {
@@ -183,6 +208,20 @@
     {
       convert image
     }
+    else
+    if (entry is archive)
+    {
+      if compo preview type is image, scan archive for images ..
+    }
+  }
+
+  if (previewFiles older than previewSourceFile)
+  {
+    if (source == audio)
+      convert via avconv
+    else
+    if (source == image)
+      convert via imagick
   }
 
   // Based on compo / entry preview type ..
@@ -197,6 +236,9 @@
     "previewThumbSize", "previewThumbType",
     "previewThumbQuality", TRUE);
 */
+  }
+  else
+    die("OMG!\n");
 }
 
 
@@ -301,20 +343,27 @@
     $mode = substr(stCArgLC(2), 0, 3);
     switch ($mode)
     {
+      case "upd":
       case "sta":
         foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
+        if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0)
         {
+          $width = 75;
           printf(
-            "\n".
-            "--[ #%03d - %-30s ]---\n".
-            "PrevType : %s\n".
-            "PrevPath : %s\n",
-            $compo["id"], substr($compo["name"], 0, 30),
-            $previewTypeList[$compo["preview_type"]][0],
-            stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])));
+            "==%'=-".($width-2)."s\n".
+            "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");
+          
+          echo str_repeat("-", $width)."\n";
 
           foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry)
             wtHandleEntryPreview($compo, $entry, $mode);
+
+          echo str_repeat("=", $width)."\n\n";
         }
         break;