From 835e95d3fd4cde551d995cde462d090d80d6d711 Mon Sep 17 00:00:00 2001
From: im85288 <ianmalcolmmclaughlin@gmail.com>
Date: Sat, 31 Dec 2016 16:30:11 +0000
Subject: [PATCH] more krypton ratings

---
 addon.xml                        |  2 +-
 resources/lib/objects/movies.py  | 29 +++++------
 resources/lib/objects/tvshows.py | 83 +++++++++++++++++++-------------
 3 files changed, 65 insertions(+), 49 deletions(-)

diff --git a/addon.xml b/addon.xml
index 6f596887..7d506117 100644
--- a/addon.xml
+++ b/addon.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <addon  id="plugin.video.emby"
         name="Emby" 
-        version="2.3.28"
+        version="2.3.29"
         provider-name="Emby.media">
   <requires>
     <import addon="xbmc.python" version="2.19.0"/>
diff --git a/resources/lib/objects/movies.py b/resources/lib/objects/movies.py
index 322b90bb..e54fb399 100644
--- a/resources/lib/objects/movies.py
+++ b/resources/lib/objects/movies.py
@@ -234,6 +234,18 @@ 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:
@@ -241,8 +253,8 @@ class Movies(Items):
 
             # Update the movie entry
             if self.kodi_version > 16:
-                self.kodi_db.update_movie_17(title, plot, shortplot, tagline, votecount, rating,
-                                             writer, year, imdb, sorttitle, runtime, mpaa, genre,
+                self.kodi_db.update_movie_17(title, plot, shortplot, tagline, votecount, uniqueid,
+                                             writer, year, uniqueid, sorttitle, runtime, mpaa, genre,
                                              director, title, studio, trailer, country, year,
                                              movieid)
             else:
@@ -265,7 +277,7 @@ class Movies(Items):
             # Create the movie entry
             if self.kodi_version > 16:
                 self.kodi_db.add_movie_17(movieid, fileid, title, plot, shortplot, tagline,
-                                          votecount, rating, writer, year, imdb, sorttitle,
+                                          votecount, uniqueid, writer, year, uniqueid, sorttitle,
                                           runtime, mpaa, genre, director, title, studio, trailer,
                                           country, year)
             else:
@@ -309,17 +321,6 @@ 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)
-
-        # 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")
         return True
 
     def add_updateBoxset(self, boxset):
diff --git a/resources/lib/objects/tvshows.py b/resources/lib/objects/tvshows.py
index 1241c496..6f3cb188 100644
--- a/resources/lib/objects/tvshows.py
+++ b/resources/lib/objects/tvshows.py
@@ -335,15 +335,29 @@ 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", tvdb, "tvdb")
 
         ##### UPDATE THE TVSHOW #####
         if update_item:
             log.info("UPDATE tvshow itemid: %s - Title: %s", itemid, title)
 
             # Update the tvshow entry
-            self.kodi_db.update_tvshow(title, plot, rating, premieredate, genre, title,
-                                       tvdb, mpaa, studio, sorttitle, showid)
-
+            if self.kodi_version > 16:
+                self.kodi_db.update_tvshow(title, plot, uniqueid, premieredate, genre, title,
+                                             uniqueid, mpaa, studio, sorttitle, showid)
+            else:
+                self.kodi_db.update_tvshow(title, plot, rating, premieredate, genre, title,
+                                           tvdb, mpaa, studio, sorttitle, showid)
             # Update the checksum in emby table
             emby_db.updateReference(itemid, checksum)
 
@@ -359,8 +373,12 @@ class TVShows(Items):
             pathid = self.kodi_db.add_path(path)
 
             # Create the tvshow entry
-            self.kodi_db.add_tvshow(showid, title, plot, rating, premieredate, genre,
-                                    title, tvdb, mpaa, studio, sorttitle)
+            if self.kodi_version > 16:
+                self.kodi_db.add_tvshow(showid, title, plot, uniqueid, premieredate, genre,
+                                    title, uniqueid, mpaa, studio, sorttitle)
+            else:
+                self.kodi_db.add_tvshow(showid, title, plot, rating, premieredate, genre,
+                                        title, tvdb, mpaa, studio, sorttitle)
 
             # Create the reference in emby table
             emby_db.addReference(itemid, showid, "Series", "tvshow", pathid=pathid,
@@ -404,18 +422,6 @@ 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):
@@ -582,14 +588,30 @@ 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 the movie entry
-            if self.kodi_version in (16, 17):
-                # Kodi Jarvis, Krypton
+            # Update the episode entry
+            if self.kodi_version > 16:
+                # Kodi Krypton
+                self.kodi_db.update_episode_16(title, plot, uniqueid, writer, premieredate, runtime,
+                                               director, season, episode, title, airsBeforeSeason,
+                                               airsBeforeEpisode, seasonid, showid, episodeid)
+            elif self.kodi_version in 16:
+                # Kodi Jarvis
                 self.kodi_db.update_episode_16(title, plot, rating, writer, premieredate, runtime,
                                                director, season, episode, title, airsBeforeSeason,
                                                airsBeforeEpisode, seasonid, showid, episodeid)
@@ -613,8 +635,13 @@ class TVShows(Items):
             fileid = self.kodi_db.add_file(filename, pathid)
 
             # Create the episode entry
-            if self.kodi_version in (16, 17):
-                # Kodi Jarvis, Krypton
+            if self.kodi_version > 16:
+                # Kodi Krypton
+                self.kodi_db.add_episode_16(episodeid, fileid, title, plot, uniqueid, writer,
+                                            premieredate, runtime, director, season, episode, title,
+                                            showid, airsBeforeSeason, airsBeforeEpisode, seasonid)
+            elif self.kodi_version in 16:
+                # Kodi Jarvis
                 self.kodi_db.add_episode_16(episodeid, fileid, title, plot, rating, writer,
                                             premieredate, runtime, director, season, episode, title,
                                             showid, airsBeforeSeason, airsBeforeEpisode, seasonid)
@@ -652,18 +679,6 @@ 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):