From 863919d6960053972cbb2adfb93c66dc5fe99884 Mon Sep 17 00:00:00 2001 From: im85288 Date: Thu, 29 Dec 2016 18:55:31 +0000 Subject: [PATCH] start of kodi ratings --- addon.xml | 2 +- resources/lib/objects/_kodi_movies.py | 27 +++++++++++++++++++++++++++ resources/lib/objects/movies.py | 6 ++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index ed0fbd92..54b5762b 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 467e17bb..ecfda1f6 100644 --- a/resources/lib/objects/_kodi_movies.py +++ b/resources/lib/objects/_kodi_movies.py @@ -21,6 +21,12 @@ class KodiMovies(KodiItems): KodiItems.__init__(self) + 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(idMovie),0) from movie") kodi_id = self.cursor.fetchone()[0] + 1 @@ -101,6 +107,27 @@ class KodiMovies(KodiItems): self.cursor.execute("DELETE FROM movie WHERE idMovie = ?", (kodi_id,)) self.cursor.execute("DELETE FROM files WHERE idFile = ?", (file_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_countries(self, kodi_id, countries): if self.kodi_version > 14: diff --git a/resources/lib/objects/movies.py b/resources/lib/objects/movies.py index ddb8682c..eb657041 100644 --- a/resources/lib/objects/movies.py +++ b/resources/lib/objects/movies.py @@ -309,6 +309,12 @@ class Movies(Items): total = round(float(runtime), 6) self.kodi_db.add_playstate(fileid, 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, movieid, "movie", "default", rating, votecount) + return True def add_updateBoxset(self, boxset):