Add json rpc method/types to support file browsing/playing
This commit is contained in:
parent
dfcb6d7d4d
commit
7bed0c7d1d
|
@ -15,10 +15,16 @@
|
|||
*/
|
||||
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.SortType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* All JSON RPC methods in Files.*
|
||||
|
@ -48,4 +54,78 @@ public class Files {
|
|||
return new FilesType.PrepareDownloadReturnType(jsonObject.get(RESULT_NODE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Files.GetSources command
|
||||
*/
|
||||
public static final class GetSources extends ApiMethod<List<FilesType.FileLocation>> {
|
||||
public final static String METHOD_NAME = "Files.GetSources";
|
||||
public final static String LIST_NODE = "sources";
|
||||
|
||||
/**
|
||||
* Provides a way to download a given file (e.g. providing an URL to the real file location)
|
||||
*/
|
||||
public GetSources(String mediaType) {
|
||||
super();
|
||||
addParameterToRequest("media", mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() { return METHOD_NAME; }
|
||||
|
||||
@Override
|
||||
public List<FilesType.FileLocation> resultFromJson(ObjectNode jsonObject) throws ApiException {
|
||||
JsonNode resultNode = jsonObject.get(RESULT_NODE);
|
||||
ArrayNode items = resultNode.has(LIST_NODE) ?
|
||||
(ArrayNode)resultNode.get(LIST_NODE) : null;
|
||||
if (items == null) {
|
||||
return new ArrayList<FilesType.FileLocation>(0);
|
||||
}
|
||||
ArrayList<FilesType.FileLocation> result = new ArrayList<FilesType.FileLocation>(items.size());
|
||||
|
||||
for (JsonNode item : items) {
|
||||
result.add(new FilesType.FileLocation(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Files.GetDirectory command
|
||||
*/
|
||||
public static final class GetDirectory extends ApiMethod<List<FilesType.FileLocation>> {
|
||||
public final static String METHOD_NAME = "Files.GetDirectory";
|
||||
public final static String SORT_NODE = "sort";
|
||||
public final static String LIST_NODE = "files";
|
||||
|
||||
/**
|
||||
* Provides a way to download a given file (e.g. providing an URL to the real file location)
|
||||
*/
|
||||
public GetDirectory(String path, SortType.Sort sort_params) {
|
||||
super();
|
||||
addParameterToRequest("media", LIST_NODE);
|
||||
addParameterToRequest("directory", path);
|
||||
addParameterToRequest(SORT_NODE, sort_params.toJsonNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() { return METHOD_NAME; }
|
||||
|
||||
@Override
|
||||
public List<FilesType.FileLocation> resultFromJson(ObjectNode jsonObject) throws ApiException {
|
||||
|
||||
JsonNode resultNode = jsonObject.get(RESULT_NODE);
|
||||
ArrayNode items = resultNode.has(LIST_NODE) ?
|
||||
(ArrayNode)resultNode.get(LIST_NODE) : null;
|
||||
if (items == null) {
|
||||
return new ArrayList<FilesType.FileLocation>(0);
|
||||
}
|
||||
ArrayList<FilesType.FileLocation> result = new ArrayList<FilesType.FileLocation>(items.size());
|
||||
|
||||
for (JsonNode item : items) {
|
||||
result.add(new FilesType.FileLocation(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -457,6 +457,30 @@ public class Player {
|
|||
addParameterToRequest("item", playlistItem.toJsonNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start playing with the specified filename
|
||||
* @param media_uri location (full path name) of the media to open
|
||||
*/
|
||||
|
||||
public Open(String media_uri) {
|
||||
super();
|
||||
PlayerType.Item item = new PlayerType.Item(media_uri);
|
||||
PlayerType.ResumeMode resumeMode = new PlayerType.ResumeMode(true);
|
||||
addParameterToRequest("item", item.toJsonNode());
|
||||
addParameterToRequest("options",resumeMode.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; }
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ 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.ListType;
|
||||
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
||||
import org.xbmc.kore.jsonrpc.type.PlaylistType.GetPlaylistsReturnType;
|
||||
|
@ -162,6 +163,19 @@ public class Playlist {
|
|||
addParameterToRequest("item", item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the media specified by fl.path to the selected playlist
|
||||
* @param playlistId selected playlistId
|
||||
* @param fl filelocation of the media to add
|
||||
*/
|
||||
public Add(int playlistId, FilesType.FileLocation fl) {
|
||||
super();
|
||||
addParameterToRequest("playlistid", playlistId);
|
||||
final ObjectNode item = objectMapper.createObjectNode();
|
||||
item.put("file", fl.path);
|
||||
addParameterToRequest("item", item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodName() { return METHOD_NAME; }
|
||||
|
||||
|
|
|
@ -45,4 +45,37 @@ public class FilesType {
|
|||
path = JsonUtils.stringFromJsonNode(details, PATH);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class FileLocation {
|
||||
public final static String LABEL = "label";
|
||||
public final static String FILE_PATH = "file";
|
||||
public final static String FILE_TYPE = "file_type";
|
||||
public final static String DIRECTORY = "directory";
|
||||
|
||||
public final String label;
|
||||
public final String path;
|
||||
public final boolean isDirectory;
|
||||
private boolean isRoot;
|
||||
|
||||
public FileLocation(JsonNode node) {
|
||||
label = JsonUtils.stringFromJsonNode(node,LABEL);
|
||||
path = JsonUtils.stringFromJsonNode(node,FILE_PATH);
|
||||
if (node.has(FILE_TYPE)) {
|
||||
isDirectory = JsonUtils.stringFromJsonNode(node,FILE_TYPE).equalsIgnoreCase(DIRECTORY);
|
||||
}
|
||||
else {
|
||||
isDirectory = path.endsWith("/") || path.endsWith("\\");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRootDir() { return this.isRoot; }
|
||||
public void setRootDir(boolean root) { this.isRoot = root; }
|
||||
|
||||
public FileLocation(String label, String path, boolean isDir) {
|
||||
this.label = label;
|
||||
this.path = path;
|
||||
this.isDirectory = isDir;
|
||||
this.isRoot = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -328,4 +328,46 @@ public class PlayerType {
|
|||
|
||||
public final String CYCLE = "cycle";
|
||||
}
|
||||
|
||||
/**
|
||||
* Player.Open type
|
||||
*/
|
||||
|
||||
public static final class ResumeMode implements ApiParameter {
|
||||
private static final String RESUME_MODE = "resume";
|
||||
public final boolean resume_mode;
|
||||
|
||||
protected static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
public ResumeMode(boolean resume) {
|
||||
this.resume_mode = resume;
|
||||
}
|
||||
public JsonNode toJsonNode() {
|
||||
final ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put(RESUME_MODE, resume_mode);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PlayerType.Item
|
||||
*/
|
||||
public static class Item implements ApiParameter {
|
||||
|
||||
protected static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public final String uri;
|
||||
/**
|
||||
* Constructors
|
||||
*/
|
||||
public Item(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode toJsonNode() {
|
||||
final ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("file", uri);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2015 DanhDroid. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.xbmc.kore.jsonrpc.type;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
/**
|
||||
* Created by danhdroid on 3/16/15.
|
||||
*/
|
||||
public class SortType {
|
||||
public static class Sort implements ApiParameter {
|
||||
public static final String METHOD = "method";
|
||||
public static final String IGNORE_ARTICLE = "ignorearticle";
|
||||
public static final String ORDER = "order";
|
||||
public static final String ASCENDING_ORDER = "ascending";
|
||||
public 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(IGNORE_ARTICLE, ignore_article);
|
||||
node.put(METHOD, sort_method);
|
||||
node.put(ORDER, ascending_order ? ASCENDING_ORDER : DESCENDING_ORDER);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue