Cleanup code around removing libraries

This commit is contained in:
Matt 2020-03-28 23:25:13 -04:00
parent 97de6f9d11
commit aeca1a0049
3 changed files with 13 additions and 35 deletions

View File

@ -11,6 +11,7 @@ from kodi_six import xbmc
import downloader as server import downloader as server
import helper.xmls as xmls import helper.xmls as xmls
from objects import Movies, TVShows, MusicVideos, Music
from database import Database, get_sync, save_sync, jellyfin_db from database import Database, get_sync, save_sync, jellyfin_db
from helper import translate, settings, window, progress, dialog, LibraryException from helper import translate, settings, window, progress, dialog, LibraryException
from helper.utils import get_screensaver, set_screensaver from helper.utils import get_screensaver, set_screensaver
@ -261,7 +262,6 @@ class FullSync(object):
''' Process movies from a single library. ''' Process movies from a single library.
''' '''
Movies = self.library.media['Movies']
processed_ids = [] processed_ids = []
for items in server.get_items(library['Id'], "Movie", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "Movie", False, self.sync['RestorePoint'].get('params')):
@ -305,7 +305,6 @@ class FullSync(object):
''' Process tvshows and episodes from a single library. ''' Process tvshows and episodes from a single library.
''' '''
TVShows = self.library.media['TVShows']
processed_ids = [] processed_ids = []
for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')):
@ -358,7 +357,6 @@ class FullSync(object):
''' Process musicvideos from a single library. ''' Process musicvideos from a single library.
''' '''
MusicVideos = self.library.media['MusicVideos']
processed_ids = [] processed_ids = []
for items in server.get_items(library['Id'], "MusicVideo", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library['Id'], "MusicVideo", False, self.sync['RestorePoint'].get('params')):
@ -401,8 +399,6 @@ class FullSync(object):
''' Process artists, album, songs from a single library. ''' Process artists, album, songs from a single library.
''' '''
Music = self.library.media['Music']
with self.library.music_database_lock: with self.library.music_database_lock:
with Database('music') as musicdb: with Database('music') as musicdb:
with Database('jellyfin') as jellyfindb: with Database('jellyfin') as jellyfindb:
@ -462,8 +458,6 @@ class FullSync(object):
''' Process all boxsets. ''' Process all boxsets.
''' '''
Movies = self.library.media['Movies']
for items in server.get_items(library_id, "BoxSet", False, self.sync['RestorePoint'].get('params')): for items in server.get_items(library_id, "BoxSet", False, self.sync['RestorePoint'].get('params')):
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
@ -483,8 +477,6 @@ class FullSync(object):
''' Delete all exisitng boxsets and re-add. ''' Delete all exisitng boxsets and re-add.
''' '''
Movies = self.library.media['Movies']
with self.video_database_locks() as (videodb, jellyfindb): with self.video_database_locks() as (videodb, jellyfindb):
obj = Movies(self.server, jellyfindb, videodb, self.direct_path) obj = Movies(self.server, jellyfindb, videodb, self.direct_path)
obj.boxsets_reset() obj.boxsets_reset()
@ -496,7 +488,6 @@ class FullSync(object):
''' Remove library by their id from the Kodi database. ''' Remove library by their id from the Kodi database.
''' '''
MEDIA = self.library.MEDIA
direct_path = self.library.direct_path direct_path = self.library.direct_path
with Database('jellyfin') as jellyfindb: with Database('jellyfin') as jellyfindb:
@ -536,16 +527,16 @@ class FullSync(object):
dialog.update(int((float(count) / float(len(items)) * 100)), heading="%s: %s" % (translate('addon_name'), library[0])) dialog.update(int((float(count) / float(len(items)) * 100)), heading="%s: %s" % (translate('addon_name'), library[0]))
count += 1 count += 1
else: else:
# from mcarlton: I'm not sure what triggers this. default_args = (self.server, jellyfindb, kodidb, direct_path)
# I've added and removed every media type except
# for music videos (because i don't have any) and
# can't find it, but I'm not comfortable
# removing it right now
LOG.info('Triggered the mystery function')
LOG.debug('Mystery function item type: {}'.format(items[0][1]))
obj = MEDIA[items[0][1]](self.server, jellyfindb, kodidb, direct_path).remove
for item in items: for item in items:
if item[1] in ('Series', 'Season', 'Episode'):
obj = TVShows(*default_args).remove
elif item[1] in ('Movie', 'BoxSet'):
obj = Movies(*default_args).remove
elif item[1] in ('MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio'):
obj = Music(*default_args).remove
elif item[1] == 'MusicVideo':
obj = MusicVideos(*default_args).remove
obj(item[0]) obj(item[0])
dialog.update(int((float(count) / float(len(items)) * 100)), heading="%s: %s" % (translate('addon_name'), library[0])) dialog.update(int((float(count) / float(len(items)) * 100)), heading="%s: %s" % (translate('addon_name'), library[0]))
@ -560,6 +551,7 @@ class FullSync(object):
self.sync['Whitelist'].remove('Mixed:%s' % library_id) self.sync['Whitelist'].remove('Mixed:%s' % library_id)
save_sync(self.sync) save_sync(self.sync)
xbmc.executebuiltin('ReloadSkin()')
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):

View File

@ -25,18 +25,6 @@ from jellyfin import Jellyfin
LOG = logging.getLogger("JELLYFIN." + __name__) LOG = logging.getLogger("JELLYFIN." + __name__)
LIMIT = int(settings('limitIndex') or 15) LIMIT = int(settings('limitIndex') or 15)
DTHREADS = int(settings('limitThreads') or 3) DTHREADS = int(settings('limitThreads') or 3)
MEDIA = {
'Movie': Movies,
'BoxSet': Movies,
'MusicVideo': MusicVideos,
'Series': TVShows,
'Season': TVShows,
'Episode': TVShows,
'MusicAlbum': Music,
'MusicArtist': Music,
'AlbumArtist': Music,
'Audio': Music
}
################################################################################################## ##################################################################################################
@ -53,9 +41,6 @@ class Library(threading.Thread):
def __init__(self, monitor): def __init__(self, monitor):
self.media = {'Movies': Movies, 'TVShows': TVShows, 'MusicVideos': MusicVideos, 'Music': Music}
self.MEDIA = MEDIA
self.direct_path = settings('useDirectPaths') == "1" self.direct_path = settings('useDirectPaths') == "1"
self.progress_display = int(settings('syncProgress') or 50) self.progress_display = int(settings('syncProgress') or 50)
self.monitor = monitor self.monitor = monitor
@ -633,7 +618,7 @@ class UpdateWorker(threading.Thread):
elif item['Type'] == 'MusicArtist': elif item['Type'] == 'MusicArtist':
obj = Music(*default_args).artist obj = Music(*default_args).artist
elif item['Type'] == 'AlbumArtist': elif item['Type'] == 'AlbumArtist':
obj = Music(*default_args).albumartist obj = Music(s*default_args).albumartist
elif item['Type'] == 'Audio': elif item['Type'] == 'Audio':
obj = Music(*default_args).song obj = Music(*default_args).song

View File

@ -46,6 +46,7 @@ class Monitor(xbmc.Monitor):
LOG.info("-->[ kodi scan/%s ]", library) LOG.info("-->[ kodi scan/%s ]", library)
def onScanFinished(self, library): def onScanFinished(self, library):
xbmc.executebuiltin("ReloadSkin()")
LOG.info("--<[ kodi scan/%s ]", library) LOG.info("--<[ kodi scan/%s ]", library)
def onNotification(self, sender, method, data): def onNotification(self, sender, method, data):