More work on client browsing and some query fixes on DACP server
[stereo.git] / DAAPLib / src / util / command / ctrlint / Cue.java
bloba7093e4fdfd351dd8cdc1b1d2e531b529dee47cd
1 package util.command.ctrlint;
3 import interfaces.DJInterface;
4 import interfaces.Track;
6 import java.util.List;
7 import java.util.Map;
9 import util.command.Command;
10 import util.node.Node;
11 import util.queryparser.ApplyFilter;
12 import util.queryparser.Filter;
13 import util.queryparser.QueryParser;
15 public class Cue implements Command {
17 private Map<String,String> args;
19 public void init(Map<String, String> args) {
20 this.args = args;
23 public Node run(DJInterface dj) {
25 List<? extends Track> playlist = dj.library().getLibrary();
27 System.out.println("library has " + playlist.size() + " elements");
29 if (args == null) {
30 return null;
33 if (args.containsKey("query")) {
35 Filter f = QueryParser.parse(args.get("query"));
36 System.out.println(f);
37 playlist = ApplyFilter.filter(f, playlist);
39 System.out.println("enqueuing " + playlist.size() + " elements");
41 dj.playbackControl().enqueue(playlist);
45 if (args.containsKey("index")) {
47 dj.playbackControl().jump(Integer.parseInt(args.get("index")));
51 if (args.containsKey("command")) {
53 String cmd = args.get("command");
55 if (cmd.equals("play")) {
56 dj.playbackControl().next();
58 else if (cmd.equals("clear")) {
59 dj.playbackControl().clear();
61 else {
62 throw new IllegalArgumentException("unexpected command: " + cmd);
66 return null;