diff --git a/addon.xml b/addon.xml index c23e5312..6f596887 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/lib/objects/_kodi_tvshows.py b/resources/lib/objects/_kodi_tvshows.py index 917cc25e..a1fbc5bc 100644 --- a/resources/lib/objects/_kodi_tvshows.py +++ b/resources/lib/objects/_kodi_tvshows.py @@ -21,6 +21,19 @@ class KodiTVShows(KodiItems): KodiItems.__init__(self) + def create_entry_uniqueid(self): + self.cursor.execute("select coalesce(max(uniqueid_id),0) from uniqueid") + kodi_id = self.cursor.fetchone()[0] + 1 + + return kodi_id + + def create_entry_rating(self): + self.cursor.execute("select coalesce(max(rating_id),0) from rating") + kodi_id = self.cursor.fetchone()[0] + 1 + + return kodi_id + + def create_entry(self): self.cursor.execute("select coalesce(max(idShow),0) from tvshow") kodi_id = self.cursor.fetchone()[0] + 1 @@ -61,6 +74,46 @@ class KodiTVShows(KodiItems): return kodi_id + def add_ratings(self, *args): + query = ( + ''' + INSERT INTO rating( + rating_id, media_id, media_type, rating_type, rating, votes) + + VALUES (?, ?, ?, ?, ?, ?) + ''' + ) + self.cursor.execute(query, (args)) + + def update_ratings(self, *args): + query = ' '.join(( + + "UPDATE rating", + "SET media_id = ?, media_type = ?, rating_type = ?, rating = ?, votes = ?", + "WHERE rating_id = ?" + )) + self.cursor.execute(query, (args)) + + def add_uniqueid(self, *args): + query = ( + ''' + INSERT INTO uniqueid( + uniqueid_id, media_id, media_type, value, type) + + VALUES (?, ?, ?, ?, ?) + ''' + ) + self.cursor.execute(query, (args)) + + def update_uniqueid(self, *args): + query = ' '.join(( + + "UPDATE uniqueid", + "SET media_id = ?, media_type = ?, value = ?, type = ?", + "WHERE uniqueid_id = ?" + )) + self.cursor.execute(query, (args)) + def add_tvshow(self, *args): query = ( diff --git a/resources/lib/objects/tvshows.py b/resources/lib/objects/tvshows.py index 9d192ccc..1241c496 100644 --- a/resources/lib/objects/tvshows.py +++ b/resources/lib/objects/tvshows.py @@ -281,6 +281,7 @@ class TVShows(Items): title = item['Name'] plot = API.get_overview() rating = item.get('CommunityRating') + votecount = item.get('VoteCount') premieredate = API.get_premiere_date() tvdb = API.get_provider('Tvdb') sorttitle = item['SortName'] @@ -403,6 +404,18 @@ class TVShows(Items): all_episodes = emby.getEpisodesbyShow(itemid) self.add_episodes(all_episodes['Items'], None) + # 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", tvdb, "tvdb") + return True def add_updateSeason(self, item, showid=None): @@ -489,6 +502,9 @@ class TVShows(Items): runtime = API.get_runtime() premieredate = API.get_premiere_date() + votecount = item.get('VoteCount') + tvdb = API.get_provider('Tvdb') + # episode details try: seriesId = item['SeriesId'] @@ -636,6 +652,18 @@ class TVShows(Items): self.kodi_db.update_file(tempfileid, filename, temppathid, dateadded) self.kodi_db.add_playstate(tempfileid, resume, total, playcount, dateplayed) + # 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") + return True def updateUserdata(self, item):