This commit is contained in:
2019-09-27 01:49:14 -07:00
parent a4a3fcab74
commit 862af085c5
8 changed files with 180 additions and 243 deletions

117
Minat.php
View File

@@ -9,34 +9,29 @@ $version = file_get_contents(__DIR__."/version.txt");
require (__DIR__."/functions.php");
// Prefs
// Load preferences
$prefs = __DIR__."/prefs.php";
if (!file_exists($prefs)) {
alert("Can't read prefs file");
die;
} else {
$p = unserialize(file_get_contents($prefs));
// Extra prefs
$p['phpbin'] = "/usr/bin/php";
$p['flacbin'] = __DIR__."/bin/flac";
$p['metaflacbin'] = __DIR__."/bin/metaflac";
$p['lamebin'] = __DIR__."/bin/lame";
$p['soxbin'] = __DIR__."/bin/sox";
$p['workdir'] = "/tmp/minat/";
$p['logfile'] = getLogPath("minat.log");
$p['disable_tags'] = 0;
$p['disable_artwork'] = 0;
$p['premature'] = 0;
$p['max_size'] = 1000;
$prefs_file = "/Users/".get_current_user()."/Library/Preferences/org.profiteroles.Minat.php";
if (!file_exists($prefs_file)) {
if (!copy(__DIR__."/prefs.php",$prefs_file)) {
echo "Error creating preferences file";
die;
}
}
$p = unserialize(file_get_contents($prefs_file));
$p['phpbin'] = "/usr/bin/php";
$p['flacbin'] = __DIR__."/bin/flac";
$p['metaflacbin'] = __DIR__."/bin/metaflac";
$p['lamebin'] = __DIR__."/bin/lame";
$p['soxbin'] = __DIR__."/bin/sox";
$p['workdir'] = "/tmp/minat/";
$p['logfile'] = getLogPath("minat.log");
$p['disable_tags'] = 0;
$p['disable_artwork'] = 0;
$p['premature'] = 0;
$p['max_size'] = 1000;
if ($p['mode'] != 1) { $p['premature'] = 1; addline("MODE ".$p['mode']." NOT YET IMPLEMENTED."); }
@@ -59,46 +54,34 @@ addline("Minat: ".$version);
addline("PHP: ".PHP_VERSION);
addline(exec("sw_vers | grep ProductVersion"));
// Launch without argv (no files dragged)
// No files dragged
array_shift($argv);
if(count($argv) == 0) {
addline("Launch without argv");
die;
}
// Preferences
if ($argv[0] == "Preferences...") {
exec($p['phpbin']." ".__DIR__."/MinatPrefs.php");
addline("Launch preferences");
die;
}
// Version check
if ($argv[0] == "Check for Updates...") {
$curr_version = file_get_contents("https://www.profiteroles.org/git/profiteroles/Minat/raw/branch/master/version.txt");
addline("Version check, me=".$version." latest=".$curr_version);
if ($curr_version > $version) {
if(askMulti("Minat ".$curr_version." is available (you have ".$version.")", array("Cancel","Download")) == 1) {
exec("open http://git.profiteroles.org/profiteroles/Minat");
switch (@$argv[0]) {
case NULL:
addline("Launch without argv");
die;
case "Preferences...":
exec($p['phpbin']." ".__DIR__."/MinatPrefs.php");
addline("Launch preferences");
die;
case "Show Debug Console":
exec("open -n Console.app --args ".$p['logfile']);
die;
case "Check for Updates...":
$curr_version = file_get_contents("https://www.profiteroles.org/git/profiteroles/Minat/raw/master/version.txt");
if ($curr_version > $version) {
if(askMulti("Minat ".$curr_version." is available (you have ".$version.")", array("Cancel","Download")) == 1) {
exec("open http://www.profiteroles.org/git/profiteroles/Minat");
echo "QUITAPP\n";
} else {
die;
}
} else {
echo "\nALERT:Up-to-date|".$version." is the latest version.\n";
die;
}
} else {
alert($version." is the latest version","Up-to-date");
die;
}
}
// Console
if ($argv[0] == "Show Debug Console") {
exec("open -n Console.app --args ".$p['logfile']);
die;
}
$stamp = md5(serialize($argv))."_".time();
@@ -175,7 +158,7 @@ foreach ($argv as $target) {
if (!$p['disable_artwork']) {
$mimecmd = $p['metaflacbin']." --list --block-type=PICTURE ".escapeshellarg($files[0])." | head -10 | grep MIME | sed 's:.*/::'";
$mimecmd = escapeshellarg($p['metaflacbin'])." --list --block-type=PICTURE ".escapeshellarg($files[0])." | head -10 | grep MIME | sed 's:.*/::'";
addline($mimecmd);
$mime = exec($mimecmd);
if ($mime == " MIME type:") {
@@ -187,7 +170,7 @@ foreach ($argv as $target) {
addline("embedded cover found in ".$files[0]);
$coverdest = $workdir."cover.".$mime;
exec($p['metaflacbin']." --export-picture-to=".escapeshellarg($coverdest)." ".escapeshellarg($files[0]));
exec(escapeshellarg($p['metaflacbin'])." --export-picture-to=".escapeshellarg($coverdest)." ".escapeshellarg($files[0]));
if (file_exists($coverdest)) { $usecover = $coverdest; } else { addline ("error extracting file"); }
} elseif ($extcover = findCover($target)) {
@@ -228,13 +211,13 @@ foreach ($argv as $target) {
addline("Processing ".$file);
if ($p['check']) {
if (exec($p['flacbin']." -ts ".escapeshellarg($file)." 2>&1")) {
if (exec(escapeshellarg($p['flacbin'])." -ts ".escapeshellarg($file)." 2>&1")) {
addline("Skipping corrupted flac: ".$file);
continue;
}
}
$tagcmd = $p['soxbin']." --i -a ".escapeshellarg($file);
$tagcmd = escapeshellarg($p['soxbin'])." --i -a ".escapeshellarg($file);
if (!$p['disable_tags']) {
@@ -246,8 +229,8 @@ foreach ($argv as $target) {
$dest = $destdir.basename($file,".flac").".mp3";
$lockfile = $workdir.md5($target).".".basename($file,".flac").".lock";
$cmd_flac = $p['flacbin']." -dcs -- ".escapeshellarg($file);
$cmd_lame = $p['lamebin']." -S ".$p['lameopts']." --id3v2-utf16 ".$tags." ".$covertags." - ".escapeshellarg($dest);
$cmd_flac = escapeshellarg($p['flacbin'])." -dcs -- ".escapeshellarg($file);
$cmd_lame = escapeshellarg($p['lamebin'])." -S ".$p['lameopts']." --id3v2-utf16 ".$tags." ".$covertags." - ".escapeshellarg($dest);
$cmd_lock = "touch ".escapeshellarg($lockfile);
$line[] = $cmd_flac." | ".$cmd_lame." ; ".$cmd_lock;