Skip to content

Commit

Permalink
jsonrpc: add "filter" parameter to VideoLibrary.GetMovies
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Aug 6, 2012
1 parent ef7aed5 commit 1e6822c
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 18 deletions.
16 changes: 15 additions & 1 deletion xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -1795,7 +1795,21 @@ namespace JSONRPC
"\"params\": ["
"{ \"name\": \"properties\", \"$ref\": \"Video.Fields.Movie\" },"
"{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
"{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
"{ \"name\": \"sort\", \"$ref\": \"List.Sort\" },"
"{ \"name\": \"filter\","
"\"type\": ["
"{ \"type\": \"object\", \"properties\": { \"genreid\": { \"$ref\": \"Library.Id\", \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"genre\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"year\": { \"type\": \"integer\", \"minimum\": 0, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"actor\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"director\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"studio\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"country\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"setid\": { \"$ref\": \"Library.Id\", \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"set\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"tag\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false }"
"]"
"}"
"],"
"\"returns\": {"
"\"type\": \"object\","
Expand Down
41 changes: 34 additions & 7 deletions xbmc/interfaces/json-rpc/VideoLibrary.cpp
Expand Up @@ -38,12 +38,40 @@ JSONRPC_STATUS CVideoLibrary::GetMovies(const CStdString &method, ITransportLaye
if (!ParseSorting(parameterObject, sorting.sortBy, sorting.sortOrder, sorting.sortAttributes))
return InvalidParams;

CVideoDbUrl videoUrl;
videoUrl.FromString("videodb://1/2/");
int genreID = -1, year = -1, setID = 0;
const CVariant &filter = parameterObject["filter"];
if (filter.isMember("genreid"))
genreID = (int)filter["genreid"].asInteger();
if (filter.isMember("genre"))
videoUrl.AddOption("genre", filter["genre"].asString());
if (filter.isMember("year"))
year = (int)filter["year"].asInteger();
if (filter.isMember("actor"))
videoUrl.AddOption("actor", filter["actor"].asString());
if (filter.isMember("director"))
videoUrl.AddOption("director", filter["director"].asString());
if (filter.isMember("studio"))
videoUrl.AddOption("studio", filter["studio"].asString());
if (filter.isMember("country"))
videoUrl.AddOption("country", filter["country"].asString());
if (filter.isMember("setid"))
setID = (int)filter["setid"].asInteger();
if (filter.isMember("set"))
videoUrl.AddOption("set", filter["set"].asString());
if (filter.isMember("tag"))
videoUrl.AddOption("tag", filter["tag"].asString());

// setID must not be -1 otherwise GetMoviesNav() will return sets
if (setID < 0)
setID = 0;

CFileItemList items;
JSONRPC_STATUS ret = OK;
if (!videodatabase.GetMoviesNav("videodb://1/2/", items, -1, -1, -1, -1, -1, -1, -1, -1, sorting))
ret = GetAdditionalMovieDetails(parameterObject, items, result, videodatabase);
if (!videodatabase.GetMoviesNav(videoUrl.ToString(), items, genreID, year, -1, -1, -1, -1, setID, -1, sorting))
return InvalidParams;

return ret;
return GetAdditionalMovieDetails(parameterObject, items, result, videodatabase);
}

