Skip to content

Commit

Permalink
closes #11439: jsonrpc: added VideoLibrary.GetMovieSets and VideoLibr…
Browse files Browse the repository at this point in the history
…ary.GetMovieSetDetails

* montellese/jsonrpc_extensions:
  Use newly added CVideoDatabase::GetSetInfo() to retrieve movie set details
  jsonrpc: added VideoLibrary.GetMovieSets and VideoLibrary.GetMovieSetDetails
  • Loading branch information
Montellese committed Apr 23, 2011
2 parents 8fc0054 + 030d000 commit 0c441d9
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 24 deletions.
2 changes: 2 additions & 0 deletions xbmc/interfaces/json-rpc/JSONRPC.cpp
Expand Up @@ -168,6 +168,8 @@ JsonRpcMethodMap CJSONRPC::m_methodMaps[] = {
// Video Library
{ "VideoLibrary.GetMovies", CVideoLibrary::GetMovies },
{ "VideoLibrary.GetMovieDetails", CVideoLibrary::GetMovieDetails },
{ "VideoLibrary.GetMovieSets", CVideoLibrary::GetMovieSets },
{ "VideoLibrary.GetMovieSetDetails", CVideoLibrary::GetMovieSetDetails },
{ "VideoLibrary.GetTVShows", CVideoLibrary::GetTVShows },
{ "VideoLibrary.GetTVShowDetails", CVideoLibrary::GetTVShowDetails },
{ "VideoLibrary.GetSeasons", CVideoLibrary::GetSeasons },
Expand Down
66 changes: 66 additions & 0 deletions xbmc/interfaces/json-rpc/ServiceDescription.h
Expand Up @@ -1388,6 +1388,72 @@ namespace JSONRPC
"}"
"}"
"},"
"\"VideoLibrary.GetMovieSets\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve all movie sets\","
"\"transport\": \"Response\","
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"fields\", \"type\": \"array\", \"id\": \"Library.Fields.MovieSet\", \"uniqueItems\": true,"
"\"items\": { \"type\": \"string\","
"\"enum\": [ \"title\", \"playcount\", \"fanart\", \"thumbnail\" ]"
"}"
"},"
"{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
"{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
"],"
"\"returns\": { \"type\": \"object\","
"\"properties\": {"
"\"limits\": { \"$ref\": \"List.LimitsReturned\", \"required\": true },"
"\"sets\": { \"type\": \"array\","
"\"items\": { \"type\": \"object\", \"id\": \"Library.Details.MovieSet\","
"\"properties\": {"
"\"setid\": { \"$ref\": \"Library.Id\", \"required\": true },"
"\"label\": { \"type\": \"string\", \"required\": true },"
"\"fanart\": { \"type\": \"string\" },"
"\"thumbnail\": { \"type\": \"string\" },"
"\"title\": { \"type\": \"string\" },"
"\"playcount\": { \"type\": \"integer\" }"
"}"
"}"
"}"
"}"
"}"
"},"
"\"VideoLibrary.GetMovieSetDetails\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve details about a specific movie set\","
"\"transport\": \"Response\","
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"setid\", \"$ref\": \"Library.Id\", \"required\": true },"
"{ \"name\": \"fields\", \"$ref\": \"Library.Fields.MovieSet\" },"
"{ \"name\": \"movies\", \"type\": \"object\","
"\"properties\": {"
"\"fields\": { \"$ref\": \"Library.Fields.Movie\" },"
"\"limits\": { \"$ref\": \"List.Limits\" },"
"\"sort\": { \"$ref\": \"List.Sort\" }"
"}"
"}"
"],"
"\"returns\": { \"type\": \"object\","
"\"properties\": {"
"\"setdetails\": { \"type\": \"object\", \"id\": \"Library.Details.MovieSet\","
"\"properties\": {"
"\"setid\": { \"$ref\": \"Library.Id\", \"required\": true },"
"\"label\": { \"type\": \"string\", \"required\": true },"
"\"fanart\": { \"type\": \"string\" },"
"\"thumbnail\": { \"type\": \"string\" },"
"\"title\": { \"type\": \"string\" },"
"\"playcount\": { \"type\": \"integer\" },"
"\"movies\": { \"type\": \"array\","
"\"items\": { \"$ref\": \"Library.Details.Movie\" }"
"}"
"}"
"}"
"}"
"}"
"},"
"\"VideoLibrary.GetTVShows\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve all tv shows\","
Expand Down
97 changes: 77 additions & 20 deletions xbmc/interfaces/json-rpc/VideoLibrary.cpp
Expand Up @@ -35,29 +35,12 @@ JSON_STATUS CVideoLibrary::GetMovies(const CStdString &method, ITransportLayer *
return InternalError;

CFileItemList items;
JSON_STATUS ret = OK;
if (videodatabase.GetMoviesByWhere("videodb://", "", "", items))
{
bool additionalInfo = false;
Json::ValueConstIterator it;
for (it = parameterObject["fields"].begin(); it != parameterObject["fields"].end(); it++)
{
CStdString fieldValue = parameterObject["fields"][it.index()].asString();
if (fieldValue == "cast" || fieldValue == "set" || fieldValue == "showlink")
additionalInfo = true;
}

if (additionalInfo)
{
for (int index = 0; index < items.Size(); index++)
{
videodatabase.GetMovieInfo("", *(items[index]->GetVideoInfoTag()), items[index]->GetVideoInfoTag()->m_iDbId);
}
}
HandleFileItemList("movieid", true, "movies", items, parameterObject, result);
}
ret = GetAdditionalMovieDetails(parameterObject, items, result);

videodatabase.Close();
return OK;
return ret;
}

JSON_STATUS CVideoLibrary::GetMovieDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const Value &parameterObject, Value &result)
Expand All @@ -84,6 +67,53 @@ JSON_STATUS CVideoLibrary::GetMovieDetails(const CStdString &method, ITransportL
return OK;
}

