From cb30feba46e00c68b1c5a307674f85d6a865d917 Mon Sep 17 00:00:00 2001 From: im85288 Date: Sun, 1 Jan 2017 16:06:40 +0000 Subject: [PATCH] support add/update krypton ratings --- addon.xml | 2 +- resources/lib/objects/_kodi_movies.py | 21 ++++++++ resources/lib/objects/_kodi_tvshows.py | 22 ++++++++ resources/lib/objects/movies.py | 36 ++++++++----- resources/lib/objects/tvshows.py | 71 +++++++++++++++++--------- 5 files changed, 116 insertions(+), 36 deletions(-) diff --git a/addon.xml b/addon.xml index 09d25e00..ef75ba40 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/lib/objects/_kodi_movies.py b/resources/lib/objects/_kodi_movies.py index 58f82456..9cb7a1d6 100644 --- a/resources/lib/objects/_kodi_movies.py +++ b/resources/lib/objects/_kodi_movies.py @@ -113,6 +113,16 @@ class KodiMovies(KodiItems): self.cursor.execute("DELETE FROM movie WHERE idMovie = ?", (kodi_id,)) self.cursor.execute("DELETE FROM files WHERE idFile = ?", (file_id,)) + def get_ratingid(self, media_id): + + query = "SELECT rating_id FROM rating WHERE media_id = ?" + self.cursor.execute(query, (media_id,)) + try: + ratingid = self.cursor.fetchone()[0] + except TypeError: + ratingid = None + + return ratingid def add_ratings(self, *args): query = ( @@ -134,6 +144,17 @@ class KodiMovies(KodiItems): )) self.cursor.execute(query, (args)) + def get_uniqueid(self, media_id): + + query = "SELECT uniqueid_id FROM uniqueid WHERE media_id = ?" + self.cursor.execute(query, (media_id,)) + try: + uniqueid = self.cursor.fetchone()[0] + except TypeError: + uniqueid = None + + return uniqueid + def add_uniqueid(self, *args): query = ( ''' diff --git a/resources/lib/objects/_kodi_tvshows.py b/resources/lib/objects/_kodi_tvshows.py index a1fbc5bc..aa291b9a 100644 --- a/resources/lib/objects/_kodi_tvshows.py +++ b/resources/lib/objects/_kodi_tvshows.py @@ -74,6 +74,17 @@ class KodiTVShows(KodiItems): return kodi_id + def get_ratingid(self, media_id): + + query = "SELECT rating_id FROM rating WHERE media_id = ?" + self.cursor.execute(query, (media_id,)) + try: + ratingid = self.cursor.fetchone()[0] + except TypeError: + ratingid = None + + return ratingid + def add_ratings(self, *args): query = ( ''' @@ -94,6 +105,17 @@ class KodiTVShows(KodiItems): )) self.cursor.execute(query, (args)) + def get_uniqueid(self, media_id): + + query = "SELECT uniqueid_id FROM uniqueid WHERE media_id = ?" + self.cursor.execute(query, (media_id,)) + try: + uniqueid = self.cursor.fetchone()[0] + except TypeError: + uniqueid = None + + return uniqueid + def add_uniqueid(self, *args): query = ( ''' diff --git a/resources/lib/objects/movies.py b/resources/lib/objects/movies.py index e54fb399..ccfa3075 100644 --- a/resources/lib/objects/movies.py +++ b/resources/lib/objects/movies.py @@ -234,23 +234,23 @@ class Movies(Items): } filename = "%s?%s" % (path, urllib.urlencode(params)) - # update new ratings Kodi 17 - todo get ratingid for updates from embydb - if self.kodi_version > 16: - ratingid = self.kodi_db.create_entry_rating() - - self.kodi_db.add_ratings(ratingid, movieid, "movie", "default", rating, votecount) - - # update new uniqueid Kodi 17 - todo get uniqueid_id for updates from embydb - if self.kodi_version > 16: - uniqueid = self.kodi_db.create_entry_uniqueid() - - self.kodi_db.add_uniqueid(uniqueid, movieid, "movie", imdb, "imdb") - ##### UPDATE THE MOVIE ##### if update_item: log.info("UPDATE movie itemid: %s - Title: %s", itemid, title) + # update new ratings Kodi 17 + if self.kodi_version > 16: + ratingid = self.kodi_db.get_ratingid(movieid) + + self.kodi_db.update_ratings(movieid, "movie", "default", rating, votecount,ratingid) + + # update new uniqueid Kodi 17 + if self.kodi_version > 16: + uniqueid = self.kodi_db.get_uniqueid(movieid) + + self.kodi_db.update_uniqueid(movieid, "movie", imdb, "imdb",uniqueid) + # Update the movie entry if self.kodi_version > 16: self.kodi_db.update_movie_17(title, plot, shortplot, tagline, votecount, uniqueid, @@ -269,6 +269,18 @@ class Movies(Items): else: log.info("ADD movie itemid: %s - Title: %s", itemid, title) + # add new ratings Kodi 17 + if self.kodi_version > 16: + ratingid = self.kodi_db.create_entry_rating() + + self.kodi_db.add_ratings(ratingid, movieid, "movie", "default", rating, votecount) + + # add new uniqueid Kodi 17 + if self.kodi_version > 16: + uniqueid = self.kodi_db.create_entry_uniqueid() + + self.kodi_db.add_uniqueid(uniqueid, movieid, "movie", imdb, "imdb") + # Add path pathid = self.kodi_db.add_path(path) # Add the file diff --git a/resources/lib/objects/tvshows.py b/resources/lib/objects/tvshows.py index 454e4140..23d819d4 100644 --- a/resources/lib/objects/tvshows.py +++ b/resources/lib/objects/tvshows.py @@ -336,22 +336,23 @@ class TVShows(Items): toplevelpath = "plugin://plugin.video.emby.tvshows/" path = "%s%s/" % (toplevelpath, itemid) - # update new ratings Kodi 17 - todo get ratingid for updates from embydb - if self.kodi_version > 16: - ratingid = self.kodi_db.create_entry_rating() - - self.kodi_db.add_ratings(ratingid, showid, "tvshow", "default", rating, votecount) - - # update new uniqueid Kodi 17 - todo get uniqueid_id for updates from embydb - if self.kodi_version > 16: - uniqueid = self.kodi_db.create_entry_uniqueid() - - self.kodi_db.add_uniqueid(uniqueid, showid, "tvshow", imdb, "imdb") ##### UPDATE THE TVSHOW ##### if update_item: log.info("UPDATE tvshow itemid: %s - Title: %s", itemid, title) + # update new ratings Kodi 17 + if self.kodi_version > 16: + ratingid = self.kodi_db.get_ratingid(showid) + + self.kodi_db.update_ratings(showid, "tvshow", "default", rating, votecount,ratingid) + + # update new uniqueid Kodi 17 + if self.kodi_version > 16: + uniqueid = self.kodi_db.get_uniqueid(showid) + + self.kodi_db.update_uniqueid(showid, "tvshow", imdb, "imdb",uniqueid) + # Update the tvshow entry if self.kodi_version > 16: self.kodi_db.update_tvshow(title, plot, uniqueid, premieredate, genre, title, @@ -366,6 +367,18 @@ class TVShows(Items): else: log.info("ADD tvshow itemid: %s - Title: %s", itemid, title) + # add new ratings Kodi 17 + if self.kodi_version > 16: + ratingid = self.kodi_db.create_entry_rating() + + self.kodi_db.add_ratings(ratingid, showid, "tvshow", "default", rating, votecount) + + # add new uniqueid Kodi 17 + if self.kodi_version > 16: + uniqueid = self.kodi_db.create_entry_uniqueid() + + self.kodi_db.add_uniqueid(uniqueid, showid, "tvshow", imdb, "imdb") + # Add top path toppathid = self.kodi_db.add_path(toplevelpath) self.kodi_db.update_path(toppathid, toplevelpath, "tvshows", "metadata.local") @@ -589,22 +602,22 @@ class TVShows(Items): } filename = "%s?%s" % (path, urllib.urlencode(params)) - # update new ratings Kodi 17 - todo get ratingid for updates from embydb - if self.kodi_version > 16: - ratingid = self.kodi_db.create_entry_rating() - - self.kodi_db.add_ratings(ratingid, showid, "episode", "default", rating, votecount) - - # update new uniqueid Kodi 17 - todo get uniqueid_id for updates from embydb - if self.kodi_version > 16: - uniqueid = self.kodi_db.create_entry_uniqueid() - - self.kodi_db.add_uniqueid(uniqueid, showid, "episode", tvdb, "tvdb") - ##### UPDATE THE EPISODE ##### if update_item: log.info("UPDATE episode itemid: %s - Title: %s", itemid, title) + # update new ratings Kodi 17 + if self.kodi_version > 16: + ratingid = self.kodi_db.get_ratingid(episodeid) + + self.kodi_db.update_ratings(episodeid, "episode", "default", rating, votecount,ratingid) + + # update new uniqueid Kodi 17 + if self.kodi_version > 16: + uniqueid = self.kodi_db.get_uniqueid(episodeid) + + self.kodi_db.update_uniqueid(episodeid, "episode", tvdb, "tvdb",uniqueid) + # Update the episode entry if self.kodi_version > 16: # Kodi Krypton @@ -630,6 +643,18 @@ class TVShows(Items): else: log.info("ADD episode itemid: %s - Title: %s", itemid, title) + # add new ratings Kodi 17 + if self.kodi_version > 16: + ratingid = self.kodi_db.create_entry_rating() + + self.kodi_db.add_ratings(ratingid, showid, "episode", "default", rating, votecount) + + # add new uniqueid Kodi 17 + if self.kodi_version > 16: + uniqueid = self.kodi_db.create_entry_uniqueid() + + self.kodi_db.add_uniqueid(uniqueid, showid, "episode", tvdb, "tvdb") + # Add path pathid = self.kodi_db.add_path(path) # Add the file