JSONRPC_STATUS CVideoLibrary::GetMovieDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
Expand Down Expand Up @@ -121,9 +149,8 @@ JSONRPC_STATUS CVideoLibrary::GetTVShows(const CStdString &method, ITransportLay
return InvalidParams;

CFileItemList items;
JSONRPC_STATUS ret = OK;
if (!videodatabase.GetTvShowsNav("videodb://2/2/", items, -1, -1, -1, -1, -1, sorting))
return ret;
return InvalidParams;

bool additionalInfo = false;
for (CVariant::const_iterator_array itr = parameterObject["properties"].begin_array(); itr != parameterObject["properties"].end_array(); itr++)
Expand All @@ -144,7 +171,7 @@ JSONRPC_STATUS CVideoLibrary::GetTVShows(const CStdString &method, ITransportLay
size = (int)items.GetProperty("total").asInteger();
HandleFileItemList("tvshowid", true, "tvshows", items, parameterObject, result, size, false);

return ret;
return OK;
}

JSONRPC_STATUS CVideoLibrary::GetTVShowDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
Expand Down
16 changes: 15 additions & 1 deletion xbmc/interfaces/json-rpc/methods.json
Expand Up @@ -931,7 +931,21 @@
"params": [
{ "name": "properties", "$ref": "Video.Fields.Movie" },
{ "name": "limits", "$ref": "List.Limits" },
{ "name": "sort", "$ref": "List.Sort" }
{ "name": "sort", "$ref": "List.Sort" },
{ "name": "filter",
"type": [
{ "type": "object", "properties": { "genreid": { "$ref": "Library.Id", "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "genre": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "year": { "type": "integer", "minimum": 0, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "actor": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "director": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "studio": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "country": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "setid": { "$ref": "Library.Id", "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "set": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "tag": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false }
]
}
],
"returns": {
"type": "object",
Expand Down
67 changes: 58 additions & 9 deletions xbmc/video/VideoDatabase.cpp
Expand Up @@ -5462,21 +5462,21 @@ bool CVideoDatabase::GetMoviesNav(const CStdString& strBaseDir, CFileItemList& i
if (!videoUrl.FromString(strBaseDir))
return false;

if (idGenre != -1)
if (idGenre > 0)
videoUrl.AddOption("genreid", idGenre);
else if (idCountry != -1)
else if (idCountry > 0)
videoUrl.AddOption("countryid", idCountry);
else if (idStudio != -1)
else if (idStudio > 0)
videoUrl.AddOption("studioid", idStudio);
else if (idDirector != -1)
else if (idDirector > 0)
videoUrl.AddOption("directorid", idDirector);
else if (idYear !=-1)
else if (idYear > 0)
videoUrl.AddOption("year", idYear);
else if (idActor != -1)
else if (idActor > 0)
videoUrl.AddOption("actorid", idActor);
else if (idSet != -1)
else if (idSet > 0)
videoUrl.AddOption("setid", idSet);
else if (idTag != -1)
else if (idTag > 0)
videoUrl.AddOption("tagid", idTag);

Filter filter;
Expand Down Expand Up @@ -8806,48 +8806,97 @@ bool CVideoDatabase::GetFilter(const CVideoDbUrl &videoUrl, Filter &filter) cons
filter.AppendWhere(PrepareSQL("genrelinkmovie.idGenre = %i", (int)option->second.asInteger()));
}

option = options.find("genre");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join genrelinkmovie on genrelinkmovie.idMovie = movieview.idMovie join genre on genre.idGenre = genrelinkmovie.idGenre"));
filter.AppendWhere(PrepareSQL("genre.strGenre like '%s'", option->second.asString().c_str()));
}

option = options.find("countryid");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join countrylinkmovie on countrylinkmovie.idMovie = movieview.idMovie"));
filter.AppendWhere(PrepareSQL("countrylinkmovie.idCountry = %i", (int)option->second.asInteger()));
}

option = options.find("country");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join countrylinkmovie on countrylinkmovie.idMovie = movieview.idMovie join country on country.idCountry = countrylinkmovie.idCountry"));
filter.AppendWhere(PrepareSQL("country.strCountry like '%s'", option->second.asString().c_str()));
}

option = options.find("studioid");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join studiolinkmovie on studiolinkmovie.idMovie = movieview.idMovie"));
filter.AppendWhere(PrepareSQL("studiolinkmovie.idStudio = %i", (int)option->second.asInteger()));
}

option = options.find("studio");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join studiolinkmovie on studiolinkmovie.idMovie = movieview.idMovie join studio on studio.idStudio = studiolinkmovie.idStudio"));
filter.AppendWhere(PrepareSQL("studio.strStudio like '%s'", option->second.asString().c_str()));
}

option = options.find("directorid");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join directorlinkmovie on directorlinkmovie.idMovie = movieview.idMovie"));
filter.AppendWhere(PrepareSQL("directorlinkmovie.idDirector = %i", (int)option->second.asInteger()));
}

option = options.find("director");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join directorlinkmovie on directorlinkmovie.idMovie = movieview.idMovie join actors on actors.idActor = directorlinkmovie.idDirector"));
filter.AppendWhere(PrepareSQL("actors.strActor like '%s'", option->second.asString().c_str()));
}

option = options.find("year");
if (option != options.end())
filter.AppendWhere(PrepareSQL("movieview.c%02d = '%i'", VIDEODB_ID_YEAR, (int)option->second.asInteger()));

option = options.find("actorid");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join actorlinkmovie on actorlinkmovie.idMovie = movieview.idMovie"));
filter.AppendWhere(PrepareSQL("actorlinkmovie.idActor = %i", (int)option->second.asInteger()));
}

option = options.find("actor");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join actorlinkmovie on actorlinkmovie.idMovie = movieview.idMovie join actors on actors.idActor = actorlinkmovie.idActor"));
filter.AppendWhere(PrepareSQL("actors.idActor = %i", (int)option->second.asInteger()));
filter.AppendWhere(PrepareSQL("actors.strActor like '%s'", option->second.asString().c_str()));
}

option = options.find("setid");
if (option != options.end())
filter.AppendWhere(PrepareSQL("movieview.idSet = %i", (int)option->second.asInteger()));

option = options.find("set");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join setlinkmovie on setlinkmovie.idMovie = movieview.idMovie join sets on sets.idSet = setlinkmovie.idSet"));
filter.AppendWhere(PrepareSQL("sets.strSet like '%s'", option->second.asString().c_str()));
}

option = options.find("tagid");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join taglinks on taglinks.idMedia = movieview.idMovie AND taglinks.media_type = 'movie'"));
filter.AppendWhere(PrepareSQL("taglinks.idTag = %i", (int)option->second.asInteger()));
}

option = options.find("tag");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join taglinks on taglinks.idMedia = movieview.idMovie AND taglinks.media_type = 'movie' join tag on tag.idTag = taglinks.idTag"));
filter.AppendWhere(PrepareSQL("tag.strTag like '%s'", option->second.asString().c_str()));
}
}
else if (type == "tvshows")
{
Expand Down

0 comments on commit 1e6822c

Please sign in to comment.