From 8acf07c607068c352f87c8953885f05422943ac6 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Mon, 9 Jan 2017 20:33:52 +0100 Subject: [PATCH] Krypton: add ratings and IMDB id for movies --- resources/lib/itemtypes.py | 32 ++++++++++++++++ resources/lib/kodidb_functions.py | 63 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 40cf7e70..3935afb7 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -268,6 +268,22 @@ class Movies(Items): # Update the movie entry if KODIVERSION > 16: + # update new ratings Kodi 17 + ratingid = self.kodi_db.get_ratingid(movieid) + self.kodi_db.update_ratings(movieid, + PF.KODI_TYPE_MOVIE, + "default", + rating, + votecount, + ratingid) + # update new uniqueid Kodi 17 + uniqueid = self.kodi_db.get_uniqueid(movieid) + self.kodi_db.update_uniqueid(movieid, + PF.KODI_TYPE_MOVIE, + imdb, + "imdb", + uniqueid) + query = ' '.join(( "UPDATE movie", "SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?," @@ -299,6 +315,22 @@ class Movies(Items): else: log.info("ADD movie itemid: %s - Title: %s" % (itemid, title)) if KODIVERSION > 16: + # add new ratings Kodi 17 + ratingid = self.kodi_db.create_entry_rating() + self.kodi_db.add_ratings(ratingid, + movieid, + PF.KODI_TYPE_MOVIE, + "default", + rating, + votecount) + # add new uniqueid Kodi 17 + uniqueid = self.kodi_db.create_entry_uniqueid() + self.kodi_db.add_uniqueid(uniqueid, + movieid, + PF.KODI_TYPE_MOVIE, + imdb, + "imdb") + query = ( ''' INSERT INTO movie( idMovie, idFile, c00, c01, c02, c03, diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index db83ea1b..e1c7ff6b 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -1399,6 +1399,69 @@ class Kodidb_Functions(): query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)" self.cursor.execute(query, (genreid, kodiid)) +# Krypton only stuff ############################## + + def create_entry_uniqueid(self): + self.cursor.execute( + "select coalesce(max(uniqueid_id),0) from uniqueid") + return self.cursor.fetchone()[0] + 1 + + def add_uniqueid(self, *args): + """ + Feed with: + uniqueid_id, media_id, media_type, value, type + + type: e.g. 'imdb' + """ + query = ''' + INSERT INTO uniqueid( + uniqueid_id, media_id, media_type, value, type) + VALUES (?, ?, ?, ?, ?) + ''' + self.cursor.execute(query, (args)) + + def create_entry_rating(self): + self.cursor.execute("select coalesce(max(rating_id),0) from rating") + return self.cursor.fetchone()[0] + 1 + + 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 update_ratings(self, *args): + """ + Feed with media_id, media_type, rating_type, rating, votes, rating_id + """ + query = ''' + UPDATE rating + SET media_id = ?, + media_type = ?, + rating_type = ?, + rating = ?, + votes = ? + WHERE rating_id = ? + ''' + self.cursor.execute(query, (args)) + + def add_ratings(self, *args): + """ + feed with: + rating_id, media_id, media_type, rating_type, rating, votes + + rating_type = 'default' + """ + query = ''' + INSERT INTO rating( + rating_id, media_id, media_type, rating_type, rating, votes) + VALUES (?, ?, ?, ?, ?, ?) + ''' + self.cursor.execute(query, (args)) + def get_kodiid_from_filename(file): """