comparison faptool.php @ 1042:b17c41ffe43b

Implement wtGetExecutable() and use it for getting executable names for external utilities for faptool.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 20 Nov 2015 13:39:20 +0200
parents ed22a3a3027f
children c0e21a405256
comparison
equal deleted inserted replaced
1041:f188caaedf0f 1042:b17c41ffe43b
15 15
16 require_once "mconfig.inc.php"; 16 require_once "mconfig.inc.php";
17 require_once "msite.inc.php"; 17 require_once "msite.inc.php";
18 18
19 19
20 function wtGetExecutable($name, $path = FALSE)
21 {
22 if (stChkSetting($name))
23 return stGetSetting($name);
24 else
25 return $name;
26 }
27
28
20 function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv) 29 function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv)
21 { 30 {
22 global $setPreviewPath; 31 global $setPreviewPath;
23 $isTemp = FALSE; 32 $isTemp = FALSE;
24 33
25 if ($useGfxConv) 34 if ($useGfxConv)
26 { 35 {
27 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit 36 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit
28 $tmpFilename = tempnam($setPreviewPath, "tmp"); 37 $tmpFilename = tempnam($setPreviewPath, "tmp");
29 $isTemp = TRUE; 38 $isTemp = TRUE;
30 if (wtExec( 39 if (wtExec(wtGetExecutable("gfxconv"),
31 "/usr/local/bin/gfxconv",
32 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($tmpFilename), 40 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($tmpFilename),
33 0) === false) 41 0) === false)
34 return FALSE; 42 return FALSE;
35 43
36 if (!file_exists($tmpFilename)) 44 if (!file_exists($tmpFilename))
90 $sfreq = intval(stGetSetting("sampleFreq")); 98 $sfreq = intval(stGetSetting("sampleFreq"));
91 $sduration = intval(stGetSetting("sampleDuration")); 99 $sduration = intval(stGetSetting("sampleDuration"));
92 $schannels = intval(stGetSetting("sampleChannels")); 100 $schannels = intval(stGetSetting("sampleChannels"));
93 101
94 return wtExec( 102 return wtExec(
95 "/usr/local/bin/openmpt123" 103 wtGetExecutable("openmpt123")
96 , 104 ,
97 "--force --quiet ". 105 "--force --quiet ".
98 "--samplerate ".$sfreq." ". 106 "--samplerate ".$sfreq." ".
99 "--channels ".$schannels." ". 107 "--channels ".$schannels." ".
100 "--end-time ".($sduration)." ". 108 "--end-time ".($sduration)." ".
113 $optStr = ""; 121 $optStr = "";
114 foreach ($outOpts as $okey => $oval) 122 foreach ($outOpts as $okey => $oval)
115 $optStr .= $okey." ".$oval." "; 123 $optStr .= $okey." ".$oval." ";
116 124
117 return wtExec( 125 return wtExec(
118 "/usr/local/bin/avconv", 126 wtGetExecutable("avconv"),
119 "-y -v 1 -t ".intval($sduration)." ". 127 "-y -v 1 -t ".intval($sduration)." ".
120 "-i ".escapeshellarg($inFilename). 128 "-i ".escapeshellarg($inFilename).
121 " ".$optStr." -ac ".$schannels. 129 " ".$optStr." -ac ".$schannels.
122 " -map_metadata -1 ". 130 " -map_metadata -1 ".
123 escapeshellarg($outFilename)); 131 escapeshellarg($outFilename));
172 // Check file type before doing anything 180 // Check file type before doing anything
173 echo "INFO: Preparing to unpack archive file '".$filename."' ...\n"; 181 echo "INFO: Preparing to unpack archive file '".$filename."' ...\n";
174 switch ($atype) 182 switch ($atype)
175 { 183 {
176 case "LHA": 184 case "LHA":
177 $exe = "/usr/bin/lha"; 185 $exe = wtGetExecutable("lha");
178 $args = "x ".escapeshellarg($filename); 186 $args = "x ".escapeshellarg($filename);
179 break; 187 break;
180 188
181 case "ZIP": 189 case "ZIP":
182 $exe = "/usr/bin/unzip"; 190 $exe = wtGetExecutable("unzip");
183 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename); 191 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename);
184 break; 192 break;
185 193
186 case "RAR": 194 case "RAR":
187 $exe = "/usr/bin/rar"; 195 $exe = wtGetExecutable("rar");
188 $args = "x -w".escapeshellarg($path)." ".escapeshellarg($filename); 196 $args = "x -w".escapeshellarg($path)." ".escapeshellarg($filename);
189 break; 197 break;
190 198
191 case "7ZIP": 199 case "7ZIP":
192 $exe = "/usr/bin/7z"; 200 $exe = wtGetExecutable("7z");
193 $args = "x -o".escapeshellarg($path)." ".escapeshellarg($filename); 201 $args = "x -o".escapeshellarg($path)." ".escapeshellarg($filename);
194 break; 202 break;
195 203
196 default: 204 default:
197 echo "Unsupported archive file type: ".$atype."\n"; 205 echo "Unsupported archive file type: ".$atype."\n";