JSON_STATUS CVideoLibrary::GetMovieSets(const CStdString &method, ITransportLayer *transport, IClient *client, const Value &parameterObject, Value &result)
{
CVideoDatabase videodatabase;
if (!videodatabase.Open())
return InternalError;

CFileItemList items;
if (videodatabase.GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES))
HandleFileItemList("setid", false, "sets", items, parameterObject, result);

videodatabase.Close();
return OK;
}

JSON_STATUS CVideoLibrary::GetMovieSetDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const Value &parameterObject, Value &result)
{
int id = parameterObject["setid"].asInt();

CVideoDatabase videodatabase;
if (!videodatabase.Open())
return InternalError;

// Get movie set details
CVideoInfoTag infos;
videodatabase.GetSetInfo(id, infos);
if (infos.m_iDbId <= 0)
{
videodatabase.Close();
return InvalidParams;
}

Value validFields = Value(arrayValue);
MakeFieldsList(parameterObject, validFields);
HandleFileItem("setid", false, "setdetails", CFileItemPtr(new CFileItem(infos)), parameterObject, validFields, result, false);

// Get movies from the set
CFileItemList items;
JSON_STATUS ret = OK;
if (videodatabase.GetMoviesNav("", items, -1, -1, -1, -1, -1, -1, id))
{
ret = GetAdditionalMovieDetails(parameterObject["movies"], items, result["setdetails"]["items"]);
}

videodatabase.Close();
return ret;
}

JSON_STATUS CVideoLibrary::GetTVShows(const CStdString &method, ITransportLayer *transport, IClient *client, const Value &parameterObject, Value &result)
{
CVideoDatabase videodatabase;
Expand Down Expand Up @@ -392,3 +422,30 @@ bool CVideoLibrary::FillFileItemList(const Value &parameterObject, CFileItemList

return false;
}

JSON_STATUS CVideoLibrary::GetAdditionalMovieDetails(const Value &parameterObject, CFileItemList &items, Value &result)
{
CVideoDatabase videodatabase;
if (!videodatabase.Open())
return InternalError;

bool additionalInfo = false;
Json::ValueConstIterator it;
for (it = parameterObject["fields"].begin(); it != parameterObject["fields"].end(); it++)
{
CStdString fieldValue = parameterObject["fields"][it.index()].asString();
if (fieldValue == "cast" || fieldValue == "set" || fieldValue == "showlink")
additionalInfo = true;
}

if (additionalInfo)
{
for (int index = 0; index < items.Size(); index++)
{
videodatabase.GetMovieInfo("", *(items[index]->GetVideoInfoTag()), items[index]->GetVideoInfoTag()->m_iDbId);
}
}
HandleFileItemList("movieid", true, "movies", items, parameterObject, result);

return OK;
}
6 changes: 6 additions & 0 deletions xbmc/interfaces/json-rpc/VideoLibrary.h
Expand Up @@ -32,6 +32,9 @@ namespace JSONRPC
static JSON_STATUS GetMovies(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);
static JSON_STATUS GetMovieDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);

