diff options
author | Erich Eckner <git@eckner.net> | 2023-05-14 21:02:35 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2023-05-14 21:02:35 +0200 |
commit | 9a22c86fe2509dc5bc003339e070e71744a1c258 (patch) | |
tree | 9762553416b40daafee8b7e0b019e21f5dae544b | |
parent | 7c9808cda197442af43fa969a588d7f5e7b66780 (diff) | |
download | mocp-web-9a22c86fe2509dc5bc003339e070e71744a1c258.tar.xz |
some functionality done
-rw-r--r-- | index.php | 96 | ||||
-rw-r--r-- | lists.php | 16 |
2 files changed, 80 insertions, 32 deletions
@@ -1,51 +1,83 @@ <?php if (!array_key_exists('what',$_GET)) { +?> +<html> +<body> + <a href="?what=all">all info</a><br> + <a href="?what=pause">pause</a><br> + <a href="lists.php">lists</a><br> +</body> +</html> +<?php die(); } $max_line_len = 50; +function crypt_status() { + return trim(shell_exec("cryptstatus")); +} + +function details() { + global $max_line_len; + 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 (strlen($file) > $max_file_len) + $file = "..." . substr($file,3-$max_file_len); + return $state . " " . $file . " (" . $time . ")"; +} + +function list_info() { + global $max_line_len; + $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 (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=/" /></head></html> +<?php +} + switch ($_GET["what"]) { case "all": - $list = substr(shell_exec("head -n1 ~musix/.moc/_playlist.m3u"),0,-1); - $cnt = substr(shell_exec("wc -l < ~musix/.moc/Listen/" . $list),0,-1); - print $list . " (" . $cnt . ")<br>\n"; - 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); - } - print $state . " " . $file . " (" . $time . ")<br>\n"; - print trim(shell_exec("cryptstatus")); + print list_info() . "<br>\n"; + print details() . "<br>\n"; + print crypt_status(); break; case "info": - $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 (strlen($list) > $max_list_len) - $list = "..." . substr($list,3-$max_list_len); - print $list . " (" . $cnt . ")"; + print list_info(); break; case "details": - 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 (strlen($file) > $max_file_len) - $file = "..." . substr($file,3-$max_file_len); - print $state . " " . $file . " (" . $time . ")"; + print details(); break; case "crypt": - print shell_exec("cryptstatus"); + print crypt_status(); + break; + case "pause": + shell_exec("mocp -M ~musix/.moc -G"); + print_redirect(); + break; + case "playlist": + if (array_key_exists("list",$_GET)) { + $i = $_GET["list"]; + if (preg_match("/^\d+$/", $i) == 1) { + shell_exec("playlist " . $i); + } + } + // print_redirect(); break; default: die(); diff --git a/lists.php b/lists.php new file mode 100644 index 0000000..9e804a5 --- /dev/null +++ b/lists.php @@ -0,0 +1,16 @@ +<?php + +$handle = popen("LC_ALL=C ls ~musix/.moc/Listen", "r"); +$i = 1; +while (!feof($handle)) { + $s = fgets($handle); + if (substr($s,0,7) !== "_lokal_") { + continue; + } + $lists[$i] = substr($s,7); + $i++; +} + +foreach ($lists as $i => $list) { + print "<a href=/?what=playlist&list=" . $i . ">" . $list . "</a><br>\n"; +} |