Skip to content

Commit

Permalink
jsonrpc: add "filter" parameter to VideoLibrary.GetMusicVideos
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Aug 6, 2012
1 parent 9f545f8 commit 7b8abd5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
14 changes: 11 additions & 3 deletions xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -1991,11 +1991,19 @@ namespace JSONRPC
"\"transport\": \"Response\","
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"artistid\", \"$ref\": \"Library.Id\" },"
"{ \"name\": \"albumid\", \"$ref\": \"Library.Id\" },"
"{ \"name\": \"properties\", \"$ref\": \"Video.Fields.MusicVideo\" },"
"{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
"{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
"{ \"name\": \"sort\", \"$ref\": \"List.Sort\" },"
"{ \"name\": \"filter\","
"\"type\": ["
"{ \"type\": \"object\", \"properties\": { \"artist\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"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\": { \"director\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
"{ \"type\": \"object\", \"properties\": { \"studio\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false }"
"]"
"}"
"],"
"\"returns\": { \"type\": \"object\","
"\"properties\": {"
Expand Down
20 changes: 17 additions & 3 deletions xbmc/interfaces/json-rpc/VideoLibrary.cpp
Expand Up @@ -311,11 +311,25 @@ JSONRPC_STATUS CVideoLibrary::GetMusicVideos(const CStdString &method, ITranspor
if (!ParseSorting(parameterObject, sorting.sortBy, sorting.sortOrder, sorting.sortAttributes))
return InvalidParams;

int artistID = (int)parameterObject["artistid"].asInteger();
int albumID = (int)parameterObject["albumid"].asInteger();
CVideoDbUrl videoUrl;
videoUrl.FromString("videodb://3/2/");
int genreID = -1, year = -1;
const CVariant &filter = parameterObject["filter"];
if (filter.isMember("artist"))
videoUrl.AddOption("artist", filter["artist"].asString());
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("director"))
videoUrl.AddOption("director", filter["director"].asString());
if (filter.isMember("studio"))
videoUrl.AddOption("studio", filter["studio"].asString());

CFileItemList items;
if (!videodatabase.GetMusicVideosNav("videodb://3/2/", items, -1, -1, artistID, -1, -1, albumID, sorting))
if (!videodatabase.GetMusicVideosNav(videoUrl.ToString(), items, genreID, year, -1, -1, -1, -1, sorting))
return InternalError;

return GetAdditionalMusicVideoDetails(parameterObject, items, result, videodatabase);
Expand Down
14 changes: 11 additions & 3 deletions xbmc/interfaces/json-rpc/methods.json
Expand Up @@ -1127,11 +1127,19 @@
"transport": "Response",
"permission": "ReadData",
"params": [
{ "name": "artistid", "$ref": "Library.Id" },
{ "name": "albumid", "$ref": "Library.Id" },
{ "name": "properties", "$ref": "Video.Fields.MusicVideo" },
{ "name": "limits", "$ref": "List.Limits" },
{ "name": "sort", "$ref": "List.Sort" }
{ "name": "sort", "$ref": "List.Sort" },
{ "name": "filter",
"type": [
{ "type": "object", "properties": { "artist": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "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": { "director": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
{ "type": "object", "properties": { "studio": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false }
]
}
],
"returns": { "type": "object",
"properties": {
Expand Down
30 changes: 29 additions & 1 deletion xbmc/video/VideoDatabase.cpp
Expand Up @@ -9100,29 +9100,57 @@ bool CVideoDatabase::GetFilter(const CVideoDbUrl &videoUrl, Filter &filter) cons
filter.AppendWhere(PrepareSQL("genrelinkmusicvideo.idGenre = %i", (int)option->second.asInteger()));
}

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

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

option = options.find("studio");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join studiolinkmusicvideo on studiolinkmusicvideo.idMVideo = musicvideoview.idMVideo join studio on studio.idStudio = studiolinkmusicvideo.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 directorlinkmusicvideo on directorlinkmusicvideo.idMVideo = musicvideoview.idMVideo"));
filter.AppendWhere(PrepareSQL("directorlinkmusicvideo.idDirector = %i", (int)option->second.asInteger()));
}

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

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

option = options.find("artistid");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo = musicvideoview.idMVideo"));
filter.AppendWhere(PrepareSQL("artistlinkmusicvideo.idArtist = %i", (int)option->second.asInteger()));
}

option = options.find("artist");
if (option != options.end())
{
filter.AppendJoin(PrepareSQL("join artistlinkmusicvideo on artistlinkmusicvideo.idMVideo = musicvideoview.idMVideo join actors on actors.idActor = artistlinkmusicvideo.idArtist"));
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("albumid");
Expand Down

0 comments on commit 7b8abd5

Please sign in to comment.