Adapted the script also to translate xrni files, it might require some extra neating but it works.
<?php <br />
/*
Requires: PHP5, Info-Zip (http://www.info-zip.org/), oggenc (http://www.rarewares.org/ogg-oggenc.php)
and optionally flac (http://flac.sourceforge.net/)
Usage: `php xrns_ogg.php /path/to/file1.xrns file2.xrns [1|2|3|...|10]`
Will output compressed file to current working directory
Public Domain, last modified August 3rd, 2007
Coded by Dac Chartrand of http://www.trotch.com/
Special thanks for collaborative efforts to:
Taktik / Bantai of http://www.renoise.com/
Beatslaughter of http://www.beatslaughter.de/
*/
// ----------------------------------------------------------------------------
// Variables
// ----------------------------------------------------------------------------
$tmp_dir = '/temp';
// ----------------------------------------------------------------------------
// Functions
// ----------------------------------------------------------------------------
function ogg_files($source, $quality = 3) {
$path_to_oggenc = 'oggenc'; // oggenc assumed to be in path
$path_to_flac = 'flac'; // flac assumed to be in path
$array = scandir($source);
foreach ($array as $file) {
$fullpath = $source . '/' . $file;
switch (preg_match('/(\.(.*)$)/i', $file, $matches)) {
case (strtolower($matches[2]) == 'flac') :
$command = $path_to_flac . ' -d --delete-input-file "'.$fullpath.'"';
$res = -1; // any nonzero value
$UnusedArrayResult = array();
$UnusedStringResult = exec($command, $UnusedArrayResult, $res);
if ($res != 0) echo "Warning: flac return_val was $res, there was a problem decompressing flac $file\n";
else $fullpath = str_replace(".flac", ".wav", $fullpath);
case (strtolower($matches[2]) == 'wav' || (strtolower($matches[2]) == 'aif') || (strtolower($matches[2]) == 'aiff')):
$command = $path_to_oggenc . " --quality $quality \"$fullpath\" ";
$res = -1; // any nonzero value
$UnusedArrayResult = array();
$UnusedStringResult = exec($command, $UnusedArrayResult, $res);
if ($res != 0) echo "Warning: oggenc return_val was $res, there was a problem compressing $file\n";
else unlink($fullpath);
}
}
}
function UnzipAllFiles($zipFile, $zipDir) {
$unzip_xrns = 'unzip "@_SRC_@" -d "@_DST_@"'; // info-zip assumed to be in path
$unzipCmd = $unzip_xrns;
$unzipCmd = str_replace('@_SRC_@', $zipFile, $unzipCmd);
$unzipCmd = str_replace('@_DST_@', $zipDir, $unzipCmd);
$res = -1; // any nonzero value
$UnusedArrayResult = array();
$UnusedStringResult = exec($unzipCmd, $UnusedArrayResult, $res);
if ($res != 0) echo "Warning: UnzipAllFiles() return_val was $res\n";
return ($res == 0 || $res == 1); // http://www.info-zip.org/FAQ.html#error-codes
}
function ZipAllFiles($zipFile, $zipDir) {
$zip_xrns = 'zip -r "@_DST_@" .'; // info-zip assumed to be in path
$tmp = getcwd();
chdir($zipDir); // Change dir to get relative path
$zipCmd = $zip_xrns;
$zipCmd = str_replace('@_DST_@', $zipFile, $zipCmd);
$res = -1; // any nonzero value
$UnusedArrayResult = array();
$UnusedStringResult = exec($zipCmd, $UnusedArrayResult, $res);
if ($res != 0) echo "Warning: ZipAllFiles() return_val was $res\n";
chdir($tmp); // Back to previous working directory
if (!copy($zipDir . $zipFile, $tmp . '/' . $zipFile)) {
die("Error: Failed to copy $zipFile...\n");
}
return ($res == 0); // http://www.info-zip.org/FAQ.html#error-codes
}
function obliterate_directory($dirname, $only_empty = false) {
if (!is_dir($dirname)) return false;
if (isset($_ENV['OS']) && strripos($_ENV['OS'], "windows", 0) !== FALSE) {
// Windows patch for buggy perimssions on some machines
$command = 'cmd /C "rmdir /S /Q "'.str_replace('//', '\\', $dirname).'\\""';
$wsh = new COM("WScript.Shell");
$wsh->Run($command, 7, false);
$wsh = null;
return true;
}
else {
$dscan = array(realpath($dirname));
$darr = array();
while (!empty($dscan)) {
$dcur = array_pop($dscan);
$darr[] = $dcur;
if ($d = opendir($dcur)) {
while ($f=readdir($d)) {
if ($f == '.' || $f == '..') continue;
$f=$dcur.'/'.$f;
if (is_dir($f)) $dscan[] = $f;
else unlink($f);
}
closedir($d);
}
}
$i_until = ($only_empty)? 1 : 0;
for ($i=count($darr)-1; $i>=$i_until; $i--) {
if (!rmdir($darr[$i])) echo ("Warning: There was a problem deleting a temporary file in $dirname\n");
}
return (($only_empty)? (count(scandir)<=2) : (!is_dir($dirname)));
}
}
function get_temp_dir() {
// Try to get from environment variable
if (!empty($_ENV['TMP'])) {
return realpath($_ENV['TMP']);
}
else if (!empty($_ENV['TMPDIR'])) {
return realpath($_ENV['TMPDIR']);
}
else if (!empty($_ENV['TEMP'])) {
return realpath($_ENV['TEMP']);
}
else {
// Detect by creating a temporary file
$temp_file = tempnam(md5(uniqid(mt_rand(), true)), '');
if ($temp_file) {
$temp_dir = realpath(dirname($temp_file));
unlink($temp_file);
return $temp_dir;
}
else {
return false;
}
}
}
// ----------------------------------------------------------------------------
// Check Variables
// ----------------------------------------------------------------------------
// get filename component of path
$argv[0] = basename($argv[0]);
if (!is_dir($tmp_dir)) {
$tmp_dir = get_temp_dir();
if (!$tmp_dir) die("Error: Please set \$tmp_dir in $argv[0] to an existing directory.\n");
}
// ----------------------------------------------------------------------------
// Check User Input
// ----------------------------------------------------------------------------
if ($argc < 3) {
echo "Error: $argv[0] expects at least 2 parameters.\n";
echo "Usage: `php $argv[0] /path/to/file1.xrns file2.xrns [1|2|3|...|10]`\n";
echo "$argv[0] will output ogg compresed file (file2.xrns) to current working directory.\n";
die();
}
if (!file_exists($argv[1])) die("Error: The file $argv[1] was not found.\n");
if (!(preg_match('/(\.zip$|\.xrns$|\.xrni$)/i', $argv[2]))) {
die("Error: The filename $argv[2] is invalid, use .xrns / .xrni (or .zip)\n");
}
$song1 = $argv[1];
$song2 = $argv[2];
// Quality
if(ctype_digit($argv[3]) && $argv[3] > 0 && $argv[3] <= 10) $quality = $argv[3];
else $quality = 3; // default
// ----------------------------------------------------------------------------
// Unpack
// ----------------------------------------------------------------------------
echo "---------------------------------------\n";
echo "$argv[0] is working...\n";
echo date("D M j G:i:s T Y\n");
echo "---------------------------------------\n";
echo "Using temporary directory: $tmp_dir\n";
// Create a unique directory
if ((preg_match('/(\.xrni$)/i', $argv[2]))) {
$unzip1 = $tmp_dir . '/xrns_ogg_' . md5(uniqid(mt_rand(), true)) . '_Ins01/';
} else {
$unzip1 = $tmp_dir . '/xrns_ogg_' . md5(uniqid(mt_rand(), true)) . '_Track01/';
}
// Unzip song1
$result = UnzipAllFiles($song1, $unzip1);
if($result === FALSE) {
echo "Error: There was a problem unzipping the first file.\n";
echo "Error code: $result\n";
die();
}
echo "Going to process samples\n";
// ----------------------------------------------------------------------------
// Convert samples to .ogg
// ----------------------------------------------------------------------------
// SampleData directory
if (is_dir($unzip1 . '/SampleData/')) {
foreach(new DirectoryIterator($unzip1 . '/SampleData/') as $file) {
if ($file == '.' || $file == '..') continue; // Skip these files
if ((preg_match('/(\.xrni$)/i', $argv[2]))) {
$source = $unzip1 . 'SampleData';
} else {
$source = $unzip1 . '/SampleData/' . $file;
}
if (is_dir($source)) {
ogg_files($source, $quality);
}
}
}
// ----------------------------------------------------------------------------
// Zip song
// ----------------------------------------------------------------------------
// Zip song
$result = ZipAllFiles($song2, $unzip1);
if($result === FALSE) {
echo "Error: There was a problem zipping the final file.\n";
echo "Error code: $result\n";
die();
}
// ----------------------------------------------------------------------------
// Remove temp directories
// ----------------------------------------------------------------------------
obliterate_directory($unzip1);
echo "---------------------------------------\n";
echo "$argv[0] is done!\n";
echo date("D M j G:i:s T Y\n");
echo "---------------------------------------\n";
?>