diff --git a/resources/lib/itemtypes/tvshows.py b/resources/lib/itemtypes/tvshows.py index 6838b770..c0b2d6c0 100644 --- a/resources/lib/itemtypes/tvshows.py +++ b/resources/lib/itemtypes/tvshows.py @@ -269,6 +269,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): @@ -278,7 +279,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 @@ -316,15 +317,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 6ea2412e..47fc9559 100644 --- a/resources/lib/kodi_db/video.py +++ b/resources/lib/kodi_db/video.py @@ -741,15 +741,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 ca1045de..bfc3a11f 100644 --- a/resources/lib/plex_api/base.py +++ b/resources/lib/plex_api/base.py @@ -397,6 +397,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