Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

jsonrpc: make use of the new sorting and limiting in VideoLibrary met…

…hods
  • Loading branch information...
commit 8643a436309554ba613dabcfca5aa5e68ee030d7 1 parent c8d5b54
@Montellese authored
View
104 xbmc/interfaces/json-rpc/FileItemHandler.cpp
@@ -175,7 +175,7 @@ void CFileItemHandler::FillDetails(ISerializable* info, CFileItemPtr item, const
}
}
-void CFileItemHandler::HandleFileItemList(const char *ID, bool allowFile, const char *resultname, CFileItemList &items, const CVariant &parameterObject, CVariant &result)
+void CFileItemHandler::HandleFileItemList(const char *ID, bool allowFile, const char *resultname, CFileItemList &items, const CVariant &parameterObject, CVariant &result, bool sortLimit /* = true */)
{
int size = items.Size();
int start = (int)parameterObject["limits"]["start"].asInteger();
@@ -183,12 +183,19 @@ void CFileItemHandler::HandleFileItemList(const char *ID, bool allowFile, const
end = (end <= 0 || end > size) ? size : end;
start = start > end ? end : start;
- Sort(items, parameterObject["sort"]);
+ if (sortLimit)
+ Sort(items, parameterObject["sort"]);
result["limits"]["start"] = start;
result["limits"]["end"] = end;
result["limits"]["total"] = size;
+ if (!sortLimit)
+ {
+ start = 0;
+ end = items.Size();
+ }
+
for (int i = start; i < end; i++)
{
CVariant object;
@@ -331,6 +338,99 @@ bool CFileItemHandler::FillFileItemList(const CVariant &parameterObject, CFileIt
return (list.Size() > 0);
}
+bool CFileItemHandler::ParseSorting(const CVariant &parameterObject, SortBy &sortBy, SortOrder &sortOrder, SortAttribute &sortAttributes)
+{
+ CStdString method = parameterObject["sort"]["method"].asString();
+ CStdString order = parameterObject["sort"]["order"].asString();
+ method.ToLower();
+ order.ToLower();
+
+ sortAttributes = SortAttributeNone;
+ if (parameterObject["sort"]["ignorearticle"].asBoolean())
+ sortAttributes = SortAttributeIgnoreArticle;
+ else
+ sortAttributes = SortAttributeNone;
+
+ if (order.Equals("ascending"))
+ sortOrder = SortOrderAscending;
+ else if (order.Equals("descending"))
+ sortOrder = SortOrderDescending;
+ else
+ return false;
+
+ if (method.Equals("none"))
+ sortBy = SortByNone;
+ else if (method.Equals("label"))
+ sortBy = SortByLabel;
+ else if (method.Equals("date"))
+ sortBy = SortByDate;
+ else if (method.Equals("size"))
+ sortBy = SortBySize;
+ else if (method.Equals("file"))
+ sortBy = SortByFile;
+ else if (method.Equals("drivetype"))
+ sortBy = SortByDriveType;
+ else if (method.Equals("track"))
+ sortBy = SortByTrackNumber;
+ else if (method.Equals("duration") ||
+ method.Equals("videoruntime"))
+ sortBy = SortByTime;
+ else if (method.Equals("title") ||
+ method.Equals("videotitle"))
+ sortBy = SortByTitle;
+ else if (method.Equals("artist"))
+ sortBy = SortByArtist;
+ else if (method.Equals("album"))
+ sortBy = SortByAlbum;
+ else if (method.Equals("genre"))
+ sortBy = SortByGenre;
+ else if (method.Equals("country"))
+ sortBy = SortByCountry;
+ else if (method.Equals("year"))
+ sortBy = SortByYear;
+ else if (method.Equals("videorating") ||
+ method.Equals("songrating"))
+ sortBy = SortByRating;
+ else if (method.Equals("dateadded"))
+ sortBy = SortByDateAdded;
+ else if (method.Equals("programcount"))
+ sortBy = SortByProgramCount;
+ else if (method.Equals("playlist"))
+ sortBy = SortByPlaylistOrder;
+ else if (method.Equals("episode"))
+ sortBy = SortByEpisodeNumber;
+ else if (method.Equals("sorttitle"))
+ sortBy = SortBySortTitle;
+ else if (method.Equals("productioncode"))
+ sortBy = SortByProductionCode;
+ else if (method.Equals("mpaarating"))
+ sortBy = SortByMPAA;
+ else if (method.Equals("studio"))
+ sortBy = SortByStudio;
+ else if (method.Equals("fullpath"))
+ sortBy = SortByPath;
+ else if (method.Equals("lastplayed"))
+ sortBy = SortByLastPlayed;
+ else if (method.Equals("playcount"))
+ sortBy = SortByPlaycount;
+ else if (method.Equals("listeners"))
+ sortBy = SortByListeners;
+ else if (method.Equals("unsorted"))
+ sortBy = SortByRandom;
+ else if (method.Equals("bitrate"))
+ sortBy = SortByBitrate;
+ else
+ return false;

This looks like it should be in a LUT already (smartplaylist uses the same?)

@Montellese Owner

Unfortunately it isn't. The ones in smartplaylist are e.g. named "rating" and not "songrating" and "videorating". Same with "track" and "duration"/"videoruntime". I had to add this because of backwards-compatibility to Eden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ return true;
+}
+
+void CFileItemHandler::ParseLimits(const CVariant &parameterObject, int &limitStart, int &limitEnd)
+{
+ limitStart = (int)parameterObject["limits"]["start"].asInteger();
+ limitEnd = (int)parameterObject["limits"]["end"].asInteger();
+}
+
bool CFileItemHandler::ParseSortMethods(const CStdString &method, const bool &ignorethe, const CStdString &order, SORT_METHOD &sortmethod, SortOrder &sortorder)
{
if (order.Equals("ascending"))
View
5 xbmc/interfaces/json-rpc/FileItemHandler.h
@@ -31,10 +31,13 @@ namespace JSONRPC
{
protected:
static void FillDetails(ISerializable* info, CFileItemPtr item, const CVariant& fields, CVariant &result);
- static void HandleFileItemList(const char *ID, bool allowFile, const char *resultname, CFileItemList &items, const CVariant &parameterObject, CVariant &result);
+ static void HandleFileItemList(const char *ID, bool allowFile, const char *resultname, CFileItemList &items, const CVariant &parameterObject, CVariant &result, bool sortLimit = true);
static void HandleFileItem(const char *ID, bool allowFile, const char *resultname, CFileItemPtr item, const CVariant &parameterObject, const CVariant &validFields, CVariant &result, bool append = true);
static bool FillFileItemList(const CVariant &parameterObject, CFileItemList &list);
+
+ static bool ParseSorting(const CVariant &parameterObject, SortBy &sortBy, SortOrder &sortOrder, SortAttribute &sortAttributes);
+ static void ParseLimits(const CVariant &parameterObject, int &limitStart, int &limitEnd);
private:
static bool ParseSortMethods(const CStdString &method, const bool &ignorethe, const CStdString &order, SORT_METHOD &sortmethod, SortOrder &sortorder);
static void Sort(CFileItemList &items, const CVariant& parameterObject);
View
59 xbmc/interfaces/json-rpc/VideoLibrary.cpp
@@ -35,7 +35,7 @@ JSONRPC_STATUS CVideoLibrary::GetMovies(const CStdString &method, ITransportLaye
CFileItemList items;
JSONRPC_STATUS ret = OK;
- if (videodatabase.GetMoviesByWhere("videodb://1/", "", items))
+ if ((ret = GetVideos(MediaTypeMovie, "videodb://1/", parameterObject, items, result, videodatabase)) == OK)
ret = GetAdditionalMovieDetails(parameterObject, items, result, videodatabase);
videodatabase.Close();
@@ -71,8 +71,10 @@ JSONRPC_STATUS CVideoLibrary::GetMovieSets(const CStdString &method, ITransportL
return InternalError;
CFileItemList items;
- if (videodatabase.GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES))
- HandleFileItemList("setid", false, "sets", items, parameterObject, result);
+ if (!videodatabase.GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES))
+ return InternalError;
+
+ HandleFileItemList("setid", false, "sets", items, parameterObject, result);
videodatabase.Close();
return OK;
@@ -114,7 +116,8 @@ JSONRPC_STATUS CVideoLibrary::GetTVShows(const CStdString &method, ITransportLay
return InternalError;
CFileItemList items;
- if (videodatabase.GetTvShowsNav("videodb://2/", items))
+ JSONRPC_STATUS ret = OK;
+ if ((ret = GetVideos(MediaTypeTvShow, "videodb://2/", parameterObject, items, result, videodatabase)) == OK)
{
bool additionalInfo = false;
for (CVariant::const_iterator_array itr = parameterObject["properties"].begin_array(); itr != parameterObject["properties"].end_array(); itr++)
@@ -129,7 +132,7 @@ JSONRPC_STATUS CVideoLibrary::GetTVShows(const CStdString &method, ITransportLay
for (int index = 0; index < items.Size(); index++)
videodatabase.GetTvShowInfo("", *(items[index]->GetVideoInfoTag()), items[index]->GetVideoInfoTag()->m_iDbId);
}
- HandleFileItemList("tvshowid", true, "tvshows", items, parameterObject, result);
+ HandleFileItemList("tvshowid", true, "tvshows", items, parameterObject, result, false);
}
videodatabase.Close();
@@ -169,8 +172,10 @@ JSONRPC_STATUS CVideoLibrary::GetSeasons(const CStdString &method, ITransportLay
CStdString strPath;
strPath.Format("videodb://2/2/%i/", tvshowID);
CFileItemList items;
- if (videodatabase.GetSeasonsNav(strPath, items, -1, -1, -1, -1, tvshowID))
- HandleFileItemList(NULL, false, "seasons", items, parameterObject, result);
+ if (!videodatabase.GetSeasonsNav(strPath, items, -1, -1, -1, -1, tvshowID))
+ return InternalError;
+
+ HandleFileItemList(NULL, false, "seasons", items, parameterObject, result);
videodatabase.Close();
return OK;
@@ -185,14 +190,21 @@ JSONRPC_STATUS CVideoLibrary::GetEpisodes(const CStdString &method, ITransportLa
if (!videodatabase.Open())
return InternalError;
+ SortDescription sorting;
+ ParseLimits(parameterObject, sorting.limitStart, sorting.limitEnd);
+ if (!ParseSorting(parameterObject, sorting.sortBy, sorting.sortOrder, sorting.sortAttributes))
+ return InvalidParams;
+
CStdString strPath;
strPath.Format("videodb://2/2/%i/%i/", tvshowID, season);
CFileItemList items;
- if (videodatabase.GetEpisodesNav(strPath, items, -1, -1, -1, -1, tvshowID, season))
- GetAdditionalEpisodeDetails(parameterObject, items, result, videodatabase);
+ if (!videodatabase.GetEpisodesNav(strPath, items, -1, -1, -1, -1, tvshowID, season, sorting))
+ return InternalError;
+
+ JSONRPC_STATUS ret = GetAdditionalEpisodeDetails(parameterObject, items, result, videodatabase);
videodatabase.Close();
- return OK;
+ return ret;
}
JSONRPC_STATUS CVideoLibrary::GetEpisodeDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
@@ -233,9 +245,16 @@ JSONRPC_STATUS CVideoLibrary::GetMusicVideos(const CStdString &method, ITranspor
if (!videodatabase.Open())
return InternalError;
+ SortDescription sorting;
+ ParseLimits(parameterObject, sorting.limitStart, sorting.limitEnd);
+ if (!ParseSorting(parameterObject, sorting.sortBy, sorting.sortOrder, sorting.sortAttributes))
+ return InvalidParams;
+
CFileItemList items;
- if (videodatabase.GetMusicVideosNav("videodb://3/", items, -1, -1, artistID, -1, -1, albumID))
- GetAdditionalMusicVideoDetails(parameterObject, items, result, videodatabase);
+ if (!videodatabase.GetMusicVideosNav("videodb://3/", items, -1, -1, artistID, -1, -1, albumID, sorting))
+ return InternalError;
+
+ JSONRPC_STATUS ret = GetAdditionalMusicVideoDetails(parameterObject, items, result, videodatabase);
videodatabase.Close();
return OK;
@@ -622,6 +641,16 @@ bool CVideoLibrary::FillFileItemList(const CVariant &parameterObject, CFileItemL
return false;
}
+JSONRPC_STATUS CVideoLibrary::GetVideos(MediaType mediaType, const CStdString &strBaseDir, const CVariant &parameterObject, CFileItemList &items, CVariant &result, CVideoDatabase &videodatabase)
+{
+ SortDescription sorting;
+ ParseLimits(parameterObject, sorting.limitStart, sorting.limitEnd);
+ if (!ParseSorting(parameterObject, sorting.sortBy, sorting.sortOrder, sorting.sortAttributes))
+ return InvalidParams;
+
+ return videodatabase.GetSortedVideos(mediaType, strBaseDir, sorting, items) ? OK : InternalError;
+}
+
JSONRPC_STATUS CVideoLibrary::GetAdditionalMovieDetails(const CVariant &parameterObject, CFileItemList &items, CVariant &result, CVideoDatabase &videodatabase)
{
if (!videodatabase.Open())
@@ -640,7 +669,7 @@ JSONRPC_STATUS CVideoLibrary::GetAdditionalMovieDetails(const CVariant &paramete
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);
+ HandleFileItemList("movieid", true, "movies", items, parameterObject, result, false);
return OK;
}
@@ -663,7 +692,7 @@ JSONRPC_STATUS CVideoLibrary::GetAdditionalEpisodeDetails(const CVariant &parame
for (int index = 0; index < items.Size(); index++)
videodatabase.GetEpisodeInfo("", *(items[index]->GetVideoInfoTag()), items[index]->GetVideoInfoTag()->m_iDbId);
}
- HandleFileItemList("episodeid", true, "episodes", items, parameterObject, result);
+ HandleFileItemList("episodeid", true, "episodes", items, parameterObject, result, false);
return OK;
}
@@ -686,7 +715,7 @@ JSONRPC_STATUS CVideoLibrary::GetAdditionalMusicVideoDetails(const CVariant &par
for (int index = 0; index < items.Size(); index++)
videodatabase.GetMusicVideoInfo("", *(items[index]->GetVideoInfoTag()), items[index]->GetVideoInfoTag()->m_iDbId);
}
- HandleFileItemList("musicvideoid", true, "musicvideos", items, parameterObject, result);
+ HandleFileItemList("musicvideoid", true, "musicvideos", items, parameterObject, result, false);
return OK;
}
View
2  xbmc/interfaces/json-rpc/VideoLibrary.h
@@ -20,6 +20,7 @@
*
*/
+#include "utils/DatabaseUtils.h"
#include "utils/StdString.h"
#include "JSONRPC.h"
#include "FileItemHandler.h"
@@ -69,6 +70,7 @@ namespace JSONRPC
static bool FillFileItemList(const CVariant &parameterObject, CFileItemList &list);
private:
+ static JSONRPC_STATUS GetVideos(MediaType mediaType, const CStdString &strBaseDir, const CVariant &parameterObject, CFileItemList &items, CVariant &result, CVideoDatabase &videodatabase);
static JSONRPC_STATUS GetAdditionalMovieDetails(const CVariant &parameterObject, CFileItemList &items, CVariant &result, CVideoDatabase &videodatabase);
static JSONRPC_STATUS GetAdditionalEpisodeDetails(const CVariant &parameterObject, CFileItemList &items, CVariant &result, CVideoDatabase &videodatabase);
static JSONRPC_STATUS GetAdditionalMusicVideoDetails(const CVariant &parameterObject, CFileItemList &items, CVariant &result, CVideoDatabase &videodatabase);
Please sign in to comment.
Something went wrong with that request. Please try again.