Fix deleting entire library sections

This commit is contained in:
croneter 2018-11-25 20:15:38 +01:00
parent 90e13cb8ee
commit 697b66167c
3 changed files with 19 additions and 4 deletions

View file

@ -32,7 +32,7 @@ class KodiDBBase(object):
return False return False
self.kodiconn.commit() self.kodiconn.commit()
self.kodiconn.close() self.kodiconn.close()
if self._texture_db: if self.artconn:
self.artconn.commit() self.artconn.commit()
self.artconn.close() self.artconn.close()

View file

@ -214,11 +214,12 @@ def delete_sections(old_sections):
with PlexDB() as plexdb: with PlexDB() as plexdb:
old_sections = [plexdb.section(x) for x in old_sections] old_sections = [plexdb.section(x) for x in old_sections]
LOG.info("Removing entire Plex library sections: %s", old_sections) LOG.info("Removing entire Plex library sections: %s", old_sections)
with kodi_db.KodiVideoDB() as kodidb: with kodi_db.KodiVideoDB(texture_db=True) as kodidb:
for section in old_sections: for section in old_sections:
if section[2] == v.KODI_TYPE_PHOTO: if section[2] == v.KODI_TYPE_PHOTO:
# not synced # not synced
plexdb.remove_section(section[0]) plexdb.remove_section(section[0])
continue
elif section[2] == v.KODI_TYPE_MOVIE: elif section[2] == v.KODI_TYPE_MOVIE:
video_library_update = True video_library_update = True
context = itemtypes.Movie(None, context = itemtypes.Movie(None,
@ -229,14 +230,23 @@ def delete_sections(old_sections):
context = itemtypes.Show(None, context = itemtypes.Show(None,
plexdb=plexdb, plexdb=plexdb,
kodidb=kodidb) kodidb=kodidb)
with kodi_db.KodiMusicDB() as kodidb: else:
continue
for plex_id in plexdb.plexid_by_sectionid(section[0], section[2]):
context.remove(plex_id)
# Only remove Plex entry if we've removed all items first
plexdb.remove_section(section[0])
with kodi_db.KodiMusicDB(texture_db=True) as kodidb:
for section in old_sections: for section in old_sections:
if section[2] == v.KODI_TYPE_ARTIST: if section[2] == v.KODI_TYPE_ARTIST:
music_library_update = True music_library_update = True
context = itemtypes.Artist(None, context = itemtypes.Artist(None,
plexdb=plexdb, plexdb=plexdb,
kodidb=kodidb) kodidb=kodidb)
for plex_id in plexdb.plexid_by_section(section[0]): else:
continue
for plex_id in plexdb.plexid_by_sectionid(section[0], section[2]):
context.remove(plex_id) context.remove(plex_id)
# Only remove Plex entry if we've removed all items first # Only remove Plex entry if we've removed all items first
plexdb.remove_section(section[0]) plexdb.remove_section(section[0])

View file

@ -143,6 +143,11 @@ class PlexDBBase(object):
self.cursor.execute('UPDATE %s SET fanart_synced = 1 WHERE plex_id = ?' % plex_type, self.cursor.execute('UPDATE %s SET fanart_synced = 1 WHERE plex_id = ?' % plex_type,
(plex_id, )) (plex_id, ))
def plexid_by_sectionid(self, section_id, plex_type):
return (x[0] for x in
self.cursor.execute('SELECT plex_id FROM %s WHERE section_id = ?' % plex_type,
(section_id, )))
def initialize(): def initialize():
""" """