Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addsource jsonrpc #5484

Closed
wants to merge 11 commits into from
102 changes: 102 additions & 0 deletions xbmc/interfaces/json-rpc/FileOperations.cpp
Expand Up @@ -31,6 +31,13 @@
#include "URL.h"
#include "utils/URIUtils.h"
#include "utils/FileUtils.h"
#include "Application.h"
#include "addons/AddonManager.h"
#include "addons/Scraper.h"
#include "video/VideoDatabase.h"
#include "video/VideoInfoScanner.h"
#include "music/MusicDatabase.h"
#include "PasswordManager.h"

using namespace XFILE;
using namespace JSONRPC;
Expand Down Expand Up @@ -227,6 +234,101 @@ JSONRPC_STATUS CFileOperations::Download(const std::string &method, ITransportLa
return transport->Download(parameterObject["path"].asString().c_str(), result) ? OK : InvalidParams;
}

CONTENT_TYPE contentTypeFromString(const std::string &content) {

This comment was marked as spam.

if (content == "movies")
return CONTENT_MOVIES;
else if (content == "tvshows")
return CONTENT_TVSHOWS;
else if (content == "musicvideos")
return CONTENT_MUSICVIDEOS;
else
return CONTENT_NONE;
}

JSONRPC_STATUS CFileOperations::AddSource(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::string name = parameterObject["name"].asString();
std::string content = parameterObject["content"].asString("none");
std::vector<std::string> contents = StringUtils::Split(content, ".");

CVariant directory = parameterObject["directory"];
std::vector<std::string> paths;

if (directory.isArray())
{
for (CVariant::iterator_array itr = directory.begin_array(); itr != directory.end_array(); itr++)
paths.push_back(itr->asString());
}
else
paths.push_back(directory.asString());

std::string media = contents[0] == "audio" ? "music" : contents[0];

for (std::vector<std::string>::iterator itr = paths.begin(); itr != paths.end(); itr++)
{
if (!itr->empty())
{ // strip off the user and password for smb paths (anything that the password manager can auth)
// and add the user/pass to the password manager - note, we haven't confirmed that it works
// at this point, but if it doesn't, the user will get prompted anyway in SMBDirectory.
CURL url(*itr);
if (url.IsProtocol("smb"))

This comment was marked as spam.

This comment was marked as spam.

{
CPasswordManager::GetInstance().SaveAuthenticatedURL(url);
url.SetPassword("");
url.SetUserName("");
}
itr->assign(url.Get());
}
}

CMediaSource share;
VECSOURCES* pShares = CMediaSourceSettings::Get().GetSources(media);
for (VECSOURCES::iterator itr = pShares->begin(); itr != pShares->end(); itr++)
{
if (StringUtils::EqualsNoCase(itr->strName, name))
return InvalidParams;
}

share.FromNameAndPaths(media, name, paths);

CMediaSourceSettings::Get().AddShare(media, share);

if (media == "video" && contents.size() > 1)
{
ADDON::AddonPtr scraperAddon;
if (ADDON::CAddonMgr::Get().GetDefault(ADDON::ScraperTypeFromContent(ADDON::TranslateContent(contents[1])), scraperAddon))
{
ADDON::ScraperPtr scraper = boost::dynamic_pointer_cast<ADDON::CScraper>(scraperAddon);

CVideoDatabase db;
db.Open();

VIDEO::SScanSettings settings;

settings.parent_name = parameterObject["parent_name"].asBoolean();
settings.parent_name_root = parameterObject["parent_name_root"].asBoolean();
settings.recurse = parameterObject["recurse"].asBoolean();
settings.noupdate = parameterObject["noupdate"].asBoolean();
settings.exclude = parameterObject["exclude"].asBoolean();

for (std::vector<std::string>::const_iterator itr = paths.begin(); itr != paths.end(); itr++)
db.SetScraperForPath(*itr, scraper, settings);
}
}
else if (content == "audio.music")
{
CMusicDatabase db;
db.Open();

for (std::vector<std::string>::const_iterator itr = paths.begin(); itr != paths.end(); itr++)
db.AddPath(*itr);

db.Close();
}

return ACK;
}

bool CFileOperations::FillFileItem(const CFileItemPtr &originalItem, CFileItemPtr &item, std::string media /* = "" */, const CVariant &parameterObject /* = CVariant(CVariant::VariantTypeArray) */)
{
if (originalItem.get() == NULL)
Expand Down
2 changes: 2 additions & 0 deletions xbmc/interfaces/json-rpc/FileOperations.h
Expand Up @@ -34,6 +34,8 @@ namespace JSONRPC
static JSONRPC_STATUS PrepareDownload(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSONRPC_STATUS Download(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);

static JSONRPC_STATUS AddSource(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);

static bool FillFileItem(const CFileItemPtr &originalItem, CFileItemPtr &item, std::string media = "", const CVariant &parameterObject = CVariant(CVariant::VariantTypeArray));
static bool FillFileItemList(const CVariant &parameterObject, CFileItemList &list);
};
Expand Down
1 change: 1 addition & 0 deletions xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
Expand Up @@ -98,6 +98,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "Files.GetFileDetails", CFileOperations::GetFileDetails },
{ "Files.PrepareDownload", CFileOperations::PrepareDownload },
{ "Files.Download", CFileOperations::Download },
{ "Files.AddSource", CFileOperations::AddSource },

// Music Library
{ "AudioLibrary.GetArtists", CAudioLibrary::GetArtists },
Expand Down
25 changes: 24 additions & 1 deletion xbmc/interfaces/json-rpc/schema/methods.json
Expand Up @@ -583,6 +583,29 @@
],
"returns": { "type": "any", "required": true }
},
"Files.AddSource": {
"type": "method",
"description": "Add a source for the media windows",
"transport": "Response",
"permission": "ReadData",
"params": [
{ "name": "name", "type": "string", "required": true },
{ "name": "directory", "type": [ "string", { "$ref": "Array.String", "required": true } ], "required": true },
{ "name": "content", "$ref": "Files.Content", "required": false },
{
"name": "settings",
"properties": {
"parent_name": { "type": "boolean", "required": false },
"parent_name_root": { "type": "boolean", "required": false },
"recurse": { "type": "boolean", "required": false, "default": true },
"noupdate": { "type": "boolean", "required": false },
"exclude": { "type": "boolean", "required": false }
},
"required": false
}
],
"returns": "string"
},
"Files.GetDirectory": {
"type": "method",
"description": "Get the directories and files in the given directory",
Expand Down Expand Up @@ -2323,4 +2346,4 @@
],
"returns": "string"
}
}
}
4 changes: 4 additions & 0 deletions xbmc/interfaces/json-rpc/schema/types.json
Expand Up @@ -78,6 +78,10 @@
"type": "string",
"enum": [ "video", "music", "pictures", "files", "programs" ]
},
"Files.Content": {
"type": "string",
"enum": [ "video", "video.movies", "video.tvshows", "video.musicvideos", "audio", "audio.music", "pictures", "files", "programs" ]
},
"List.Amount": {
"type": "integer",
"default": -1,
Expand Down