diff options
author | phate89 <phates89@gmail.com> | 2016-06-23 19:45:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-23 19:45:15 +0200 |
commit | 273131114c5ee64810e9dc91f8bb61839e7b9f36 (patch) | |
tree | e5d2a6c5ddcc854ba42857808e5f81cd5335aaa1 | |
parent | 6bf535db36a16f042a0332a82ed68f96831fc0c8 (diff) | |
parent | 9373279d95ef1092f5f9b8c5a6348830c951d18c (diff) |
Merge pull request #10020 from phate89/ratings_as_art
Change ratings to reflect json art (and future uniqueid) structure
-rw-r--r-- | xbmc/interfaces/json-rpc/VideoLibrary.cpp | 45 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/VideoLibrary.h | 1 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/schema/methods.json | 6 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/schema/types.json | 28 | ||||
-rw-r--r-- | xbmc/interfaces/json-rpc/schema/version.txt | 2 | ||||
-rw-r--r-- | xbmc/video/VideoDatabase.cpp | 23 | ||||
-rw-r--r-- | xbmc/video/VideoInfoTag.cpp | 37 | ||||
-rw-r--r-- | xbmc/video/VideoInfoTag.h | 10 |
8 files changed, 93 insertions, 59 deletions
diff --git a/xbmc/interfaces/json-rpc/VideoLibrary.cpp b/xbmc/interfaces/json-rpc/VideoLibrary.cpp index 79d9ac3e5c..c9067a716b 100644 --- a/xbmc/interfaces/json-rpc/VideoLibrary.cpp +++ b/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 ¶meterObject, CFileItemL return success; } +int CVideoLibrary::RequiresInitialDetails(const CVariant ¶meterObject) +{ + 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 ¶meterObject) { if (mediaType != MediaTypeMovie && mediaType != MediaTypeTvShow && mediaType != MediaTypeEpisode && mediaType != MediaTypeMusicVideo) @@ -1116,30 +1124,25 @@ void CVideoLibrary::UpdateVideoTag(const CVariant ¶meterObject, 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(); diff --git a/xbmc/interfaces/json-rpc/VideoLibrary.h b/xbmc/interfaces/json-rpc/VideoLibrary.h index f1bac0bdae..efe9d5c937 100644 --- a/xbmc/interfaces/json-rpc/VideoLibrary.h +++ b/xbmc/interfaces/json-rpc/VideoLibrary.h @@ -84,6 +84,7 @@ namespace JSONRPC private: static int RequiresAdditionalDetails(const MediaType& mediaType, const CVariant ¶meterObject); + static int RequiresInitialDetails(const CVariant ¶meterObject); static JSONRPC_STATUS HandleItems(const char *idProperty, const char *resultName, CFileItemList &items, const CVariant ¶meterObject, CVariant &result, bool limit = true); static JSONRPC_STATUS RemoveVideo(const CVariant ¶meterObject); static void UpdateVideoTag(const CVariant ¶meterObject, CVideoInfoTag &details, std::map<std::string, std::string> &artwork, std::set<std::string> &removedArtwork, std::set<std::string>& updatedDetails); diff --git a/xbmc/interfaces/json-rpc/schema/methods.json b/xbmc/interfaces/json-rpc/schema/methods.json index 9c16789b39..e4897ef52c 100644 --- a/xbmc/interfaces/json-rpc/schema/methods.json +++ b/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" diff --git a/xbmc/interfaces/json-rpc/schema/types.json b/xbmc/interfaces/json-rpc/schema/types.json index 79460f69a0..6264dea038 100644 --- a/xbmc/interfaces/json-rpc/schema/types.json +++ b/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": { diff --git a/xbmc/interfaces/json-rpc/schema/version.txt b/xbmc/interfaces/json-rpc/schema/version.txt index 2f4d6d31b9..ee0a997c17 100644 --- a/xbmc/interfaces/json-rpc/schema/version.txt +++ b/xbmc/interfaces/json-rpc/schema/version.txt @@ -1 +1 @@ -7.15.2
\ No newline at end of file +7.16.0
\ No newline at end of file diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 2b9740aa4f..b02a203052 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/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) diff --git a/xbmc/video/VideoInfoTag.cpp b/xbmc/video/VideoInfoTag.cpp index 6736acde52..79f9362826 100644 --- a/xbmc/video/VideoInfoTag.cpp +++ b/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) diff --git a/xbmc/video/VideoInfoTag.h b/xbmc/video/VideoInfoTag.h index 16c50a7014..e4ead3427d 100644 --- a/xbmc/video/VideoInfoTag.h +++ b/xbmc/video/VideoInfoTag.h @@ -84,6 +84,7 @@ public: 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 @@ public: 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 @@ public: 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 @@ private: */ 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); }; |