summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2023-05-16 13:51:04 +0200
committerErich Eckner <git@eckner.net>2023-05-16 14:35:19 +0200
commitf78632169360cb93220799fe9368dc0218be34ce (patch)
treed89e1ababab36bfbedf526658227ca274e13e822
parentfe874043dcbb26e1e69b929b33cdaa34c875d8b1 (diff)
downloadmocp-web-f78632169360cb93220799fe9368dc0218be34ce.tar.xz
move more functions to moc_commands.php
-rw-r--r--index.php42
-rw-r--r--moc-commands.php44
2 files changed, 45 insertions, 41 deletions
diff --git a/index.php b/index.php
index c9eef41..389701f 100644
--- a/index.php
+++ b/index.php
@@ -59,48 +59,12 @@ Passwort: <input type="password" id="password" onchange="update_key(this.form);"
die();
}
-$commands['stop'] = 'mocp -M ~musix/.moc -s';
-$commands['play'] = 'mocp -M ~musix/.moc -p';
-$commands['pause'] = 'mocp -M ~musix/.moc -G';
-$commands['next'] = 'mocp -M ~musix/.moc -f';
-$commands['prev'] = 'mocp -M ~musix/.moc -r';
-$commands['shuffle on'] = 'mocp -M ~musix/.moc -o shuffle';
-$commands['shuffle off'] = 'mocp -M ~musix/.moc -u shuffle';
-$commands['lauter'] = 'lautstaerke +5';
-$commands['viel lauter'] = 'lautstaerke +25';
-$commands['leiser'] = 'lautstaerke -5';
-$commands['viel leiser'] = 'lautstaerke -25';
-
$max_line_len = 50;
function crypt_status() {
return trim(shell_exec("cryptstatus"));
}
-function details($max_line_len = 0) {
- foreach (explode("\n",shell_exec("mocp -M ~musix/.moc -i 2>/dev/null")) as $line) {
- if (substr($line,0,7)=="State: ")
- $state = substr($line,7);
- if (substr($line,0,6)=="File: ")
- $file = basename(substr($line,6));
- if (substr($line,0,10)=="TimeLeft: ")
- $time = substr($line,10);
- }
- $max_file_len = $max_line_len - 4 - strlen($state) - strlen($time);
- if ($max_line_len && (strlen($file) > $max_file_len))
- $file = "..." . substr($file,3-$max_file_len);
- return $state . " " . $file . " (" . $time . ")";
-}
-
-function list_info($max_line_len = 0) {
- $list = substr(shell_exec("head -n1 ~musix/.moc/_playlist.m3u"),0,-1);
- $cnt = substr(shell_exec("wc -l < ~musix/.moc/Listen/" . $list),0,-1);
- $max_list_len = $max_line_len - 3 - strlen($cnt);
- if ($max_line_len && (strlen($list) > $max_list_len))
- $list = "..." . substr($list,3-$max_list_len);
- return $list . " (" . $cnt . ")";
-}
-
function print_redirect() {
?>
<html><head><meta http-equiv="refresh" content="0; url=/<?php attach_key('?'); ?>" /></head></html>
@@ -117,11 +81,7 @@ if (!array_key_exists('what',$_GET)) {
?>
<a href="?what=all<?php attach_key(); ?>">all info</a><br>
<?php
- foreach ($commands as $key => $command) {
- print ' <a href="?what=' . $key;
- attach_key();
- print '">' . $key . '</a><br>' . "\n";
- }
+ print_known_commands();
?>
<a href="?what=lists<?php attach_key(); ?>">lists</a><br>
</body>
diff --git a/moc-commands.php b/moc-commands.php
index 4baddb2..ec962d6 100644
--- a/moc-commands.php
+++ b/moc-commands.php
@@ -24,3 +24,47 @@ function print_lists() {
print '">' . $list . "</a><br>\n";
}
}
+
+$commands['stop'] = 'mocp -M ~musix/.moc -s';
+$commands['play'] = 'mocp -M ~musix/.moc -p';
+$commands['pause'] = 'mocp -M ~musix/.moc -G';
+$commands['next'] = 'mocp -M ~musix/.moc -f';
+$commands['prev'] = 'mocp -M ~musix/.moc -r';
+$commands['shuffle on'] = 'mocp -M ~musix/.moc -o shuffle';
+$commands['shuffle off'] = 'mocp -M ~musix/.moc -u shuffle';
+$commands['lauter'] = 'lautstaerke +5';
+$commands['viel lauter'] = 'lautstaerke +25';
+$commands['leiser'] = 'lautstaerke -5';
+$commands['viel leiser'] = 'lautstaerke -25';
+
+function details($max_line_len = 0) {
+ foreach (explode("\n",shell_exec("mocp -M ~musix/.moc -i 2>/dev/null")) as $line) {
+ if (substr($line,0,7)=="State: ")
+ $state = substr($line,7);
+ if (substr($line,0,6)=="File: ")
+ $file = basename(substr($line,6));
+ if (substr($line,0,10)=="TimeLeft: ")
+ $time = substr($line,10);
+ }
+ $max_file_len = $max_line_len - 4 - strlen($state) - strlen($time);
+ if ($max_line_len && (strlen($file) > $max_file_len))
+ $file = "..." . substr($file,3-$max_file_len);
+ return $state . " " . $file . " (" . $time . ")";
+}
+
+function list_info($max_line_len = 0) {
+ $list = substr(shell_exec("head -n1 ~musix/.moc/_playlist.m3u"),0,-1);
+ $cnt = substr(shell_exec("wc -l < ~musix/.moc/Listen/" . $list),0,-1);
+ $max_list_len = $max_line_len - 3 - strlen($cnt);
+ if ($max_line_len && (strlen($list) > $max_list_len))
+ $list = "..." . substr($list,3-$max_list_len);
+ return $list . " (" . $cnt . ")";
+}
+
+print_known_commands() {
+ foreach ($commands as $key => $command) {
+ print ' <a href="?what=' . $key;
+ attach_key();
+ print '">' . $key . '</a><br>' . "\n";
+ }
+}