On Thu, 23 Mar 2017, Martin Tarenskeen wrote:
I have added an -m option to specify midi file output to the script.
I have done some more finetuning on the script. What's new:
* A more verbose help message
* -u option to select newer unstable/devel version of lilypond
Todo:
This is growing in a tool that's actually usable.
Maybe it's time to add some author and licence/copyright stuff in the
code. Any suggestions?
--
Martin
#!/usr/bin/env php
<?php
function do_curl($url, $opts)
{
$curl = curl_init($url);
curl_setopt_array($curl, $opts);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
$versiondate = "2017-03-24";
$opts = getopt('admu', $argv);
$sep = array_search('--', $argv);
$files = array_slice($argv, $sep ? ++$sep : count($opts) + 1);
$help = "lilybin versiondate: " . $versiondate . PHP_EOL .
"Usage: lilybin [-admu] INFILE [OUTFILE]" . PHP_EOL .
"\t-a do All: upload INFILE and save result locally as OUTFILE" .
PHP_EOL .
"\t-d Download result from server" . PHP_EOL .
"\t-m download MIDI file (default: PDF)" . PHP_EOL .
"\t-u use Unstable lilypond-devel version" . PHP_EOL;
if (count($files) === 0 || count($files) > 2) {
die($help);
}
$all = isset($opts['a']);
$download = isset($opts['d']);
$midi = isset($opts['m']);
if ($midi) {
$ext = '.midi';
} else {
$ext = '.pdf';
}
$unstable = isset($opts['u']);
if ($unstable) {
$stable = 'unstable';
} else {
$stable = 'stable';
}
if ($all || !$download) {
$url =
'https://7icpm9qr6a.execute-api.us-west-2.amazonaws.com/prod/prepare_preview/'
. $stable;
$result = json_decode(do_curl($url, [
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode(['code' =>
file_get_contents($files[0])]),
CURLOPT_RETURNTRANSFER => true,
]));
if (!$result->id) {
echo "ERROR:\n", $result->stderr;
exit(1);
}
if ($all) {
$files[0] = $result->id . $ext;
} else {
echo $argv[0], ' -d ', $result->id, $ext . "\n";
exit;
}
}
if ($all || $download) {
$url = 'https://s3-us-west-2.amazonaws.com/lilybin-scores/' . $files[0];
$file = fopen(@$files[1] ?: $files[0], 'w');
do_curl($url, [CURLOPT_FILE => $file]);
fclose($file);
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user