Delete items of a removed Plex library
This commit is contained in:
parent
16e6fc5ca4
commit
86434bab34
2 changed files with 44 additions and 6 deletions
|
@ -847,17 +847,39 @@ class LibrarySync(Thread):
|
||||||
# Save total
|
# Save total
|
||||||
window('Plex.nodes.total', str(totalnodes))
|
window('Plex.nodes.total', str(totalnodes))
|
||||||
|
|
||||||
# Reopen DB connection to ensure that changes were commited before
|
# Get rid of old items (view has been deleted on Plex side)
|
||||||
with plexdb.Get_Plex_DB() as plex_db:
|
if self.old_views:
|
||||||
log.info("Removing views: %s" % self.old_views)
|
self.delete_views()
|
||||||
for view in self.old_views:
|
|
||||||
plex_db.removeView(view)
|
|
||||||
# update views for all:
|
# update views for all:
|
||||||
|
with plexdb.Get_Plex_DB() as plex_db:
|
||||||
self.views = plex_db.getAllViewInfo()
|
self.views = plex_db.getAllViewInfo()
|
||||||
|
|
||||||
log.info("Finished processing views. Views saved: %s" % self.views)
|
log.info("Finished processing views. Views saved: %s" % self.views)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def delete_views(self):
|
||||||
|
log.info("Removing views: %s" % self.old_views)
|
||||||
|
delete_items = []
|
||||||
|
with plexdb.Get_Plex_DB() as plex_db:
|
||||||
|
for view in self.old_views:
|
||||||
|
plex_db.removeView(view)
|
||||||
|
delete_items.extend(plex_db.get_items_by_viewid(view))
|
||||||
|
# All video removals are the same, so pick Movies() class
|
||||||
|
with itemtypes.Movies() as movie:
|
||||||
|
for item in (i for i in delete_items
|
||||||
|
if i['kodi_type'] == v.KODI_TYPE_MOVIE):
|
||||||
|
movie.remove(item['plex_id'])
|
||||||
|
with itemtypes.TVShows() as tv:
|
||||||
|
for item in (i for i in delete_items
|
||||||
|
if i['kodi_type'] in (v.KODI_TYPE_EPISODE,
|
||||||
|
v.KODI_TYPE_SEASON,
|
||||||
|
v.KODI_TYPE_SHOW)):
|
||||||
|
tv.remove(item['plex_id'])
|
||||||
|
# And for the music DB:
|
||||||
|
with itemtypes.Music() as music:
|
||||||
|
for item in (i for i in delete_items
|
||||||
|
if i['kodi_type'] in v.KODI_AUDIOTYPES):
|
||||||
|
music.remove(item['plex_id'])
|
||||||
|
|
||||||
def GetUpdatelist(self, xml, itemType, method, viewName, viewId):
|
def GetUpdatelist(self, xml, itemType, method, viewName, viewId):
|
||||||
"""
|
"""
|
||||||
THIS METHOD NEEDS TO BE FAST! => e.g. no API calls
|
THIS METHOD NEEDS TO BE FAST! => e.g. no API calls
|
||||||
|
|
|
@ -159,6 +159,22 @@ class Plex_DB_Functions():
|
||||||
'''
|
'''
|
||||||
self.plexcursor.execute(query, (view_id,))
|
self.plexcursor.execute(query, (view_id,))
|
||||||
|
|
||||||
|
def get_items_by_viewid(self, view_id):
|
||||||
|
"""
|
||||||
|
Returns a list for view_id with one item like this:
|
||||||
|
{
|
||||||
|
'plex_id': xxx
|
||||||
|
'kodi_type': xxx
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
query = '''SELECT plex_id, kodi_type FROM plex WHERE view_id = ?'''
|
||||||
|
self.plexcursor.execute(query, (view_id, ))
|
||||||
|
rows = self.plexcursor.fetchall()
|
||||||
|
res = []
|
||||||
|
for row in rows:
|
||||||
|
res.append({'plex_id': row[0], 'kodi_type': row[1]})
|
||||||
|
return res
|
||||||
|
|
||||||
def getItem_byFileId(self, kodi_fileid, kodi_type):
|
def getItem_byFileId(self, kodi_fileid, kodi_type):
|
||||||
"""
|
"""
|
||||||
Returns plex_id for kodi_fileid and kodi_type
|
Returns plex_id for kodi_fileid and kodi_type
|
||||||
|
|
Loading…
Reference in a new issue