mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
commit
fe039a36fd
2 changed files with 70 additions and 35 deletions
|
@ -598,6 +598,18 @@ class UpdateWorker(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb:
|
with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb:
|
||||||
|
default_args = (self.server, jellyfindb, kodidb, self.direct_path)
|
||||||
|
if kodidb.db_file == "video":
|
||||||
|
movies = Movies(*default_args)
|
||||||
|
tvshows = TVShows(*default_args)
|
||||||
|
musicvideos = MusicVideos(*default_args)
|
||||||
|
elif kodidb.db_file == "music":
|
||||||
|
music = Music(*default_args)
|
||||||
|
else:
|
||||||
|
# this should not happen
|
||||||
|
LOG.error('"{}" is not a valid Kodi library type.'.format(kodidb.db_file))
|
||||||
|
return
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -605,29 +617,28 @@ class UpdateWorker(threading.Thread):
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
default_args = (self.server, jellyfindb, kodidb, self.direct_path)
|
|
||||||
try:
|
try:
|
||||||
LOG.debug('{} - {}'.format(item['Type'], item['Name']))
|
LOG.debug('{} - {}'.format(item['Type'], item['Name']))
|
||||||
if item['Type'] == 'Movie':
|
if item['Type'] == 'Movie':
|
||||||
Movies(*default_args).movie(item)
|
movies.movie(item)
|
||||||
elif item['Type'] == 'BoxSet':
|
elif item['Type'] == 'BoxSet':
|
||||||
Movies(*default_args).boxset(item)
|
movies.boxset(item)
|
||||||
elif item['Type'] == 'Series':
|
elif item['Type'] == 'Series':
|
||||||
TVShows(*default_args).tvshow(item)
|
tvshows.tvshow(item)
|
||||||
elif item['Type'] == 'Season':
|
elif item['Type'] == 'Season':
|
||||||
TVShows(*default_args).season(item)
|
tvshows.season(item)
|
||||||
elif item['Type'] == 'Episode':
|
elif item['Type'] == 'Episode':
|
||||||
TVShows(*default_args).episode(item)
|
tvshows.episode(item)
|
||||||
elif item['Type'] == 'MusicVideo':
|
elif item['Type'] == 'MusicVideo':
|
||||||
MusicVideos(*default_args).musicvideo(item)
|
musicvideos.musicvideo(item)
|
||||||
elif item['Type'] == 'MusicAlbum':
|
elif item['Type'] == 'MusicAlbum':
|
||||||
Music(*default_args).album(item)
|
music.album(item)
|
||||||
elif item['Type'] == 'MusicArtist':
|
elif item['Type'] == 'MusicArtist':
|
||||||
Music(*default_args).artist(item)
|
music.artist(item)
|
||||||
elif item['Type'] == 'AlbumArtist':
|
elif item['Type'] == 'AlbumArtist':
|
||||||
Music(*default_args).albumartist(item)
|
music.albumartist(item)
|
||||||
elif item['Type'] == 'Audio':
|
elif item['Type'] == 'Audio':
|
||||||
Music(*default_args).song(item)
|
music.song(item)
|
||||||
|
|
||||||
if self.notify:
|
if self.notify:
|
||||||
self.notify_output.put((item['Type'], api.API(item).get_naming()))
|
self.notify_output.put((item['Type'], api.API(item).get_naming()))
|
||||||
|
@ -663,6 +674,17 @@ class UserDataWorker(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb:
|
with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb:
|
||||||
|
default_args = (self.server, jellyfindb, kodidb, self.direct_path)
|
||||||
|
if kodidb.db_file == "video":
|
||||||
|
movies = Movies(*default_args)
|
||||||
|
tvshows = TVShows(*default_args)
|
||||||
|
elif kodidb.db_file == "music":
|
||||||
|
music = Music(*default_args)
|
||||||
|
else:
|
||||||
|
# this should not happen
|
||||||
|
LOG.error('"{}" is not a valid Kodi library type.'.format(kodidb.db_file))
|
||||||
|
return
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -670,20 +692,19 @@ class UserDataWorker(threading.Thread):
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
default_args = (self.server, jellyfindb, kodidb, self.direct_path)
|
|
||||||
try:
|
try:
|
||||||
if item['Type'] == 'Movie':
|
if item['Type'] == 'Movie':
|
||||||
Movies(*default_args).userdata(item)
|
movies.userdata(item)
|
||||||
elif item['Type'] in ['Series', 'Season', 'Episode']:
|
elif item['Type'] in ['Series', 'Season', 'Episode']:
|
||||||
TVShows(*default_args).userdata(item)
|
tvshows.userdata(item)
|
||||||
elif item['Type'] == 'MusicAlbum':
|
elif item['Type'] == 'MusicAlbum':
|
||||||
Music(*default_args).album(item)
|
music.album(item)
|
||||||
elif item['Type'] == 'MusicArtist':
|
elif item['Type'] == 'MusicArtist':
|
||||||
Music(*default_args).artist(item)
|
music.artist(item)
|
||||||
elif item['Type'] == 'AlbumArtist':
|
elif item['Type'] == 'AlbumArtist':
|
||||||
Music(*default_args).albumartist(item)
|
music.albumartist(item)
|
||||||
elif item['Type'] == 'Audio':
|
elif item['Type'] == 'Audio':
|
||||||
Music(*default_args).userdata(item)
|
music.userdata(item)
|
||||||
except LibraryException as error:
|
except LibraryException as error:
|
||||||
if error.status == 'StopCalled':
|
if error.status == 'StopCalled':
|
||||||
break
|
break
|
||||||
|
@ -750,17 +771,30 @@ class RemovedWorker(threading.Thread):
|
||||||
|
|
||||||
is_done = False
|
is_done = False
|
||||||
|
|
||||||
def __init__(self, queue, lock, database, *args):
|
def __init__(self, queue, lock, database, server, direct_path):
|
||||||
|
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.lock = lock
|
self.lock = lock
|
||||||
self.database = Database(database)
|
self.database = Database(database)
|
||||||
self.args = args
|
self.server = server
|
||||||
|
self.direct_path = direct_path
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb:
|
with self.lock, self.database as kodidb, Database('jellyfin') as jellyfindb:
|
||||||
|
default_args = (self.server, jellyfindb, kodidb, self.direct_path)
|
||||||
|
if kodidb.db_file == "video":
|
||||||
|
movies = Movies(*default_args)
|
||||||
|
tvshows = TVShows(*default_args)
|
||||||
|
musicvideos = MusicVideos(*default_args)
|
||||||
|
elif kodidb.db_file == "music":
|
||||||
|
music = Music(*default_args)
|
||||||
|
else:
|
||||||
|
# this should not happen
|
||||||
|
LOG.error('"{}" is not a valid Kodi library type.'.format(kodidb.db_file))
|
||||||
|
return
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -769,13 +803,13 @@ class RemovedWorker(threading.Thread):
|
||||||
break
|
break
|
||||||
|
|
||||||
if item['Type'] == 'Movie':
|
if item['Type'] == 'Movie':
|
||||||
obj = Movies(self.args[0], jellyfindb, kodidb, self.args[1]).remove
|
obj = movies.remove
|
||||||
elif item['Type'] in ['Series', 'Season', 'Episode']:
|
elif item['Type'] in ['Series', 'Season', 'Episode']:
|
||||||
obj = TVShows(self.args[0], jellyfindb, kodidb, self.args[1]).remove
|
obj = tvshows.remove
|
||||||
elif item['Type'] in ['MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio']:
|
elif item['Type'] in ['MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio']:
|
||||||
obj = Music(self.args[0], jellyfindb, kodidb, self.args[1]).remove
|
obj = music.remove
|
||||||
elif item['Type'] == 'MusicVideo':
|
elif item['Type'] == 'MusicVideo':
|
||||||
obj = MusicVideos(self.args[0], jellyfindb, kodidb, self.args[1]).remove
|
obj = musicvideos.remove
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj(item['Id'])
|
obj(item['Id'])
|
||||||
|
@ -784,7 +818,7 @@ class RemovedWorker(threading.Thread):
|
||||||
break
|
break
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
LOG.exception(error)
|
LOG.exception(error)
|
||||||
|
finally:
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
if window('jellyfin_should_stop.bool'):
|
if window('jellyfin_should_stop.bool'):
|
||||||
|
|
|
@ -160,22 +160,23 @@ class Kodi(object):
|
||||||
self.cursor.execute(QU.add_person, args)
|
self.cursor.execute(QU.add_person, args)
|
||||||
return self.cursor.lastrowid
|
return self.cursor.lastrowid
|
||||||
|
|
||||||
def _get_person(self, *args):
|
def _get_person(self, name):
|
||||||
'''Retrieve person from the database, or add them if they don't exist
|
'''Retrieve person from the database, or add them if they don't exist
|
||||||
'''
|
'''
|
||||||
resp = self.cursor.execute(QU.get_person, args).fetchone()
|
resp = self.cursor.execute(QU.get_person, (name,)).fetchone()
|
||||||
if resp is not None:
|
if resp is not None:
|
||||||
return resp[0]
|
return resp[0]
|
||||||
else:
|
else:
|
||||||
return self.add_person(*args)
|
return self.add_person(name)
|
||||||
|
|
||||||
def get_person(self, *args):
|
def get_person(self, name):
|
||||||
'''Retrieve person from cache, else forward to db query
|
'''Retrieve person from cache, else forward to db query
|
||||||
'''
|
'''
|
||||||
person_id = self._people_cache.get(args)
|
if name in self._people_cache:
|
||||||
if not person_id:
|
return self._people_cache[name]
|
||||||
person_id = self._get_person(*args)
|
else:
|
||||||
self._people_cache[args] = person_id
|
person_id = self._get_person(name)
|
||||||
|
self._people_cache[name] = person_id
|
||||||
return person_id
|
return person_id
|
||||||
|
|
||||||
def add_genres(self, genres, *args):
|
def add_genres(self, genres, *args):
|
||||||
|
|
Loading…
Reference in a new issue