Merge pull request #41 from DanhKE6D/master
Add json rpc method/types to support file browsing/playing
This commit is contained in:
commit
4df3fda8d0
|
@ -15,10 +15,17 @@
|
|||
*/
|
||||
package org.xbmc.kore.jsonrpc.method;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.xbmc.kore.jsonrpc.ApiException;
|
||||
import org.xbmc.kore.jsonrpc.ApiMethod;
|
||||
import org.xbmc.kore.jsonrpc.type.FilesType;
|
||||
import org.xbmc.kore.jsonrpc.type.ItemType;
|
||||
import org.xbmc.kore.jsonrpc.type.ListType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* All JSON RPC methods in Files.*
|
||||
|
@ -48,4 +55,94 @@ public class Files {
|
|||
return new FilesType.PrepareDownloadReturnType(jsonObject.get(RESULT_NODE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enums for File.Media
|
||||
*/
|
||||
public interface Media {
|
||||
public final static String VIDEO = "video";
|
||||
public final static String MUSIC = "music";
|
||||
public final static String PICTURES = "pictures";
|
||||
public final static String FILES = "files";
|
||||
public final static String PROGRAMS = "programs";
|
||||
public final static String[] allValues = new String[] {
|
||||
VIDEO, MUSIC, PICTURES, FILES, PROGRAMS
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Files.GetSources command
|
||||
*/
|
||||
public static final class GetSources extends ApiMethod<List<ItemType.Source>> {
|
||||
public final static String METHOD_NAME = "Files.GetSources";
|
||||
public final static String SOURCE_NODE = "sources";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mediaType See {@link Files.Media} for a
|
||||
* list of accepted values
|
||||
*/
|
||||
public GetSources(String mediaType) {
|
||||
super();
|
||||
addParameterToRequest("media", mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() { return METHOD_NAME; }
|
||||
|
||||
@Override
|
||||
public List<ItemType.Source> resultFromJson(ObjectNode jsonObject) throws ApiException {
|
||||
JsonNode resultNode = jsonObject.get(RESULT_NODE);
|
||||
ArrayNode items = resultNode.has(SOURCE_NODE) ?
|
||||
(ArrayNode) resultNode.get(SOURCE_NODE) : null;
|
||||
if (items == null) {
|
||||
return new ArrayList<ItemType.Source>(0);
|
||||
}
|
||||
ArrayList<ItemType.Source> result = new ArrayList<ItemType.Source>(items.size());
|
||||
|
||||
for (JsonNode item : items) {
|
||||
result.add(new ItemType.Source(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Files.GetDirectory command
|
||||
*/
|
||||
public static final class GetDirectory extends ApiMethod<List<ListType.ItemFile>> {
|
||||
public final static String METHOD_NAME = "Files.GetDirectory";
|
||||
public final static String SORT_NODE = "sort";
|
||||
public final static String FILE_NODE = "files";
|
||||
|
||||
/**
|
||||
* Get the directory content
|
||||
* @param path full path name
|
||||
* @param sort_params sorting criteria
|
||||
*/
|
||||
public GetDirectory(String path, ListType.Sort sort_params) {
|
||||
super();
|
||||
addParameterToRequest("directory", path);
|
||||
addParameterToRequest(SORT_NODE, sort_params.toJsonNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() { return METHOD_NAME; }
|
||||
|
||||
@Override
|
||||
public List<ListType.ItemFile> resultFromJson(ObjectNode jsonObject) throws ApiException {
|
||||
|
||||
JsonNode resultNode = jsonObject.get(RESULT_NODE);
|
||||
ArrayNode items = resultNode.has(FILE_NODE) ?
|
||||
(ArrayNode) resultNode.get(FILE_NODE) : null;
|
||||
if (items == null) {
|
||||
return new ArrayList<ListType.ItemFile>(0);
|
||||
}
|
||||
ArrayList<ListType.ItemFile> result = new ArrayList<ListType.ItemFile>(items.size());
|
||||
for (JsonNode item : items) {
|
||||
result.add(new ListType.ItemFile(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -457,6 +457,17 @@ public class Player {
|
|||
addParameterToRequest("item", playlistItem.toJsonNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the active player
|
||||
* @param playlistId playlist ID to select
|
||||
*/
|
||||
public Open(int playlistId) {
|
||||
super();
|
||||
final ObjectNode item = objectMapper.createObjectNode();
|
||||
item.put("playlistid", playlistId);
|
||||
addParameterToRequest("item", item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() { return METHOD_NAME; }
|
||||
|
||||
|
|
|
@ -37,4 +37,22 @@ public class ItemType {
|
|||
label = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Item.Details.Source
|
||||
*/
|
||||
public static class Source extends DetailsBase {
|
||||
public static final String FILE = "file";
|
||||
|
||||
public final String file;
|
||||
|
||||
public Source(JsonNode node) {
|
||||
super(node);
|
||||
JsonNode fileNode = node.get(FILE);
|
||||
if (fileNode != null)
|
||||
file = fileNode.asText();
|
||||
else
|
||||
file = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -430,5 +430,79 @@ public class ListType {
|
|||
LOCKED, CHANNELNUMBER, STARTTIME, ENDTIME
|
||||
};
|
||||
}
|
||||
public static class ItemFile extends ItemBase {
|
||||
public static final String FILETYPE = "filetype";
|
||||
public static final String DIRECTORY = "directory";
|
||||
public final String filetype;
|
||||
|
||||
public ItemFile(JsonNode node) {
|
||||
super(node);
|
||||
filetype = JsonUtils.stringFromJsonNode(node, FILETYPE, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Sort implements ApiParameter {
|
||||
public static final String SORT_METHOD_NONE = "none";
|
||||
public static final String SORT_METHOD_LABEL = "label";
|
||||
public static final String SORT_METHOD_DATE = "date";
|
||||
public static final String SORT_METHOD_SIZE = "size";
|
||||
public static final String SORT_METHOD_FILE = "file";
|
||||
public static final String SORT_METHOD_PATH = "path";
|
||||
public static final String SORT_METHOD_DRIVETYPE = "drivetype";
|
||||
public static final String SORT_METHOD_TYPE = "title";
|
||||
public static final String SORT_METHOD_TRACK = "track";
|
||||
public static final String SORT_METHOD_TIME = "time";
|
||||
public static final String SORT_METHOD_ARTIST = "artist";
|
||||
public static final String SORT_METHOD_ALBUM = "album";
|
||||
public static final String SORT_METHOD_ALBUMTYPE = "albumtype";
|
||||
public static final String SORT_METHOD_GENRE = "genre";
|
||||
public static final String SORT_METHOD_COUNTRY = "country";
|
||||
public static final String SORT_METHOD_YEAR = "year";
|
||||
public static final String SORT_METHOD_RATING = "rating";
|
||||
public static final String SORT_METHOD_VOTES = "votes";
|
||||
public static final String SORT_METHOD_TOP250 = "top250";
|
||||
public static final String SORT_METHOD_PROGRAMCOUNT = "programcount";
|
||||
public static final String SORT_METHOD_PLAYLIST = "playlist";
|
||||
public static final String SORT_METHOD_EPISODE = "episode";
|
||||
public static final String SORT_METHOD_SEASON = "season";
|
||||
public static final String SORT_METHOD_TOTALEPISODES = "totalepisodes";
|
||||
public static final String SORT_METHOD_WATCHEDEPISODES = "watchedepisodes";
|
||||
public static final String SORT_METHOD_TVSHOWSTATUS = "tvshowstatus";
|
||||
public static final String SORT_METHOD_TVSHOWTITLE = "tvshowtitle";
|
||||
public static final String SORT_METHOD_SORTTITLE = "sorttitle";
|
||||
public static final String SORT_METHOD_PRODUCTIONCODE = "productioncode";
|
||||
public static final String SORT_METHOD_MPAA = "mpaa";
|
||||
public static final String SORT_METHOD_STUDIO = "studio";
|
||||
public static final String SORT_METHOD_DATEADDED = "dateadded";
|
||||
public static final String SORT_METHOD_LASTPLAYED = "lastplayed";
|
||||
public static final String SORT_METHOD_PLAYCOUNT = "playcount";
|
||||
public static final String SORT_METHOD_LISTENERS = "listeners";
|
||||
public static final String SORT_METHOD_BITRATE = "bitrate";
|
||||
public static final String SORT_METHOD_RANDOM = "random";
|
||||
|
||||
static final String METHOD = "method";
|
||||
static final String IGNORE_ARTICLE = "ignorearticle";
|
||||
static final String ORDER = "order";
|
||||
static final String ASCENDING_ORDER = "ascending";
|
||||
static final String DESCENDING_ORDER = "descending";
|
||||
|
||||
protected static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
public final boolean ignore_article;
|
||||
public final boolean ascending_order;
|
||||
public final String sort_method;
|
||||
|
||||
public Sort(String method, boolean ascending, boolean ignore_article) {
|
||||
this.sort_method = method;
|
||||
this.ascending_order = ascending;
|
||||
this.ignore_article = ignore_article;
|
||||
}
|
||||
|
||||
public JsonNode toJsonNode() {
|
||||
final ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put(ORDER, ascending_order ? ASCENDING_ORDER : DESCENDING_ORDER);
|
||||
node.put(IGNORE_ARTICLE, ignore_article);
|
||||
node.put(METHOD, sort_method);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue