Permalink
Browse files

ADD: JSON-RPC: add a parameter to "Remove" methods allowing to also d…

…elete the file
  • Loading branch information...
1 parent a6a5de0 commit 40db91b70d924b70a6a7582a16b6bef6dc9002a2 @koying committed Jul 17, 2012
@@ -2165,7 +2165,8 @@ namespace JSONRPC
"\"transport\": \"Response\","
"\"permission\": \"RemoveData\","
"\"params\": ["
- "{ \"name\": \"movieid\", \"$ref\": \"Library.Id\", \"required\": true }"
+ "{ \"name\": \"movieid\", \"$ref\": \"Library.Id\", \"required\": true },"
+ "{ \"name\": \"deletefile\", \"type\": \"boolean\", \"default\": false, \"description\": \"Whether to delete the physical file\" }"
"],"
"\"returns\": \"string\""
"}",
@@ -2185,7 +2186,8 @@ namespace JSONRPC
"\"transport\": \"Response\","
"\"permission\": \"RemoveData\","
"\"params\": ["
- "{ \"name\": \"episodeid\", \"$ref\": \"Library.Id\", \"required\": true }"
+ "{ \"name\": \"episodeid\", \"$ref\": \"Library.Id\", \"required\": true },"
+ "{ \"name\": \"deletefile\", \"type\": \"boolean\", \"default\": false, \"description\": \"Whether to delete the physical file\" }"
"],"
"\"returns\": \"string\""
"}",
@@ -2195,7 +2197,8 @@ namespace JSONRPC
"\"transport\": \"Response\","
"\"permission\": \"RemoveData\","
"\"params\": ["
- "{ \"name\": \"musicvideoid\", \"$ref\": \"Library.Id\", \"required\": true }"
+ "{ \"name\": \"musicvideoid\", \"$ref\": \"Library.Id\", \"required\": true },"
+ "{ \"name\": \"deletefile\", \"type\": \"boolean\", \"default\": false, \"description\": \"Whether to delete the physical file\" }"
"],"
"\"returns\": \"string\""
"}",
@@ -24,6 +24,7 @@
#include "Util.h"
#include "utils/URIUtils.h"
#include "video/VideoDatabase.h"
+#include "filesystem/File.h"
using namespace JSONRPC;
@@ -697,14 +698,47 @@ JSONRPC_STATUS CVideoLibrary::RemoveVideo(const CVariant &parameterObject)
if (!videodatabase.Open())
return InternalError;
+ bool bDeleteFile = false;
+ if (parameterObject.isMember("deletefile"))
+ bDeleteFile = parameterObject["deletefile"].asBoolean();
+
+ int itemId = -1;
+ VIDEODB_CONTENT_TYPE iType;
+ CStdString filePath("");
+
if (parameterObject.isMember("movieid"))
- videodatabase.DeleteMovie((int)parameterObject["movieid"].asInteger());
- else if (parameterObject.isMember("tvshowid"))
- videodatabase.DeleteTvShow((int)parameterObject["tvshowid"].asInteger());
- else if (parameterObject.isMember("episodeid"))
- videodatabase.DeleteEpisode((int)parameterObject["episodeid"].asInteger());
- else if (parameterObject.isMember("musicvideoid"))
- videodatabase.DeleteMusicVideo((int)parameterObject["musicvideoid"].asInteger());
+ {
+ iType = VIDEODB_CONTENT_MOVIES;
+ itemId = (int)parameterObject["movieid"].asInteger();
+ videodatabase.GetFilePathById(itemId, filePath, iType);
+ videodatabase.DeleteMovie(itemId);
+ } else if (parameterObject.isMember("tvshowid"))
+ {
+ iType = VIDEODB_CONTENT_TVSHOWS;
+ itemId = (int)parameterObject["tvshowid"].asInteger();
+ videodatabase.DeleteTvShow(itemId);
+ } else if (parameterObject.isMember("episodeid"))
+ {
+ iType = VIDEODB_CONTENT_EPISODES;
+ itemId = (int)parameterObject["episodeid"].asInteger();
+ videodatabase.GetFilePathById(itemId, filePath, iType);
+ videodatabase.DeleteEpisode(itemId);
+ } else if (parameterObject.isMember("musicvideoid"))
+ {
+ iType = VIDEODB_CONTENT_MUSICVIDEOS;
+ videodatabase.GetFilePathById(itemId, filePath, iType);
+ itemId = (int)parameterObject["musicvideoid"].asInteger();
+ videodatabase.DeleteMusicVideo(itemId);
+ }
+
+ if (bDeleteFile && itemId >= 0)
+ {
+ if (filePath != "")
+ {
+ XFILE::CFile::Delete(filePath);
+ }
+ }
+
return ACK;
}
@@ -1300,8 +1300,9 @@
"transport": "Response",
"permission": "RemoveData",
"params": [
- { "name": "movieid", "$ref": "Library.Id", "required": true }
- ],
+ { "name": "movieid", "$ref": "Library.Id", "required": true },
+ { "name": "deletefile", "type": "boolean", "default": false, "description": "Whether to delete the physical file" }
+ ],
"returns": "string"
},
"VideoLibrary.RemoveTVShow": {
@@ -1320,7 +1321,8 @@
"transport": "Response",
"permission": "RemoveData",
"params": [
- { "name": "episodeid", "$ref": "Library.Id", "required": true }
+ { "name": "episodeid", "$ref": "Library.Id", "required": true },
+ { "name": "deletefile", "type": "boolean", "default": false, "description": "Whether to delete the physical file" }
],
"returns": "string"
},
@@ -1330,7 +1332,8 @@
"transport": "Response",
"permission": "RemoveData",
"params": [
- { "name": "musicvideoid", "$ref": "Library.Id", "required": true }
+ { "name": "musicvideoid", "$ref": "Library.Id", "required": true },
+ { "name": "deletefile", "type": "boolean", "default": false, "description": "Whether to delete the physical file" }
],
"returns": "string"
},
@@ -1341,7 +1344,7 @@
"permission": "UpdateData",
"params": [
{ "name": "directory", "type": "string", "default": "" }
- ],
+ ],
"returns": "string"
},
"VideoLibrary.Export": {

0 comments on commit 40db91b

Please sign in to comment.