diff --git a/resources/lib/database/emby_db.py b/resources/lib/database/emby_db.py index 2f756800..60e34bc3 100644 --- a/resources/lib/database/emby_db.py +++ b/resources/lib/database/emby_db.py @@ -135,6 +135,11 @@ class EmbyDatabase(): return self.cursor.fetchall() + def get_views_by_media(self, *args): + self.cursor.execute(QU.get_views_by_media, args) + + return self.cursor.fetchall() + def get_items_by_media(self, *args): self.cursor.execute(QU.get_items_by_media, args) diff --git a/resources/lib/database/queries.py b/resources/lib/database/queries.py index e2af7445..529be85e 100644 --- a/resources/lib/database/queries.py +++ b/resources/lib/database/queries.py @@ -72,6 +72,10 @@ get_view = """ SELECT view_name, media_type get_views = """ SELECT * FROM view """ +get_views_by_media = """ SELECT * + FROM view + WHERE media_type = ? + """ get_items_by_media = """ SELECT emby_id FROM emby WHERE media_type = ? diff --git a/resources/lib/helper/wrapper.py b/resources/lib/helper/wrapper.py index 5859cea5..20bd3bcf 100644 --- a/resources/lib/helper/wrapper.py +++ b/resources/lib/helper/wrapper.py @@ -118,17 +118,26 @@ def library_check(): if view is None: ancestors = self.server['api'].get_ancestors(item['Id']) - + if not ancestors: - return + if item['Type'] == 'MusicArtist': - for ancestor in ancestors: - if ancestor['Type'] == 'CollectionFolder': + try: + views = self.emby_db.get_views_by_media('music')[0] + except Exception: + return - view = self.emby_db.get_view_name(ancestor['Id']) - view = {'Id': None, 'Name': None} if view is None else {'Name': ancestor['Name'], 'Id': ancestor['Id']} + view = {'Id': views[0], 'Name': views[1]} + else: # Grab the first music library + return + else: + for ancestor in ancestors: + if ancestor['Type'] == 'CollectionFolder': - break + view = self.emby_db.get_view_name(ancestor['Id']) + view = {'Id': None, 'Name': None} if view is None else {'Name': ancestor['Name'], 'Id': ancestor['Id']} + + break if view['Id'] not in [x.replace('Mixed:', "") for x in sync['Whitelist'] + sync['Libraries']]: LOG.info("Library %s is not synced. Skip update.", view['Id']) diff --git a/resources/lib/objects/music.py b/resources/lib/objects/music.py index 36fa34c8..b25e4779 100644 --- a/resources/lib/objects/music.py +++ b/resources/lib/objects/music.py @@ -193,9 +193,8 @@ class Music(KodiDb): temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] except TypeError: continue - else: - self.add_discography(*values(temp_obj, QU.update_discography_obj)) + self.add_discography(*values(temp_obj, QU.update_discography_obj)) self.emby_db.update_parent_id(*values(temp_obj, QUEM.update_parent_album_obj)) def artist_link(self, obj): @@ -212,15 +211,13 @@ class Music(KodiDb): try: temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] except TypeError: - continue - """ - self.artist(self.server['api'].get_item(temp_obj['Id']), artist_type="AlbumArtist") try: + self.artist(self.server['api'].get_item(temp_obj['Id']), library=None) temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] - except TypeError: + except Exception as error: + LOG.error(error) continue - """ else: self.update_artist_name(*values(temp_obj, QU.update_artist_name_obj)) @@ -367,11 +364,12 @@ class Music(KodiDb): try: temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] except TypeError: - self.artist(self.server['api'].get_item(temp_obj['Id'])) try: + self.artist(self.server['api'].get_item(temp_obj['Id']), library=None) temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] - except TypeError: + except Exception as error: + LOG.error(error) continue self.link(*values(temp_obj, QU.update_link_obj)) @@ -399,11 +397,12 @@ class Music(KodiDb): try: temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] except TypeError: - self.artist(self.server['api'].get_item(temp_obj['Id'])) try: + self.artist(self.server['api'].get_item(temp_obj['Id']), library=None) temp_obj['ArtistId'] = self.emby_db.get_item_by_id(*values(temp_obj, QUEM.get_item_obj))[0] - except TypeError: + except Exception as error: + LOG.error(error) continue self.link_song_artist(*values(temp_obj, QU.update_song_artist_obj))