Skip to content
Browse files

jsonrpc: add Files.GetFileDetails

  • Loading branch information...
1 parent 00e9ecd commit f8c0817e0a2d37867a564626a94c1c600c38869f @Montellese committed Aug 20, 2012
View
41 xbmc/interfaces/json-rpc/FileOperations.cpp
@@ -30,6 +30,7 @@
#include "settings/AdvancedSettings.h"
#include "Util.h"
#include "URL.h"
+#include "utils/URIUtils.h"
using namespace XFILE;
using namespace JSONRPC;
@@ -203,6 +204,46 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
return InvalidParams;
}
+JSONRPC_STATUS CFileOperations::GetFileDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ CStdString file = parameterObject["file"].asString();
+ if (!CFile::Exists(file))
+ return InvalidParams;
+
+ CStdString path;
+ URIUtils::GetDirectory(file, path);
+
+ CFileItemList items;
+ if (path.empty() || !CDirectory::GetDirectory(path, items) || !items.Contains(file))
+ return InvalidParams;
+
+ CFileItemPtr item = items.Get(file);
+ FillFileItem(item, *item.get(), parameterObject["media"].asString());
+
+ // Check if the "properties" list exists
+ // and make sure it contains the "file"
+ // field
+ CVariant param = parameterObject;
+ if (!param.isMember("properties"))
+ param["properties"] = CVariant(CVariant::VariantTypeArray);
+
+ bool hasFileField = false;
+ for (CVariant::const_iterator_array itr = param["properties"].begin_array(); itr != param["properties"].end_array(); itr++)
+ {
+ if (itr->asString().compare("file") == 0)
+ {
+ hasFileField = true;
+ break;
+ }
+ }
+
+ if (!hasFileField)
+ param["properties"].append("file");
+
+ HandleFileItem("id", true, "filedetails", item, parameterObject, param["properties"], result, false);
+ return OK;
+}
+
JSONRPC_STATUS CFileOperations::PrepareDownload(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::string protocol;
View
1 xbmc/interfaces/json-rpc/FileOperations.h
@@ -31,6 +31,7 @@ namespace JSONRPC
public:
static JSONRPC_STATUS GetRootDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS GetDirectory(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSONRPC_STATUS GetFileDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS PrepareDownload(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Download(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
View
1 xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
@@ -98,6 +98,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
// Files
{ "Files.GetSources", CFileOperations::GetRootDirectory },
{ "Files.GetDirectory", CFileOperations::GetDirectory },
+ { "Files.GetFileDetails", CFileOperations::GetFileDetails },
{ "Files.PrepareDownload", CFileOperations::PrepareDownload },
{ "Files.Download", CFileOperations::Download },
View
17 xbmc/interfaces/json-rpc/ServiceDescription.h
@@ -1445,6 +1445,23 @@ namespace JSONRPC
"}"
"}"
"}",
+ "\"Files.GetFileDetails\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Get details for a specific file\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": ["
+ "{ \"name\": \"file\", \"type\": \"string\", \"required\": true, \"description\": \"Full path to the file\" },"
+ "{ \"name\": \"media\", \"$ref\": \"Files.Media\", \"default\": \"files\" },"
+ "{ \"name\": \"properties\", \"$ref\": \"List.Fields.Files\" }"
+ "],"
+ "\"returns\": {"
+ "\"type\": \"object\","
+ "\"properties\": {"
+ "\"filedetails\": { \"$ref\": \"List.Item.File\", \"required\": true }"
+ "}"
+ "}"
+ "}",
"\"AudioLibrary.GetArtists\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve all artists\","
View
17 xbmc/interfaces/json-rpc/methods.json
@@ -581,6 +581,23 @@
}
}
},
+ "Files.GetFileDetails": {
+ "type": "method",
+ "description": "Get details for a specific file",
+ "transport": "Response",
+ "permission": "ReadData",
+ "params": [
+ { "name": "file", "type": "string", "required": true, "description": "Full path to the file" },
+ { "name": "media", "$ref": "Files.Media", "default": "files" },
+ { "name": "properties", "$ref": "List.Fields.Files" }
+ ],
+ "returns": {
+ "type": "object",
+ "properties": {
+ "filedetails": { "$ref": "List.Item.File", "required": true }
+ }
+ }
+ },
"AudioLibrary.GetArtists": {
"type": "method",
"description": "Retrieve all artists",

0 comments on commit f8c0817

Please sign in to comment.
Something went wrong with that request. Please try again.