more id3v2 fixes
[amper.git] / ampercli.d
blobc2a2e29dd75dc3896ad4192512a908c60c5b46cb
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, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module ampercli;
19 import std.path : absolutePath;
21 import iv.alice;
22 import iv.cmdcon;
23 import iv.vfs.io;
25 import amperrpcproto;
28 void main (string[] args) {
29 if (args.length < 2) {
30 conwrite(
31 "usage: ampercli command [args]\n",
32 "commands:\n",
33 " add path\n",
34 " replace path\n",
35 " play\n",
36 " stop\n",
37 " pause\n",
38 " clear\n",
39 " title\n",
41 return;
43 //amperRPCall!amperScanDir("/home/www/dox/muzax/irij/flac/2006_rusalka");
44 // hack! convert anything that looks like a file to a full path
45 foreach (ref string s; args[1..$]) {
46 import std.file : exists;
47 try {
48 if (s.exists) s = absolutePath(s);
49 } catch (Exception e) {}
51 // process args
52 for (usize aidx = 1; aidx < args.length; ) {
53 string cmd = args[aidx++];
54 switch (cmd) {
55 case "add":
56 if (aidx >= args.length) assert(0, "no argument for command '"~cmd~"'");
57 amperRPCall!amperScanDir(absolutePath(args[aidx++]), true);
58 break;
59 case "replace":
60 if (aidx >= args.length) assert(0, "no argument for command '"~cmd~"'");
61 amperRPCall!amperScanDir(absolutePath(args[aidx++]), false);
62 break;
63 case "play": amperRPCall!amperPlay(); break;
64 case "stop": amperRPCall!amperStop(); break;
65 case "pause": amperRPCall!amperTogglePause(); break;
66 case "clear": amperRPCall!amperClearPlaylist(); break;
67 case "title": writeln(amperRPCall!amperGetSongVisTitle()); break;
68 default:
69 if (cmd.length && cmd[0] == '+') {
70 string command = cmd[1..$];
71 while (aidx < args.length) {
72 string s = args[aidx++];
73 if (s.length == 0) continue;
74 if (command.length && command[$-1] > ' ') command ~= ' ';
75 command ~= s;
77 amperRPCall!amperConsoleCommand(command);
78 return;
80 import std.file;
81 if (cmd.exists) {
82 amperRPCall!amperClearPlaylist();
83 --aidx;
84 while (aidx < args.length) amperRPCall!amperScanDir(absolutePath(args[aidx++]), true);
85 amperRPCall!amperPlay();
86 return;
88 assert(0, "invalid command: '"~cmd~"'");