From 9150e168f633677c4b6349b8cfb470d8bd5ab35f Mon Sep 17 00:00:00 2001 From: croneter Date: Wed, 24 Feb 2021 17:20:37 +0100 Subject: [PATCH] Sync name and user rating of a TV show season to Kodi --- resources/lib/itemtypes/tvshows.py | 18 ++++++++++++++---- resources/lib/kodi_db/video.py | 23 ++++++++++++++++++++--- resources/lib/plex_api/base.py | 6 ++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/resources/lib/itemtypes/tvshows.py b/resources/lib/itemtypes/tvshows.py index 632d7f2c..d983f5ce 100644 --- a/resources/lib/itemtypes/tvshows.py +++ b/resources/lib/itemtypes/tvshows.py @@ -270,6 +270,7 @@ class Show(TvShowMixin, ItemBase): unique_ids.get('imdb', unique_ids.get('tmdb'))) + class Season(TvShowMixin, ItemBase): def add_update(self, xml, section_name=None, section_id=None, children=None): @@ -279,7 +280,7 @@ class Season(TvShowMixin, ItemBase): api = API(xml) if not self.sync_this_item(section_id or api.library_section_id()): LOG.debug('Skipping sync of %s %s: %s - section %s not synched to ' - 'Kodi', api.plex_type, api.plex_id, api.title(), + 'Kodi', api.plex_type, api.plex_id, api.season_name(), section_id or api.library_section_id()) return plex_id = api.plex_id @@ -317,15 +318,24 @@ class Season(TvShowMixin, ItemBase): if key in artwork and artwork[key] == parent_artwork[key]: del artwork[key] if update_item: - LOG.info('UPDATE season plex_id %s - %s', plex_id, api.title()) + LOG.info('UPDATE season plex_id %s - %s', + plex_id, api.season_name()) kodi_id = season['kodi_id'] + self.kodidb.update_season(kodi_id, + parent_id, + api.index(), + api.season_name(), + api.userrating() or None) if app.SYNC.artwork: self.kodidb.modify_artwork(artwork, kodi_id, v.KODI_TYPE_SEASON) else: - LOG.info('ADD season plex_id %s - %s', plex_id, api.title()) - kodi_id = self.kodidb.add_season(parent_id, api.index()) + LOG.info('ADD season plex_id %s - %s', plex_id, api.season_name()) + kodi_id = self.kodidb.add_season(parent_id, + api.index(), + api.season_name(), + api.userrating() or None) if app.SYNC.artwork: self.kodidb.add_artwork(artwork, kodi_id, diff --git a/resources/lib/kodi_db/video.py b/resources/lib/kodi_db/video.py index 2466e5e3..6a349150 100644 --- a/resources/lib/kodi_db/video.py +++ b/resources/lib/kodi_db/video.py @@ -718,15 +718,32 @@ class KodiVideoDB(common.KodiDBBase): self.cursor.execute('DELETE FROM sets WHERE idSet = ?', (set_id,)) @db.catch_operationalerrors - def add_season(self, showid, seasonnumber): + def add_season(self, showid, seasonnumber, name, userrating): """ Adds a TV show season to the Kodi video DB or simply returns the ID, if there already is an entry in the DB """ - self.cursor.execute('INSERT INTO seasons(idShow, season) VALUES (?, ?)', - (showid, seasonnumber)) + self.cursor.execute(''' + INSERT INTO seasons( + idShow, season, name, userrating) + VALUES (?, ?, ?, ?) + ''', (showid, seasonnumber, name, userrating)) return self.cursor.lastrowid + @db.catch_operationalerrors + def update_season(self, seasonid, showid, seasonnumber, name, userrating): + """ + Updates a TV show season with a certain seasonid + """ + self.cursor.execute(''' + UPDATE seasons + SET idShow = ?, + season = ?, + name = ?, + userrating = ? + WHERE idSeason = ? + ''', (showid, seasonnumber, name, userrating, seasonid)) + @db.catch_operationalerrors def add_uniqueid(self, *args): """ diff --git a/resources/lib/plex_api/base.py b/resources/lib/plex_api/base.py index 9a749a60..60a0739a 100644 --- a/resources/lib/plex_api/base.py +++ b/resources/lib/plex_api/base.py @@ -398,6 +398,12 @@ class Base(object): """ return self.parent_index() + def season_name(self): + """ + Returns the season's name/title or None + """ + return self.xml.get('title') + def artist_name(self): """ Returns the artist name for an album: first it attempts to return