static JSON_STATUS GetMovieSets(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);
static JSON_STATUS GetMovieSetDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);

static JSON_STATUS GetTVShows(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);
static JSON_STATUS GetTVShowDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);
static JSON_STATUS GetSeasons(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);
Expand All @@ -48,5 +51,8 @@ namespace JSONRPC
static JSON_STATUS ScanForContent(const CStdString &method, ITransportLayer *transport, IClient *client, const Json::Value &parameterObject, Json::Value &result);

static bool FillFileItemList(const Json::Value &parameterObject, CFileItemList &list);

private:
static JSON_STATUS GetAdditionalMovieDetails(const Json::Value &parameterObject, CFileItemList &items, Json::Value &result);
};
}
24 changes: 24 additions & 0 deletions xbmc/video/VideoDatabase.cpp
Expand Up @@ -1605,6 +1605,28 @@ void CVideoDatabase::GetMusicVideoInfo(const CStdString& strFilenameAndPath, CVi
}
}

void CVideoDatabase::GetSetInfo(int idSet, CVideoInfoTag& details)
{
try
{
if (idSet < 0)
return;

CStdString where = PrepareSQL("WHERE sets.idSet=%d", idSet);
CFileItemList items;
if (!GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES, where) ||
items.Size() != 1 ||
!items[0]->HasVideoInfoTag())
return;

details = *(items[0]->GetVideoInfoTag());
}
catch (...)
{
CLog::Log(LOGERROR, "%s (%d) failed", __FUNCTION__, idSet);
}
}

void CVideoDatabase::AddGenreAndDirectorsAndStudios(const CVideoInfoTag& details, vector<int>& vecDirectors, vector<int>& vecGenres, vector<int>& vecStudios)
{
// add all directors
Expand Down Expand Up @@ -3824,6 +3846,7 @@ bool CVideoDatabase::GetSetsNav(const CStdString& strBaseDir, CFileItemList& ite
for (it=mapSets.begin();it != mapSets.end();++it)
{
CFileItemPtr pItem(new CFileItem(it->second.first));
pItem->GetVideoInfoTag()->m_iDbId = it->first;
CStdString strDir;
strDir.Format("%ld/", it->first);
pItem->m_strPath=strBaseDir + strDir;
Expand All @@ -3845,6 +3868,7 @@ bool CVideoDatabase::GetSetsNav(const CStdString& strBaseDir, CFileItemList& ite
while (!m_pDS->eof())
{
CFileItemPtr pItem(new CFileItem(m_pDS->fv("sets.strSet").get_asString()));
pItem->GetVideoInfoTag()->m_iDbId = m_pDS->fv("sets.idSet").get_asInt();
CStdString strDir;
strDir.Format("%ld/", m_pDS->fv("sets.idSet").get_asInt());
pItem->m_strPath=strBaseDir + strDir;
Expand Down
1 change: 1 addition & 0 deletions xbmc/video/VideoDatabase.h
Expand Up @@ -367,6 +367,7 @@ class CVideoDatabase : public CDatabase
void GetTvShowInfo(const CStdString& strPath, CVideoInfoTag& details, int idTvShow = -1);
bool GetEpisodeInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1);
void GetMusicVideoInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idMVideo=-1);
void GetSetInfo(int idSet, CVideoInfoTag& details);

int GetPathId(const CStdString& strPath);
int GetTvShowId(const CStdString& strPath);
Expand Down
5 changes: 1 addition & 4 deletions xbmc/video/windows/GUIWindowVideoBase.cpp
Expand Up @@ -1567,10 +1567,7 @@ void CGUIWindowVideoBase::UpdateVideoTitle(const CFileItem* pItem)
if (iType == VIDEODB_CONTENT_MOVIES)
database.GetMovieInfo("", detail, pItem->GetVideoInfoTag()->m_iDbId);
if (iType == VIDEODB_CONTENT_MOVIE_SETS)
{
detail.m_strTitle = database.GetSetById(params.GetSetId());
iDbId = params.GetSetId();
}
database.GetSetInfo(params.GetSetId(), detail);
if (iType == VIDEODB_CONTENT_EPISODES)
database.GetEpisodeInfo(pItem->m_strPath,detail,pItem->GetVideoInfoTag()->m_iDbId);
if (iType == VIDEODB_CONTENT_TVSHOWS)
Expand Down

0 comments on commit 0c441d9

Please sign in to comment.