Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1308 from Montellese/jsonrpc_getfiledetails

JSON-RPC: add Files.GetFileDetails
  • Loading branch information...
commit 691fede12bd52c90e812f41b3c5728581ce32c99 2 parents 18f6604 + f8c0817
@Montellese Montellese authored
View
43 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;
@@ -170,7 +171,7 @@ JSONRPC_STATUS CFileOperations::GetDirectory(const CStdString &method, ITranspor
bool hasFileField = false;
for (CVariant::const_iterator_array itr = param["properties"].begin_array(); itr != param["properties"].end_array(); itr++)
{
- if (*itr == CVariant("file"))
+ if (itr->asString().compare("file") == 0)
{
hasFileField = true;
break;
@@ -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
@@ -1446,6 +1446,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
@@ -582,6 +582,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",
View
38 xbmc/video/VideoDatabase.cpp
@@ -1539,6 +1539,8 @@ bool CVideoDatabase::LoadVideoInfo(const CStdString& strFilenameAndPath, CVideoI
CLog::Log(LOGDEBUG,"%s, got music video info!", __FUNCTION__);
CLog::Log(LOGDEBUG," Title = %s", details.m_strTitle.c_str());
}
+ else if (GetFileInfo(strFilenameAndPath, details))
+ CLog::Log(LOGDEBUG,"%s, got file info!", __FUNCTION__);
return !details.IsEmpty();
}
@@ -1835,6 +1837,42 @@ bool CVideoDatabase::GetSetInfo(int idSet, CVideoInfoTag& details)
return false;
}
+bool CVideoDatabase::GetFileInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idFile /* = -1 */)
+{
+ try
+ {
+ if (idFile < 0)
+ idFile = GetFileId(strFilenameAndPath);
+ if (idFile < 0)
+ return false;
+
+ CStdString sql = PrepareSQL("SELECT * FROM files "
+ "JOIN path ON path.idPath = files.idPath "
+ "JOIN bookmark ON bookmark.idFile = files.idFile AND bookmark.type = %i "
+ "WHERE files.idFile = %i", CBookmark::RESUME, idFile);
+ if (!m_pDS->query(sql.c_str()))
+ return false;
+
+ details.m_iFileId = m_pDS->fv("files.idFile").get_asInt();
+ details.m_strPath = m_pDS->fv("path.strPath").get_asString();
+ CStdString strFileName = m_pDS->fv("files.strFilename").get_asString();
+ ConstructPath(details.m_strFileNameAndPath, details.m_strPath, strFileName);
+ details.m_playCount = m_pDS->fv("files.playCount").get_asInt();
+ details.m_lastPlayed.SetFromDBDateTime(m_pDS->fv("files.lastPlayed").get_asString());
+ details.m_dateAdded.SetFromDBDateTime(m_pDS->fv("files.dateAdded").get_asString());
+ details.m_resumePoint.timeInSeconds = m_pDS->fv("bookmark.timeInSeconds").get_asInt();
+ details.m_resumePoint.totalTimeInSeconds = m_pDS->fv("bookmark.totalTimeInSeconds").get_asInt();
+ details.m_resumePoint.type = CBookmark::RESUME;
+
+ return !details.IsEmpty();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s (%s) failed", __FUNCTION__, strFilenameAndPath.c_str());
+ }
+ return false;
+}
+
void CVideoDatabase::AddGenreAndDirectorsAndStudios(const CVideoInfoTag& details, vector<int>& vecDirectors, vector<int>& vecGenres, vector<int>& vecStudios)
{
// add all directors
View
1  xbmc/video/VideoDatabase.h
@@ -430,6 +430,7 @@ class CVideoDatabase : public CDatabase
bool GetEpisodeInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1);
bool GetMusicVideoInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idMVideo=-1);
bool GetSetInfo(int idSet, CVideoInfoTag& details);
+ bool GetFileInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idFile = -1);
int GetPathId(const CStdString& strPath);
int GetTvShowId(const CStdString& strPath);

0 comments on commit 691fede

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