Speed up sync with dedicated add_artwork method

This commit is contained in:
croneter 2018-11-09 07:56:10 +01:00
parent 096af4dc7c
commit 463d0540a4
4 changed files with 58 additions and 24 deletions

View file

@ -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]

View file

@ -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())
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,

View file

@ -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.

View file

@ -725,11 +725,6 @@ 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('''