Greatly speed up sync with dedicated add_people method

This commit is contained in:
croneter 2018-11-08 21:40:19 +01:00
parent a16eae143a
commit 5f57b0af5f
3 changed files with 53 additions and 9 deletions

View file

@ -108,6 +108,9 @@ class Movie(ItemBase):
else: else:
self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_MOVIE) self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_MOVIE)
uniqueid = -1 uniqueid = -1
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_MOVIE,
api.people_list())
else: else:
LOG.info("ADD movie plex_id: %s - %s", plex_id, title) LOG.info("ADD movie plex_id: %s - %s", plex_id, title)
rating_id = self.kodidb.get_ratingid(kodi_id, rating_id = self.kodidb.get_ratingid(kodi_id,
@ -128,6 +131,9 @@ class Movie(ItemBase):
"imdb") "imdb")
else: else:
uniqueid = -1 uniqueid = -1
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_MOVIE,
api.people_list())
# Update Kodi's main entry # Update Kodi's main entry
self.kodidb.add_movie(kodi_id, self.kodidb.add_movie(kodi_id,
@ -156,9 +162,6 @@ class Movie(ItemBase):
userdata['UserRating']) userdata['UserRating'])
self.kodidb.modify_countries(kodi_id, v.KODI_TYPE_MOVIE, countries) self.kodidb.modify_countries(kodi_id, v.KODI_TYPE_MOVIE, countries)
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_MOVIE,
api.people_list())
self.kodidb.modify_genres(kodi_id, v.KODI_TYPE_MOVIE, genres) self.kodidb.modify_genres(kodi_id, v.KODI_TYPE_MOVIE, genres)
self.kodidb.modify_artwork(api.artwork(), self.kodidb.modify_artwork(api.artwork(),
kodi_id, kodi_id,

View file

@ -180,6 +180,9 @@ class Show(ItemBase, TvShowMixin):
else: else:
self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_SHOW) self.kodidb.remove_uniqueid(kodi_id, v.KODI_TYPE_SHOW)
uniqueid = -1 uniqueid = -1
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_SHOW,
api.people_list())
# Update the tvshow entry # Update the tvshow entry
self.kodidb.update_show(api.title(), self.kodidb.update_show(api.title(),
api.plot(), api.plot(),
@ -214,6 +217,9 @@ class Show(ItemBase, TvShowMixin):
"unknown") "unknown")
else: else:
uniqueid = -1 uniqueid = -1
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_SHOW,
api.people_list())
# Create the tvshow entry # Create the tvshow entry
self.kodidb.add_show(kodi_id, self.kodidb.add_show(kodi_id,
api.title(), api.title(),
@ -226,9 +232,6 @@ class Show(ItemBase, TvShowMixin):
api.content_rating(), api.content_rating(),
studio, studio,
api.sorttitle()) api.sorttitle())
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_SHOW,
api.people_list())
self.kodidb.modify_genres(kodi_id, v.KODI_TYPE_SHOW, genres) self.kodidb.modify_genres(kodi_id, v.KODI_TYPE_SHOW, genres)
self.kodidb.modify_artwork(api.artwork(), self.kodidb.modify_artwork(api.artwork(),
kodi_id, kodi_id,
@ -417,6 +420,9 @@ class Episode(ItemBase, TvShowMixin):
api.provider('tvdb'), api.provider('tvdb'),
"tvdb", "tvdb",
uniqueid) uniqueid)
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_EPISODE,
api.people_list())
self.kodidb.update_episode(api.title(), self.kodidb.update_episode(api.title(),
api.plot(), api.plot(),
ratingid, ratingid,
@ -456,6 +462,9 @@ class Episode(ItemBase, TvShowMixin):
v.KODI_TYPE_EPISODE, v.KODI_TYPE_EPISODE,
api.provider('tvdb'), api.provider('tvdb'),
"tvdb") "tvdb")
self.kodidb.add_people(kodi_id,
v.KODI_TYPE_EPISODE,
api.people_list())
self.kodidb.add_episode(kodi_id, self.kodidb.add_episode(kodi_id,
kodi_fileid, kodi_fileid,
api.title(), api.title(),
@ -476,9 +485,6 @@ class Episode(ItemBase, TvShowMixin):
parent_id, parent_id,
userdata['UserRating']) userdata['UserRating'])
self.kodidb.modify_people(kodi_id,
v.KODI_TYPE_EPISODE,
api.people_list())
self.kodidb.modify_artwork(api.artwork(), self.kodidb.modify_artwork(api.artwork(),
kodi_id, kodi_id,
v.KODI_TYPE_EPISODE) v.KODI_TYPE_EPISODE)

View file

@ -324,6 +324,41 @@ class KodiVideoDB(common.KodiDBBase):
'tag', 'tag',
'tag_id') 'tag_id')
def add_people(self, kodi_id, kodi_type, people):
"""
Makes sure that actors, directors and writers are recorded correctly
for the elmement kodi_id, kodi_type.
Will also delete a freshly orphaned actor entry.
"""
for kind, people_list in people.iteritems():
self._add_people_kind(kodi_id, kodi_type, kind, people_list)
def _add_people_kind(self, kodi_id, kodi_type, kind, people_list):
# Save new people to Kodi DB by iterating over the remaining entries
if kind == 'actor':
for person in people_list:
# Make sure the person entry in table actor exists
actor_id = self._get_actor_id(person[0], art_url=person[1])
# Link the person with the media element
try:
self.cursor.execute('INSERT INTO actor_link VALUES (?, ?, ?, ?, ?)',
(actor_id, kodi_id, kodi_type,
person[2], person[3]))
except IntegrityError:
# With Kodi, an actor may have only one role, unlike Plex
pass
else:
for person in people_list:
# Make sure the person entry in table actor exists:
actor_id = self._get_actor_id(person[0])
# Link the person with the media element
try:
self.cursor.execute('INSERT INTO %s_link VALUES (?, ?, ?)' % kind,
(actor_id, kodi_id, kodi_type))
except IntegrityError:
# Again, Kodi may have only one person assigned to a role
pass
def modify_people(self, kodi_id, kodi_type, people=None): def modify_people(self, kodi_id, kodi_type, people=None):
""" """
Makes sure that actors, directors and writers are recorded correctly Makes sure that actors, directors and writers are recorded correctly