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

View File

@@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
## [0.1.8]
- Tweaks and bugfixes
## [0.1.7]
- Updated Pashua binary

BIN
Minat.app.zip Normal file

Binary file not shown.

View File

@@ -9,19 +9,16 @@ $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");
$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;
} else {
$p = unserialize(file_get_contents($prefs));
// Extra prefs
}
}
$p = unserialize(file_get_contents($prefs_file));
$p['phpbin'] = "/usr/bin/php";
$p['flacbin'] = __DIR__."/bin/flac";
@@ -36,8 +33,6 @@ if (!file_exists($prefs)) {
$p['premature'] = 0;
$p['max_size'] = 1000;
}
if ($p['mode'] != 1) { $p['premature'] = 1; addline("MODE ".$p['mode']." NOT YET IMPLEMENTED."); }
// Make work dir
@@ -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) {
switch (@$argv[0]) {
case NULL:
addline("Launch without argv");
die;
}
// Preferences
if ($argv[0] == "Preferences...") {
case "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);
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://git.profiteroles.org/profiteroles/Minat");
exec("open http://www.profiteroles.org/git/profiteroles/Minat");
echo "QUITAPP\n";
} else {
die;
}
} else {
alert($version." is the latest version","Up-to-date");
echo "\nALERT:Up-to-date|".$version." is the latest version.\n";
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;

View File

@@ -1,16 +1,121 @@
<?php
// MinatPrefs 0.1.0
// MinatPrefs
//
// Includes
function makeWindowString($p, $strings) {
require (__DIR__."/functions.php");
require (__DIR__."/functions.pashua.php");
$conf = "
# Set window title
*.title = Preferences
*.floating = 1
hr.type = image
hr.path = ".__DIR__."/hr.png"."
hr.width = 320
hr.height = 2
hr.x = 0
hr.y = 564
mode.type = popup
mode.label = Minat Operation
mode.option = ".$strings[2][0]."
mode.option = ".$strings[2][1]."
mode.option = ".$strings[2][2]."
mode.default = ".$strings[2][$p['mode']]."
mode.width = 320
mode.rely = 20
mode.disabled = 1
dest.type = popup
dest.label = Destination
dest.option = ".$strings[0][0]."
dest.option = ".$strings[0][1]."
dest.option = ".$strings[0][2]."
dest.default = ".$strings[0][$p['dest']]."
dest.width = 160
destpath.type = openbrowser
destpath.filetype = directory
destpath.label = Custom destination
destpath.default = ".$p['destpath']."
destpath.width = 320
lameopts.type = textfield
lameopts.label = LAME flags
lameopts.default = ".$p['lameopts']."
lameopts.placeholder = -h -b 320 --ignore-tag-errors
lameopts.width = 320
check.type = checkbox
check.label = Check flacs
check.default = ".$p['check']."
warn_art.type = checkbox
warn_art.label = Warn for missing art
warn_art.default = ".$p['warn_art']."
warn_art.x = 120
warn_art.y = 338
template.type = textfield
template.label = Rename template
template.default = ".$p['template']."
template.placeholder = ^ARTIST^ - ^YEAR^ - ^ALBUM^ {LABEL CAT} [FORMAT]
template.width = 320
template.disabled = 1
spec_dims_x.type = textfield
spec_dims_x.label = Spec dimensions
spec_dims_x.default = ".$p['spec_dims'][0]."
spec_dims_x.width = 60
spec_dims_x.disabled = 1
spec_dims_y.type = textfield
spec_dims_y.default = ".$p['spec_dims'][1]."
spec_dims_y.width = 60
spec_dims_y.x = 80
spec_dims_y.y = 214
spec_dims_y.disabled = 1
postflight.type = popup
postflight.label = When finished
postflight.option = ".$strings[1][0]."
postflight.option = ".$strings[1][1]."
postflight.option = ".$strings[1][2]."
postflight.option = ".$strings[1][3]."
postflight.default = ".$strings[1][$p['postflight']]."
postflight.width = 160
handler.type = openbrowser
handler.filetype = app
handler.label = Handler application
handler.default = ".$p['handler']."
handler.width = 320
stay_open.type = checkbox
stay_open.label = Stay open
stay_open.default = ".$p['stay_open']."
ding.type = checkbox
ding.label = Ding
ding.default = ".$p['ding']."
ding.x = 100
ding.y = 48
cb.type = cancelbutton
db.type = defaultbutton
db.label = Save
";
return $conf;
}
// Read Prefs
$p = unserialize(file_get_contents(__DIR__."/prefs.php"));
$prefs_file = "/Users/".get_current_user()."/Library/Preferences/org.profiteroles.Minat.php";
$p = unserialize(file_get_contents($prefs_file));
if(!$p['destpath']) {
$p['destpath'] = "/Users/".get_current_user()."/Desktop";
}
@@ -21,7 +126,18 @@ $strings[] = array("Temp","Inline","Custom (specify below)");
$strings[] = array("Do nothing","Quicklook","Show in Finder","Open with handler (specify below)");
$strings[] = array("Rename","Transcode","Spectrogram");
$result = Pashua::showDialog(makeWindowString($p, $strings));
// Launch Pashua and parse results
$path = __DIR__."/Pashua.app/Contents/MacOS/Pashua";
$raw = shell_exec("echo ".escapeshellarg(makeWindowString($p, $strings))." | ".escapeshellarg($path)." - ");
$result = array();
foreach (explode("\n", $raw) as $line) {
preg_match('/^(\w+)=(.*)$/', $line, $matches);
if (empty($matches) or empty($matches[1])) {
continue;
}
$result[$matches[1]] = $matches[2];
}
// User cancelled
@@ -43,13 +159,13 @@ if(!$p['destpath']) {
$p['destpath'] = "/Users/".get_current_user()."/Desktop";
}
// Fix a fucking Pashua bug
// Fix a Pashua bug
$result['destpath'] = str_replace("Desktop/Desktop","Desktop",$result['destpath']);
// Write Prefs
file_put_contents("prefs.php",serialize($result));
file_put_contents($prefs_file,serialize($result));
echo "1";
?>

View File

@@ -1,4 +1,4 @@
#!/opt/local/bin/perl
#!/usr/bin/perl
# Copyright (C) 2007-2019 Ole Tange and Free Software Foundation, Inc.
#

View File

@@ -9,7 +9,7 @@ Support is planned for two other operations:
* Generate specs from audio files supported by sox
* Rename folders based on the tags of the audio files inside
* **⇩ [Download Minat 0.1.7](https://www.profiteroles.org/downloads/Minat_0.1.7.zip)**
* **⇩ [Download Latest Version](https://www.profiteroles.org/git/profiteroles/Minat/raw/master/Minat.app.zip)**
## Screenshot

View File

@@ -1,165 +0,0 @@
<?php
// Pashua Stuff
/**
* Static class which wraps the two simple methods used for communicating with Pashua
*/
class Pashua
{
/**
* Invokes a Pashua dialog window with the given window configuration
*
* @param string $conf Configuration string to pass to Pashua
* @param string $customLocation Filesystem path to directory containing Pashua
*
* @throws \RuntimeException
* @return array Associative array of values returned by Pashua
*/
public static function showDialog($conf, $customLocation = null)
{
if (ini_get('safe_mode')) {
$msg = "To use Pashua you will have to disable safe mode or " .
"change " . __FUNCTION__ . "() to fit your environment.\n";
fwrite(STDERR, $msg);
exit(1);
}
// Write configuration string to temporary config file
$configfile = tempnam('/tmp', 'Pashua_');
if (false === $fp = @fopen($configfile, 'w')) {
throw new \RuntimeException("Error trying to open $configfile");
}
fwrite($fp, $conf);
fclose($fp);
$path = __DIR__."/Pashua.app/Contents/MacOS/Pashua";
// Call pashua binary with config file as argument and read result
$result = shell_exec(escapeshellarg($path) . ' ' . escapeshellarg($configfile));
@unlink($configfile);
// Parse result
$parsed = array();
foreach (explode("\n", $result) as $line) {
preg_match('/^(\w+)=(.*)$/', $line, $matches);
if (empty($matches) or empty($matches[1])) {
continue;
}
$parsed[$matches[1]] = $matches[2];
}
return $parsed;
}
}
function makeWindowString($p, $strings) {
$conf = "
# Set window title
*.title = Preferences
*.floating = 1
hr.type = image
hr.path = ".__DIR__."/hr.png"."
hr.width = 320
hr.height = 2
hr.x = 0
hr.y = 564
mode.type = popup
mode.label = Minat Operation
mode.option = ".$strings[2][0]."
mode.option = ".$strings[2][1]."
mode.option = ".$strings[2][2]."
mode.default = ".$strings[2][$p['mode']]."
mode.width = 320
mode.rely = 20
mode.disabled = 1
dest.type = popup
dest.label = Destination
dest.option = ".$strings[0][0]."
dest.option = ".$strings[0][1]."
dest.option = ".$strings[0][2]."
dest.default = ".$strings[0][$p['dest']]."
dest.width = 160
destpath.type = openbrowser
destpath.filetype = directory
destpath.label = Custom destination
destpath.default = ".$p['destpath']."
destpath.width = 320
lameopts.type = textfield
lameopts.label = LAME flags
lameopts.default = ".$p['lameopts']."
lameopts.placeholder = -h -b 320 --ignore-tag-errors
lameopts.width = 320
check.type = checkbox
check.label = Check flacs
check.default = ".$p['check']."
warn_art.type = checkbox
warn_art.label = Warn for missing art
warn_art.default = ".$p['warn_art']."
warn_art.x = 120
warn_art.y = 338
template.type = textfield
template.label = Rename template
template.default = ".$p['template']."
template.placeholder = ^ARTIST^ - ^YEAR^ - ^ALBUM^ {LABEL CAT} [FORMAT]
template.width = 320
template.disabled = 1
spec_dims_x.type = textfield
spec_dims_x.label = Spec dimensions
spec_dims_x.default = ".$p['spec_dims'][0]."
spec_dims_x.width = 60
spec_dims_x.disabled = 1
spec_dims_y.type = textfield
spec_dims_y.default = ".$p['spec_dims'][1]."
spec_dims_y.width = 60
spec_dims_y.x = 80
spec_dims_y.y = 214
spec_dims_y.disabled = 1
postflight.type = popup
postflight.label = When finished
postflight.option = ".$strings[1][0]."
postflight.option = ".$strings[1][1]."
postflight.option = ".$strings[1][2]."
postflight.option = ".$strings[1][3]."
postflight.default = ".$strings[1][$p['postflight']]."
postflight.width = 160
handler.type = openbrowser
handler.filetype = app
handler.label = Handler application
handler.default = ".$p['handler']."
handler.width = 320
stay_open.type = checkbox
stay_open.label = Stay open
stay_open.default = ".$p['stay_open']."
ding.type = checkbox
ding.label = Ding
ding.default = ".$p['ding']."
ding.x = 100
ding.y = 48
cb.type = cancelbutton
db.type = defaultbutton
db.label = Save
";
return $conf;
}
?>

View File

@@ -1 +1 @@
0.1.7
0.1.8