package agersant.polaris;

import org.json.JSONException;
import org.json.JSONObject;

public class CollectionItem implements Cloneable {

    private String name;
    private String path;
    private String artist;
    private String title;
    private String artwork;
    private boolean isDirectory;

    private CollectionItem() {
    }

    public static CollectionItem parse(JSONObject source) throws JSONException {
        CollectionItem item = new CollectionItem();
        item.isDirectory = source.optString("variant", "").equals("Directory");
        JSONObject fields = source.getJSONArray("fields").getJSONObject(0);
        item.parseFields(fields);
        return item;
    }

    public static CollectionItem parseSong(JSONObject fields) throws JSONException {
        CollectionItem item = new CollectionItem();
        item.isDirectory = false;
        item.parseFields(fields);
        return item;
    }

    protected void parseFields(JSONObject fields) throws JSONException {
        path = fields.getString("path");
        artist = fields.optString("artist", null);
        title = fields.optString("title", null);
        artwork = fields.optString("artwork", null);

        String[] chunks = path.split("/|\\\\");
        name = chunks[chunks.length - 1];
    }

    @Override
    public CollectionItem clone() throws CloneNotSupportedException {
        return (CollectionItem) super.clone();
    }

    public String getName() {
        return name;
    }

    public String getPath() {
        return path;
    }

    public String getArtist() {
        return artist;
    }

    public String getTitle() {
        return title;
    }

    public String getArtwork() {
        return artwork;
    }

    public boolean isDirectory() {
        return isDirectory;
    }
}

@@ -259,24 +259,50 @@
 ng artwork;%0A
+    private String album;%0A
     private 
@@ -322,16 +322,16 @@
 ectory;%0A
-
 %0A    pri
@@ -955,15 +955,13 @@
   pr
-otec
+iva
 te
-d
  voi
@@ -1209,16 +1209,65 @@
 , null);
+%0A        album = fields.optString(%22album%22, null);
 %0A%0A      
@@ -1828,24 +1828,24 @@
 rectory() %7B%0A
-
         retu
@@ -1865,11 +1865,71 @@
 y;%0A    %7D
+%0A%0A    public String getAlbum() %7B%0A        return album;%0A    %7D
 %0A%7D%0A

Read album names