diff --git a/resources/lib/itemtypes/movies.py b/resources/lib/itemtypes/movies.py index 63bd0fd1..57926f9e 100644 --- a/resources/lib/itemtypes/movies.py +++ b/resources/lib/itemtypes/movies.py @@ -111,6 +111,9 @@ class Movie(ItemBase): self.kodidb.modify_people(kodi_id, v.KODI_TYPE_MOVIE, api.people_list()) + self.kodidb.modify_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_MOVIE) else: LOG.info("ADD movie plex_id: %s - %s", plex_id, title) rating_id = self.kodidb.get_ratingid(kodi_id, @@ -134,6 +137,9 @@ class Movie(ItemBase): self.kodidb.add_people(kodi_id, v.KODI_TYPE_MOVIE, api.people_list()) + self.kodidb.add_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_MOVIE) # Update Kodi's main entry self.kodidb.add_movie(kodi_id, @@ -163,9 +169,7 @@ class Movie(ItemBase): self.kodidb.modify_countries(kodi_id, v.KODI_TYPE_MOVIE, countries) self.kodidb.modify_genres(kodi_id, v.KODI_TYPE_MOVIE, genres) - self.kodidb.modify_artwork(api.artwork(), - kodi_id, - v.KODI_TYPE_MOVIE) + self.kodidb.modify_streams(file_id, api.mediastreams(), runtime) self.kodidb.modify_studios(kodi_id, v.KODI_TYPE_MOVIE, studios) tags = [section_name] diff --git a/resources/lib/itemtypes/tvshows.py b/resources/lib/itemtypes/tvshows.py index 47663cc7..596981e6 100644 --- a/resources/lib/itemtypes/tvshows.py +++ b/resources/lib/itemtypes/tvshows.py @@ -183,6 +183,9 @@ class Show(ItemBase, TvShowMixin): self.kodidb.modify_people(kodi_id, v.KODI_TYPE_SHOW, api.people_list()) + self.kodidb.modify_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_SHOW) # Update the tvshow entry self.kodidb.update_show(api.title(), api.plot(), @@ -220,6 +223,9 @@ class Show(ItemBase, TvShowMixin): self.kodidb.add_people(kodi_id, v.KODI_TYPE_SHOW, api.people_list()) + self.kodidb.add_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_SHOW) # Create the tvshow entry self.kodidb.add_show(kodi_id, api.title(), @@ -233,9 +239,6 @@ class Show(ItemBase, TvShowMixin): studio, api.sorttitle()) self.kodidb.modify_genres(kodi_id, v.KODI_TYPE_SHOW, genres) - self.kodidb.modify_artwork(api.artwork(), - kodi_id, - v.KODI_TYPE_SHOW) # Process studios self.kodidb.modify_studios(kodi_id, v.KODI_TYPE_SHOW, studios) # Process tags: view, PMS collection tags @@ -263,6 +266,11 @@ class Season(ItemBase, TvShowMixin): LOG.error('Error getting plex_id for season, skipping: %s', xml.attrib) return + season = self.plexdb.season(plex_id) + if not season: + update_item = False + else: + update_item = True show_id = api.parent_id() show = self.plexdb.show(show_id) if not show: @@ -280,10 +288,16 @@ class Season(ItemBase, TvShowMixin): LOG.error('Still could not find parent tv show %s', show_id) return parent_id = show['kodi_id'] - kodi_id = self.kodidb.add_season(parent_id, api.season_number()) - self.kodidb.modify_artwork(api.artwork(), - kodi_id, - v.KODI_TYPE_SEASON) + if update_item: + kodi_id = season['kodi_id'] + self.kodidb.modify_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_SEASON) + else: + kodi_id = self.kodidb.add_season(parent_id, api.season_number()) + self.kodidb.add_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_SEASON) self.plexdb.add_season(plex_id=plex_id, checksum=api.checksum(), section_id=section_id, @@ -423,6 +437,9 @@ class Episode(ItemBase, TvShowMixin): self.kodidb.modify_people(kodi_id, v.KODI_TYPE_EPISODE, api.people_list()) + self.kodidb.modify_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_EPISODE) self.kodidb.update_episode(api.title(), api.plot(), ratingid, @@ -465,6 +482,9 @@ class Episode(ItemBase, TvShowMixin): self.kodidb.add_people(kodi_id, v.KODI_TYPE_EPISODE, api.people_list()) + self.kodidb.add_artwork(api.artwork(), + kodi_id, + v.KODI_TYPE_EPISODE) self.kodidb.add_episode(kodi_id, kodi_fileid, api.title(), @@ -485,9 +505,6 @@ class Episode(ItemBase, TvShowMixin): parent_id, userdata['UserRating']) - self.kodidb.modify_artwork(api.artwork(), - kodi_id, - v.KODI_TYPE_EPISODE) streams = api.mediastreams() self.kodidb.modify_streams(kodi_fileid, streams, api.runtime()) self.kodidb.set_resume(kodi_fileid, diff --git a/resources/lib/kodi_db/common.py b/resources/lib/kodi_db/common.py index 53300154..52042150 100644 --- a/resources/lib/kodi_db/common.py +++ b/resources/lib/kodi_db/common.py @@ -43,6 +43,24 @@ class KodiDBBase(object): self.cursor.execute('SELECT url FROM art WHERE type == ?', (kodi_type, ))) + def add_artwork(self, artworks, kodi_id, kodi_type): + """ + Pass in an artworks dict (see PlexAPI) to set an items artwork. + """ + for kodi_art, url in artworks.iteritems(): + self.add_art(url, kodi_id, kodi_type, kodi_art) + + def add_art(self, url, kodi_id, kodi_type, kodi_art): + """ + Adds or modifies the artwork of kind kodi_art (e.g. 'poster') in the + Kodi art table for item kodi_id/kodi_type. Will also cache everything + except actor portraits. + """ + self.cursor.execute(''' + INSERT INTO art(media_id, media_type, type, url) + VALUES (?, ?, ?, ?) + ''', (kodi_id, kodi_type, kodi_art, url)) + def modify_artwork(self, artworks, kodi_id, kodi_type): """ Pass in an artworks dict (see PlexAPI) to set an items artwork. diff --git a/resources/lib/kodi_db/video.py b/resources/lib/kodi_db/video.py index 3d8cf766..f984bcb4 100644 --- a/resources/lib/kodi_db/video.py +++ b/resources/lib/kodi_db/video.py @@ -725,17 +725,12 @@ class KodiVideoDB(common.KodiDBBase): 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('SELECT idSeason FROM seasons WHERE idShow = ? AND season = ?', - (showid, seasonnumber,)) - try: - seasonid = self.cursor.fetchone()[0] - except TypeError: - self.cursor.execute("SELECT COALESCE(MAX(idSeason),0) FROM seasons") - seasonid = self.cursor.fetchone()[0] + 1 - self.cursor.execute(''' - INSERT INTO seasons(idSeason, idShow, season) - VALUES (?, ?, ?) - ''', (seasonid, showid, seasonnumber)) + self.cursor.execute("SELECT COALESCE(MAX(idSeason),0) FROM seasons") + seasonid = self.cursor.fetchone()[0] + 1 + self.cursor.execute(''' + INSERT INTO seasons(idSeason, idShow, season) + VALUES (?, ?, ?) + ''', (seasonid, showid, seasonnumber)) return seasonid def add_uniqueid(self, *args):