From eb6891871dfd91ff9be9e75e308d2f38b330dad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Tue, 13 Jun 2023 13:44:23 +0200 Subject: [PATCH 1/2] Fix duplicate artist links INSERT OR REPLACE does not work when null values are provided as part of the unique index --- jellyfin_kodi/objects/kodi/kodi.py | 4 ++-- jellyfin_kodi/objects/kodi/queries.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/kodi.py b/jellyfin_kodi/objects/kodi/kodi.py index b96501492..1782425a7 100644 --- a/jellyfin_kodi/objects/kodi/kodi.py +++ b/jellyfin_kodi/objects/kodi/kodi.py @@ -147,8 +147,8 @@ def add_thumbnail(person_id, person, person_type): bulk_updates.setdefault(sql, []).append((person_id,) + args) elif person['Type'] == 'Artist': - sql = QU.update_link.replace("{LinkType}", 'actor_link') - bulk_updates.setdefault(sql, []).append((person_id,) + args) + sql = QU.insert_link_if_not_exists.replace("{LinkType}", 'actor_link') + bulk_updates.setdefault(sql, []).append((person_id,) + args + (person_id,) + args) add_thumbnail(person_id, person, person['Type']) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index f35f333b7..71459e2c5 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -395,6 +395,13 @@ INSERT OR REPLACE INTO {LinkType}(actor_id, media_id, media_type) VALUES (?, ?, ?) """ +# update_link does not work for actor_link as not all values from unique index are provided +# Resulting in duplicates +insert_link_if_not_exists = """ +INSERT INTO {LinkType}(actor_id, media_id, media_type) +SELECT ?, ?, ? +WHERE NOT EXISTS(SELECT 1 FROM {LinkType} WHERE actor_id = ? AND media_id = ? AND media_type = ?) +""" update_movie = """ UPDATE movie SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?, c06 = ?, From 9bfbe7eaa414166d78ff52f5be68fdad11023a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Tue, 13 Jun 2023 14:31:46 +0200 Subject: [PATCH 2/2] Fix: remove override of previously set libraryId and name Which caused new videos not to be added to library on automatic update --- jellyfin_kodi/objects/musicvideos.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/jellyfin_kodi/objects/musicvideos.py b/jellyfin_kodi/objects/musicvideos.py index 32f76967d..93cc7b607 100644 --- a/jellyfin_kodi/objects/musicvideos.py +++ b/jellyfin_kodi/objects/musicvideos.py @@ -86,8 +86,6 @@ def musicvideo(self, item, e_item): obj['Year'] = int(str(obj['Year'])[:4]) obj['Path'] = API.get_file_path(obj['Path']) - obj['LibraryId'] = self.library['Id'] - obj['LibraryName'] = self.library['Name'] obj['Genres'] = obj['Genres'] or [] obj['ArtistItems'] = obj['ArtistItems'] or [] obj['Studios'] = [API.validate_studio(studio) for studio in (obj['Studios'] or [])]