Moved MPRIS to a new project
[stereo.git] / DAAPLib / src / util / command / databases / Items.java
blob657fe3c24dddf860c068c54ceefb7a6066b7cc9c
1 package util.command.databases;
3 import interfaces.DJInterface;
4 import interfaces.Track;
5 import interfaces.collection.Collection;
6 import interfaces.collection.Source;
8 import java.util.ArrayList;
9 import java.util.List;
10 import java.util.Map;
12 import util.command.Command;
13 import util.queryparser.ApplyFilter;
14 import util.queryparser.Filter;
15 import util.queryparser.QueryParser;
16 import api.Response;
18 public class Items implements Command {
20 private Map<String,String> args;
21 private int container;
23 public Items(int container) {
24 this.container = container;
27 public void init(Map<String, String> args) {
28 this.args = args;
31 public Response run(DJInterface dj) {
33 Source<? extends Track> source = null;
35 for (Collection<? extends Track> p: dj.library().collections()) {
36 if (p.id() == container) {
37 source = p.source();
38 break;
42 if (source == null) {
43 System.err.println("requested playlist not found!");
44 return null;
47 System.out.println("playlist has " + source.size() + " elements");
49 List<? extends Track> pl;
51 if (args != null && args.containsKey("query")) {
52 Filter f = QueryParser.parse(args.get("query"));
53 System.out.println(f);
54 pl = ApplyFilter.filter(f, source.tracks());
56 else {
57 List<Track> l = new ArrayList<Track>();
58 for (Track t: source.tracks()) {
59 l.add(t);
61 pl = l;
64 /*Collections.sort(playlist, new Comparator<Track>() {
65 public int compare(Track o1, Track o2) {
66 String a = (String)o1.getTag(DAAPConstants.NAME);
67 String b = (String)o2.getTag(DAAPConstants.NAME);
68 if (a == null) a = "";
69 if (b == null) b = "";
70 return a.compareTo(b);
72 });*/
74 System.out.println("returning " + source.size() + " elements");
76 return new util.response.PlaylistSongs(pl);