Browse files

Merge pull request #10020 from phate89/ratings_as_art

Change ratings to reflect json art (and future uniqueid) structure
  • Loading branch information...
2 parents 6bf535d + 9373279 commit 273131114c5ee64810e9dc91f8bb61839e7b9f36 @phate89 phate89 committed on GitHub Jun 23, 2016
View
45 xbmc/interfaces/json-rpc/VideoLibrary.cpp
@@ -528,7 +528,7 @@ JSONRPC_STATUS CVideoLibrary::SetMovieDetails(const std::string &method, ITransp
return InternalError;
CVideoInfoTag infos;
- if (!videodatabase.GetMovieInfo("", infos, id) || infos.m_iDbId <= 0)
+ if (!videodatabase.GetMovieInfo("", infos, id, RequiresInitialDetails(parameterObject)) || infos.m_iDbId <= 0)
return InvalidParams;
// get artwork
@@ -605,7 +605,7 @@ JSONRPC_STATUS CVideoLibrary::SetTVShowDetails(const std::string &method, ITrans
return InternalError;
CVideoInfoTag infos;
- if (!videodatabase.GetTvShowInfo("", infos, id) || infos.m_iDbId <= 0)
+ if (!videodatabase.GetTvShowInfo("", infos, id, (CFileItem *)0, RequiresInitialDetails(parameterObject)) || infos.m_iDbId <= 0)
return InvalidParams;
// get artwork
@@ -676,7 +676,7 @@ JSONRPC_STATUS CVideoLibrary::SetEpisodeDetails(const std::string &method, ITran
return InternalError;
CVideoInfoTag infos;
- videodatabase.GetEpisodeInfo("", infos, id);
+ videodatabase.GetEpisodeInfo("", infos, id, RequiresInitialDetails(parameterObject));
if (infos.m_iDbId <= 0)
{
videodatabase.Close();
@@ -988,6 +988,14 @@ bool CVideoLibrary::FillFileItemList(const CVariant &parameterObject, CFileItemL
return success;
}
+int CVideoLibrary::RequiresInitialDetails(const CVariant &parameterObject)
+{
+ int details = VideoDbDetailsNone;
+ if (ParameterNotNull(parameterObject, "ratings") || ParameterNotNull(parameterObject, "rating") || ParameterNotNull(parameterObject, "votes"))
+ return VideoDbDetailsRating;
+ return details;
+}
+
int CVideoLibrary::RequiresAdditionalDetails(const MediaType& mediaType, const CVariant &parameterObject)
{
if (mediaType != MediaTypeMovie && mediaType != MediaTypeTvShow && mediaType != MediaTypeEpisode && mediaType != MediaTypeMusicVideo)
@@ -1116,30 +1124,25 @@ void CVideoLibrary::UpdateVideoTag(const CVariant &parameterObject, CVideoInfoTa
}
if (ParameterNotNull(parameterObject, "ratings"))
{
- RatingMap ratings;
- std::string def = "";
- for (CVariant::const_iterator_array rIt = parameterObject["ratings"].begin_array(); rIt != parameterObject["ratings"].end_array(); rIt++)
+ CVariant ratings = parameterObject["ratings"];
+ for (CVariant::const_iterator_map rIt = ratings.begin_map(); rIt != ratings.end_map(); rIt++)
{
- auto& rating = *rIt;
- if (ParameterNotNull(rating, "name") && ParameterNotNull(rating, "rating"))
+ if (rIt->second.isObject() && ParameterNotNull(rIt->second, "rating"))
{
+ const auto& rating = rIt->second;
if (ParameterNotNull(rating, "votes"))
- ratings[rating["name"].asString()] = CRating(rating["rating"].asFloat(), rating["votes"].asInteger());
+ details.AddRating(rating["rating"].asFloat(), rating["votes"].asFloat(), rIt->first, (ParameterNotNull(rating, "default") && rating["default"].asBoolean()));
else
- ratings[rating["name"].asString()] = CRating(rating["rating"].asFloat());
- if (ParameterNotNull(rating, "default") && rating["default"].asBoolean())
- def = rating["name"].asString();
+ details.SetRating(rating["rating"].asFloat(), rIt->first, (ParameterNotNull(rating, "default") && rating["default"].asBoolean()));
+
+ updatedDetails.insert("ratings");
+ }
+ else if (rIt->second.isNull())
+ {
+ details.RemoveRating(rIt->first);
+ updatedDetails.insert("ratings");
}
}
- if (def.empty() && !ratings.empty())
- {
- if (ratings.find(details.m_strDefaultRating) == ratings.end())
- details.m_strDefaultRating = ratings.begin()->first;
- }
- else
- details.m_strDefaultRating = def;
- details.SetRatings(ratings);
- updatedDetails.insert("ratings");
}
if (ParameterNotNull(parameterObject, "userrating"))
details.m_iUserRating = parameterObject["userrating"].asInteger();
View
1 xbmc/interfaces/json-rpc/VideoLibrary.h
@@ -84,6 +84,7 @@ namespace JSONRPC
private:
static int RequiresAdditionalDetails(const MediaType& mediaType, const CVariant &parameterObject);
+ static int RequiresInitialDetails(const CVariant &parameterObject);
static JSONRPC_STATUS HandleItems(const char *idProperty, const char *resultName, CFileItemList &items, const CVariant &parameterObject, CVariant &result, bool limit = true);
static JSONRPC_STATUS RemoveVideo(const CVariant &parameterObject);
static void UpdateVideoTag(const CVariant &parameterObject, CVideoInfoTag &details, std::map<std::string, std::string> &artwork, std::set<std::string> &removedArtwork, std::set<std::string>& updatedDetails);
View
6 xbmc/interfaces/json-rpc/schema/methods.json
@@ -1491,7 +1491,7 @@
{ "name": "art", "type": [ "null", { "$ref": "Media.Artwork.Set", "required": true } ], "default": null },
{ "name": "resume", "type": [ "null", { "$ref": "Video.Resume", "required": true } ], "default": null },
{ "name": "userrating", "$ref": "Optional.Integer" },
- { "name": "ratings", "$ref": "Video.Ratings" },
+ { "name": "ratings", "$ref": "Video.Ratings.Set" },
{ "name": "dateadded", "$ref": "Optional.String" },
{ "name": "premiered", "$ref": "Optional.String", "description": "linked with year. Overriedes year" }
],
@@ -1535,7 +1535,7 @@
{ "name": "tag", "type": [ "null", { "$ref": "Array.String", "required": true } ], "default": null },
{ "name": "art", "type": [ "null", { "$ref": "Media.Artwork.Set", "required": true } ], "default": null },
{ "name": "userrating", "$ref": "Optional.Integer" },
- { "name": "ratings", "$ref": "Video.Ratings" },
+ { "name": "ratings", "$ref": "Video.Ratings.Set" },
{ "name": "dateadded", "$ref": "Optional.String" },
{ "name": "runtime", "$ref": "Optional.Integer", "description": "Runtime in seconds" },
{ "name": "status", "$ref": "Optional.String" }
@@ -1580,7 +1580,7 @@
{ "name": "art", "type": [ "null", { "$ref": "Media.Artwork.Set", "required": true } ], "default": null },
{ "name": "resume", "type": [ "null", { "$ref": "Video.Resume", "required": true } ], "default": null },
{ "name": "userrating", "$ref": "Optional.Integer" },
- { "name": "ratings", "$ref": "Video.Ratings" },
+ { "name": "ratings", "$ref": "Video.Ratings.Set" },
{ "name": "dateadded", "$ref": "Optional.String" }
],
"returns": "string"
View
28 xbmc/interfaces/json-rpc/schema/types.json
@@ -392,6 +392,22 @@
},
"additionalProperties": { "type": [ "null", { "$ref": "Global.String.NotEmpty", "required": true } ] }
},
+ "Video.Rating": {
+ "type": "object",
+ "properties": {
+ "rating": { "type": "number", "required": true },
+ "votes": { "type": "integer" },
+ "default": { "type": "boolean" }
+ }
+ },
+ "Video.Ratings": {
+ "type": "object",
+ "additionalProperties": { "$ref": "Video.Rating" }
+ },
+ "Video.Ratings.Set": {
+ "type": "object",
+ "additionalProperties": { "type": [ "null", { "$ref": "Video.Rating", "required": true } ] }
+ },
"Library.Fields.Genre": {
"extends": "Item.Fields.Base",
"items": { "type": "string", "enum": [ "title", "thumbnail" ] }
@@ -672,18 +688,6 @@
"additionalProperties": false
}
},
- "Video.Ratings": {
- "type": "array",
- "items": { "type": "object",
- "properties": {
- "name": { "type": "string", "required": true },
- "rating": { "type": "number", "required": true },
- "votes": { "type": "integer" },
- "default": { "type": "boolean" }
- },
- "additionalProperties": false
- }
- },
"Video.Streams": {
"type": "object",
"properties": {
View
2 xbmc/interfaces/json-rpc/schema/version.txt
@@ -1 +1 @@
-7.15.2
+7.16.0
View
23 xbmc/video/VideoDatabase.cpp
@@ -2190,7 +2190,7 @@ int CVideoDatabase::SetDetailsForMovie(const std::string& strFilenameAndPath, CV
AddActorLinksToItem(idMovie, MediaTypeMovie, "writer", details.m_writingCredits);
// add ratings
- details.m_iIdRating = AddRatings(idMovie, MediaTypeMovie, details.m_ratings, details.m_strDefaultRating);
+ details.m_iIdRating = AddRatings(idMovie, MediaTypeMovie, details.m_ratings, details.GetDefaultRating());
// add set...
int idSet = -1;
@@ -2285,7 +2285,7 @@ int CVideoDatabase::UpdateDetailsForMovie(int idMovie, CVideoInfoTag& details, c
if (updatedDetails.find("art.altered") != updatedDetails.end())
SetArtForItem(idMovie, MediaTypeMovie, artwork);
if (updatedDetails.find("ratings") != updatedDetails.end())
- details.m_iIdRating = UpdateRatings(idMovie, MediaTypeMovie, details.m_ratings, details.m_strDefaultRating);
+ details.m_iIdRating = UpdateRatings(idMovie, MediaTypeMovie, details.m_ratings, details.GetDefaultRating());
if (updatedDetails.find("dateadded") != updatedDetails.end() && details.m_dateAdded.IsValid())
{
if (details.m_iFileId <= 0)
@@ -2461,7 +2461,7 @@ bool CVideoDatabase::UpdateDetailsForTvShow(int idTvShow, CVideoInfoTag &details
AddActorLinksToItem(idTvShow, MediaTypeTvShow, "director", details.m_director);
// add ratings
- details.m_iIdRating = AddRatings(idTvShow, MediaTypeTvShow, details.m_ratings, details.m_strDefaultRating);
+ details.m_iIdRating = AddRatings(idTvShow, MediaTypeTvShow, details.m_ratings, details.GetDefaultRating());
// add "all seasons" - the rest are added in SetDetailsForEpisode
AddSeason(idTvShow, -1);
@@ -2590,7 +2590,7 @@ int CVideoDatabase::SetDetailsForEpisode(const std::string& strFilenameAndPath,
AddActorLinksToItem(idEpisode, MediaTypeEpisode, "writer", details.m_writingCredits);
// add ratings
- details.m_iIdRating = AddRatings(idEpisode, MediaTypeEpisode, details.m_ratings, details.m_strDefaultRating);
+ details.m_iIdRating = AddRatings(idEpisode, MediaTypeEpisode, details.m_ratings, details.GetDefaultRating());
if (details.HasStreamDetails())
{
@@ -3677,8 +3677,9 @@ CVideoInfoTag CVideoDatabase::GetDetailsForMovie(const dbiplus::sql_record* cons
details.m_resumePoint.totalTimeInSeconds = record->at(VIDEODB_DETAILS_MOVIE_TOTAL_TIME).get_asInt();
details.m_resumePoint.type = CBookmark::RESUME;
details.m_iUserRating = record->at(VIDEODB_DETAILS_MOVIE_USER_RATING).get_asInt();
- details.m_strDefaultRating = record->at(VIDEODB_DETAILS_MOVIE_RATING_TYPE).get_asString();
- details.AddRating(record->at(VIDEODB_DETAILS_MOVIE_RATING).get_asFloat(), record->at(VIDEODB_DETAILS_MOVIE_VOTES).get_asInt());
+ details.AddRating(record->at(VIDEODB_DETAILS_MOVIE_RATING).get_asFloat(),
+ record->at(VIDEODB_DETAILS_MOVIE_VOTES).get_asInt(),
+ record->at(VIDEODB_DETAILS_MOVIE_RATING_TYPE).get_asString(), true);
std::string premieredString = record->at(VIDEODB_DETAILS_MOVIE_PREMIERED).get_asString();
if (premieredString.size() == 4)
details.SetYear(record->at(VIDEODB_DETAILS_MOVIE_PREMIERED).get_asInt());
@@ -3755,8 +3756,9 @@ CVideoInfoTag CVideoDatabase::GetDetailsForTvShow(const dbiplus::sql_record* con
details.m_playCount = record->at(VIDEODB_DETAILS_TVSHOW_NUM_WATCHED).get_asInt();
details.m_strShowTitle = details.m_strTitle;
details.m_iUserRating = record->at(VIDEODB_DETAILS_TVSHOW_USER_RATING).get_asInt();
- details.m_strDefaultRating = record->at(VIDEODB_DETAILS_TVSHOW_RATING_TYPE).get_asString();
- details.AddRating(record->at(VIDEODB_DETAILS_TVSHOW_RATING).get_asFloat(), record->at(VIDEODB_DETAILS_TVSHOW_VOTES).get_asInt());
+ details.AddRating(record->at(VIDEODB_DETAILS_TVSHOW_RATING).get_asFloat(),
+ record->at(VIDEODB_DETAILS_TVSHOW_VOTES).get_asInt(),
+ record->at(VIDEODB_DETAILS_TVSHOW_RATING_TYPE).get_asString(), true);
details.m_duration = record->at(VIDEODB_DETAILS_TVSHOW_DURATION).get_asInt();
movieTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
@@ -3831,8 +3833,9 @@ CVideoInfoTag CVideoDatabase::GetDetailsForEpisode(const dbiplus::sql_record* co
details.m_resumePoint.totalTimeInSeconds = record->at(VIDEODB_DETAILS_EPISODE_TOTAL_TIME).get_asInt();
details.m_resumePoint.type = CBookmark::RESUME;
details.m_iUserRating = record->at(VIDEODB_DETAILS_EPISODE_USER_RATING).get_asInt();
- details.m_strDefaultRating = record->at(VIDEODB_DETAILS_EPISODE_RATING_TYPE).get_asString();
- details.AddRating(record->at(VIDEODB_DETAILS_EPISODE_RATING).get_asFloat(), record->at(VIDEODB_DETAILS_EPISODE_VOTES).get_asInt());
+ details.AddRating(record->at(VIDEODB_DETAILS_EPISODE_RATING).get_asFloat(),
+ record->at(VIDEODB_DETAILS_EPISODE_VOTES).get_asInt(),
+ record->at(VIDEODB_DETAILS_EPISODE_RATING_TYPE).get_asString(), true);
movieTime += XbmcThreads::SystemClockMillis() - time; time = XbmcThreads::SystemClockMillis();
if (getDetails)
View
37 xbmc/video/VideoInfoTag.cpp
@@ -556,17 +556,17 @@ void CVideoInfoTag::Serialize(CVariant& value) const
value["episode"] = m_iEpisode;
value["uniqueid"]["unknown"] = m_strUniqueId;
value["rating"] = GetRating().rating;
- value["ratings"] = CVariant(CVariant::VariantTypeArray);
+ CVariant ratings = CVariant(CVariant::VariantTypeObject);
for (const auto& i : m_ratings)
{
CVariant rating;
- rating["name"] = i.first;
rating["rating"] = i.second.rating;
rating["votes"] = i.second.votes;
- if (i.first == m_strDefaultRating)
- rating["default"] = true;
- value["ratings"].push_back(rating);
+ rating["default"] = i.first == m_strDefaultRating;
+
+ ratings[i.first] = rating;
}
+ value["ratings"] = ratings;
value["userrating"] = m_iUserRating;
value["dbid"] = m_iDbId;
value["fileid"] = m_iFileId;
@@ -681,6 +681,11 @@ const CRating CVideoInfoTag::GetRating(std::string type) const
return rating->second;
}
+const std::string& CVideoInfoTag::GetDefaultRating() const
+{
+ return m_strDefaultRating;
+}
+
const bool CVideoInfoTag::HasYear() const
{
return m_premiered.IsValid();
@@ -1195,25 +1200,41 @@ void CVideoInfoTag::SetPictureURL(CScraperUrl &pictureURL)
m_strPictureURL = pictureURL;
}
-void CVideoInfoTag::AddRating(float rating, int votes, const std::string& type /* = "" */)
+void CVideoInfoTag::AddRating(float rating, int votes, const std::string& type /* = "" */, bool def /* = false */)
{
AddRating(CRating(rating, votes), type);
}
-void CVideoInfoTag::AddRating(CRating rating, const std::string& type /* = "" */)
+void CVideoInfoTag::AddRating(CRating rating, const std::string& type /* = "" */, bool def /* = false */)
{
if (type.empty())
m_ratings[m_strDefaultRating] = rating;
else
m_ratings[type] = rating;
+
+ if (def)
+ m_strDefaultRating = type;
}
-void CVideoInfoTag::SetRating(float rating, const std::string& type /* = "" */)
+void CVideoInfoTag::SetRating(float rating, const std::string& type /* = "" */, bool def /* = false */)
{
if (type.empty())
m_ratings[m_strDefaultRating].rating = rating;
else
m_ratings[type].rating = rating;
+
+ if (def)
+ m_strDefaultRating = type;
+}
+
+void CVideoInfoTag::RemoveRating(const std::string& type)
+{
+ if (m_ratings.find(type) != m_ratings.end())
+ {
+ m_ratings.erase(type);
+ if (m_strDefaultRating == type && !m_ratings.empty())
+ m_strDefaultRating = m_ratings.begin()->first;
+ }
}
void CVideoInfoTag::SetRatings(RatingMap ratings)
View
10 xbmc/video/VideoInfoTag.h
@@ -84,6 +84,7 @@ class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
virtual void Serialize(CVariant& value) const;
virtual void ToSortable(SortItem& sortable, Field field) const;
const CRating GetRating(std::string type = "") const;
+ const std::string& GetDefaultRating() const;
const bool HasYear() const;
const int GetYear() const;
const bool HasPremiered() const;
@@ -122,9 +123,10 @@ class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
void SetTitle(std::string title);
void SetSortTitle(std::string sortTitle);
void SetPictureURL(CScraperUrl &pictureURL);
- void AddRating(float rating, int votes, const std::string& type = "");
- void AddRating(CRating rating, const std::string& type = "");
- void SetRating(float rating, const std::string& type = "");
+ void AddRating(float rating, int votes, const std::string& type = "", bool def = false);
+ void AddRating(CRating rating, const std::string& type = "", bool def = false);
+ void SetRating(float rating, const std::string& type = "", bool def = false);
+ void RemoveRating(const std::string& type);
void SetRatings(RatingMap ratings);
void SetVotes(int votes, const std::string& type = "");
void SetPremiered(CDateTime premiered);
@@ -201,7 +203,6 @@ class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
int m_iTrack;
RatingMap m_ratings;
int m_iIdRating;
- std::string m_strDefaultRating;
int m_iUserRating;
CBookmark m_EpBookmark;
int m_iBookmarkId;
@@ -226,6 +227,7 @@ class CVideoInfoTag : public IArchivable, public ISerializable, public ISortable
*/
void ParseNative(const TiXmlElement* element, bool prioritise);
+ std::string m_strDefaultRating;
std::string Trim(std::string &&value);
std::vector<std::string> Trim(std::vector<std::string> &&items);
};

0 comments on commit 2731311

Please sign in to comment.