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

[interfaces/json-rpc] Allow VideoLibrary.Clean by directory #18562

Merged
merged 1 commit into from Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions xbmc/Application.cpp
Expand Up @@ -4752,18 +4752,23 @@ void CApplication::StopMusicScan()
}

void CApplication::StartVideoCleanup(bool userInitiated /* = true */,
const std::string& content /* = "" */)
const std::string& content /* = "" */,
const std::string& strDirectory /* = "" */)
{
if (userInitiated && CVideoLibraryQueue::GetInstance().IsRunning())
return;

std::set<int> paths;
if (!content.empty())
if (!content.empty() || !strDirectory.empty())
{
CVideoDatabase db;
std::set<std::string> contentPaths;
if (db.Open() && db.GetPaths(contentPaths))
if (db.Open())
{
if (!strDirectory.empty())
contentPaths.insert(strDirectory);
else
db.GetPaths(contentPaths);
for (const std::string& path : contentPaths)
{
if (db.GetContentForPath(path) == content)
Expand Down
3 changes: 2 additions & 1 deletion xbmc/Application.h
Expand Up @@ -259,8 +259,9 @@ friend class CAppInboundProtocol;
\brief Starts a video library cleanup.
\param userInitiated Whether the action was initiated by the user (either via GUI or any other method) or not. It is meant to hide or show dialogs.
\param content Content type to clean, blank for everything
\param strDirectory The path to clean or "" (empty string) for a global clean.
*/
void StartVideoCleanup(bool userInitiated = true, const std::string& content = "");
void StartVideoCleanup(bool userInitiated = true, const std::string& content = "", const std::string& strDirectory = "");

/*!
\brief Starts a video library update.
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/builtins/LibraryBuiltins.cpp
Expand Up @@ -46,7 +46,7 @@ static int CleanLibrary(const std::vector<std::string>& params)
if (!g_application.IsVideoScanning())
{
const std::string content = (params.empty() || params[0] == "video") ? "" : params[0];
g_application.StartVideoCleanup(userInitiated, content);
g_application.StartVideoCleanup(userInitiated, content, params.size() > 2 ? params[2] : "");
}
else
CLog::Log(LOGERROR, "CleanLibrary is not possible while scanning or cleaning");
Expand Down
9 changes: 7 additions & 2 deletions xbmc/interfaces/json-rpc/VideoLibrary.cpp
Expand Up @@ -901,11 +901,16 @@ JSONRPC_STATUS CVideoLibrary::Export(const std::string &method, ITransportLayer

JSONRPC_STATUS CVideoLibrary::Clean(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
std::string directory = parameterObject["directory"].asString();
std::string cmd;
if (parameterObject["content"].empty())
cmd = StringUtils::Format("cleanlibrary(video, {0})", parameterObject["showdialogs"].asBoolean() ? "true" : "false");
cmd = StringUtils::Format("cleanlibrary(video, {0}, {1})",
parameterObject["showdialogs"].asBoolean() ? "true" : "false",
StringUtils::Paramify(directory).c_str());
else
cmd = StringUtils::Format("cleanlibrary({0}, {1})", parameterObject["content"].asString(), parameterObject["showdialogs"].asBoolean() ? "true" : "false");
cmd = StringUtils::Format("cleanlibrary({0}, {1}, {2})", parameterObject["content"].asString(),
parameterObject["showdialogs"].asBoolean() ? "true" : "false",
StringUtils::Paramify(directory).c_str());

CApplicationMessenger::GetInstance().SendMsg(TMSG_EXECUTE_BUILT_IN, -1, -1, nullptr, cmd);
return ACK;
Expand Down
3 changes: 2 additions & 1 deletion xbmc/interfaces/json-rpc/schema/methods.json
Expand Up @@ -1821,7 +1821,8 @@
"permission": "RemoveData",
"params": [
{ "name": "showdialogs", "type": "boolean", "default": true, "description": "Whether or not to show the progress bar or any other GUI dialog" },
{ "name": "content", "type": "string", "default": "video", "enum": [ "video", "movies", "tvshows", "musicvideos" ], "description": "Content type to clean for" }
{ "name": "content", "type": "string", "default": "video", "enum": [ "video", "movies", "tvshows", "musicvideos" ], "description": "Content type to clean for" },
{ "name": "directory", "type": "string", "default": "", "description": "Path to the directory to clean up; performs a global cleanup if not specified" }
],
"returns": "string"
},
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/json-rpc/schema/version.txt
@@ -1 +1 @@
JSONRPC_VERSION 11.14.0
JSONRPC_VERSION 11.15.0