switched to GPLv3 ONLY, because i don't trust FSF anymore
[amper.git] / ampercli.d
blob2cbc79982d6efa66b47ccd54e5c81efb2c781073
1 /* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 3 of the License ONLY.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 module ampercli;
18 import std.path : absolutePath;
20 import iv.alice;
21 import iv.cmdcon;
22 import iv.vfs.io;
24 import amperrpcproto;
27 void main (string[] args) {
28 if (args.length < 2) {
29 conwrite(
30 "usage: ampercli command [args]\n",
31 "commands:\n",
32 " add path\n",
33 " replace path\n",
34 " play\n",
35 " stop\n",
36 " pause\n",
37 " clear\n",
38 " title\n",
40 return;
42 //amperRPCall!amperScanDir("/home/www/dox/muzax/irij/flac/2006_rusalka");
43 // hack! convert anything that looks like a file to a full path
44 foreach (ref string s; args[1..$]) {
45 import std.file : exists;
46 try {
47 if (s.exists) s = absolutePath(s);
48 } catch (Exception e) {}
50 // process args
51 for (usize aidx = 1; aidx < args.length; ) {
52 string cmd = args[aidx++];
53 switch (cmd) {
54 case "add":
55 if (aidx >= args.length) assert(0, "no argument for command '"~cmd~"'");
56 amperRPCall!amperScanDir(absolutePath(args[aidx++]), true);
57 break;
58 case "replace":
59 if (aidx >= args.length) assert(0, "no argument for command '"~cmd~"'");
60 amperRPCall!amperScanDir(absolutePath(args[aidx++]), false);
61 break;
62 case "play": amperRPCall!amperPlay(); break;
63 case "stop": amperRPCall!amperStop(); break;
64 case "pause": amperRPCall!amperTogglePause(); break;
65 case "clear": amperRPCall!amperClearPlaylist(); break;
66 case "title": writeln(amperRPCall!amperGetSongVisTitle()); break;
67 default:
68 if (cmd.length && cmd[0] == '+') {
69 string command = cmd[1..$];
70 while (aidx < args.length) {
71 string s = args[aidx++];
72 if (s.length == 0) continue;
73 if (command.length && command[$-1] > ' ') command ~= ' ';
74 command ~= s;
76 amperRPCall!amperConsoleCommand(command);
77 return;
79 import std.file;
80 if (cmd.exists) {
81 amperRPCall!amperClearPlaylist();
82 --aidx;
83 while (aidx < args.length) amperRPCall!amperScanDir(absolutePath(args[aidx++]), true);
84 amperRPCall!amperPlay();
85 return;
87 assert(0, "invalid command: '"~cmd~"'");