From 437df7724623d7975485fa63e52ddc8277c9b21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Wed, 3 May 2023 00:00:11 +0200 Subject: [PATCH 01/19] WIP --- jellyfin_kodi/objects/kodi/queries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index f35f333b..1e652381 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -334,12 +334,12 @@ VALUES (?, ?, ?) """ add_episode = """ INSERT INTO episode(idEpisode, idFile, c00, c01, c03, c04, c05, c09, c10, c12, c13, c14, - idShow, c15, c16, idSeason) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + idShow, c15, c16, idSeason, c18, c20) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """ add_episode_obj = ["{EpisodeId}", "{FileId}", "{Title}", "{Plot}", "{RatingId}", "{Writers}", "{Premiere}", "{Runtime}", "{Directors}", "{Season}", "{Index}", "{Title}", "{ShowId}", "{AirsBeforeSeason}", - "{AirsBeforeEpisode}", "{SeasonId}"] + "{AirsBeforeEpisode}", "{SeasonId}", "{Filename}", "{Unique}"] add_art = """ INSERT INTO art(media_id, media_type, type, url) VALUES (?, ?, ?, ?) From fcda2ec04318d38529aa6beb7a40e988c209f77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Thu, 4 May 2023 20:07:33 +0200 Subject: [PATCH 02/19] Feat: added idParentPath to tvshows --- jellyfin_kodi/objects/kodi/queries.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index 1e652381..f80bc7c3 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -348,14 +348,14 @@ VALUES (?, ?, ?, ?) update_path = """ UPDATE path -SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ? +SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?, idParentPath = ? WHERE idPath = ? """ -update_path_movie_obj = ["{Path}", "movies", "metadata.local", 1, "{PathId}"] -update_path_toptvshow_obj = ["{TopLevel}", "tvshows", "metadata.local", 1, "{TopPathId}"] -update_path_tvshow_obj = ["{Path}", None, None, 1, "{PathId}"] -update_path_episode_obj = ["{Path}", None, None, 1, "{PathId}"] -update_path_mvideo_obj = ["{Path}", "musicvideos", None, 1, "{PathId}"] +update_path_movie_obj = ["{Path}", "movies", "metadata.local", 1, None, "{PathId}"] +update_path_toptvshow_obj = ["{TopLevel}", "tvshows", "metadata.local", 1, None, "{TopPathId}"] +update_path_tvshow_obj = ["{Path}", None, None, 1, "{TopPathId}", "{PathId}"] +update_path_episode_obj = ["{Path}", None, None, 1, None, "{PathId}"] +update_path_mvideo_obj = ["{Path}", "musicvideos", None, 1, None, "{PathId}"] update_file = """ UPDATE files SET idPath = ?, strFilename = ?, dateAdded = ? From 5b0fecf50c05ea0720f06fb5755f4b85efac2734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Fri, 5 May 2023 13:18:37 +0200 Subject: [PATCH 03/19] WIP: other path update approach Use jellyfin db to determine parent path id --- jellyfin_kodi/database/jellyfin_db.py | 18 ++++++++++++++++++ jellyfin_kodi/database/queries.py | 23 +++++++++++++++++++++++ jellyfin_kodi/objects/tvshows.py | 6 ++++++ 3 files changed, 47 insertions(+) diff --git a/jellyfin_kodi/database/jellyfin_db.py b/jellyfin_kodi/database/jellyfin_db.py index a518b830..c7a0ba36 100644 --- a/jellyfin_kodi/database/jellyfin_db.py +++ b/jellyfin_kodi/database/jellyfin_db.py @@ -71,6 +71,24 @@ class JellyfinDatabase(): except TypeError: return + def get_season_kodi_parent_path_id(self, *args): + + try: + self.cursor.execute(QU.get_season_kodi_parent_path_id_obj, args) + + return self.cursor.fetchone()[0] + except TypeError: + return + + def get_episode_kodi_parent_path_id(self, *args): + + try: + self.cursor.execute(QU.get_episode_kodi_parent_path_id_obj, args) + + return self.cursor.fetchone()[0] + except TypeError: + return + def get_full_item_by_kodi_id(self, *args): try: diff --git a/jellyfin_kodi/database/queries.py b/jellyfin_kodi/database/queries.py index e1c3eb69..36dc50ba 100644 --- a/jellyfin_kodi/database/queries.py +++ b/jellyfin_kodi/database/queries.py @@ -166,3 +166,26 @@ WHERE jellyfin_parent_id = ? delete_version = """ DELETE FROM version """ +get_season_kodi_parent_path_id = """ +SELECT sh.kodi_pathid +FROM jellyfin s +JOIN jellyfin sh +ON s.parent_id = sh.kodi_id +WHERE s.media_type = ? +AND sh.media_type = ? +AND s.id = ? +""" +get_season_kodi_parent_path_id_obj = ["season", "tvshow", "{SeasonId}"] +get_episode_kodi_parent_path_id = """ +SELECT sh.kodi_pathid +FROM jellyfin e +JOIN jellyfin s +ON e.parent_id = s.kodi_id +JOIN jellyfin sh +ON s.parent_id = sh.kodi_id +WHERE e.media_type = "episode" +AND s.media_type = "season" +AND sh.media_type = "tvshow" +AND e.kodi_fileid = 698; +""" +get_episode_kodi_parent_path_id = ["episode", "season", "tvshow", "{EpisodeId}"] \ No newline at end of file diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index 3b169e1b..33f06b75 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -116,6 +116,7 @@ class TVShows(KodiDb): self.tvshow_add(obj) self.link(*values(obj, QU.update_tvshow_link_obj)) + # Ne marche pas en mode update... self.update_path(*values(obj, QU.update_path_tvshow_obj)) self.add_tags(*values(obj, QU.add_tags_tvshow_obj)) self.add_people(*values(obj, QU.add_people_tvshow_obj)) @@ -152,6 +153,8 @@ class TVShows(KodiDb): season_id = self.get_season(*values(obj, QU.get_season_special_obj)) self.artwork.add(obj['Artwork'], season_id, "season") +# verifier ici + for season in season_episodes: for episodes in server.get_episode_by_season(season_episodes[season], season): @@ -259,6 +262,9 @@ class TVShows(KodiDb): obj = self.objects.map(item, 'Episode') update = True + LOG.debug("EPISODE item: [%s]", item) + LOG.debug("EPISODE e_item: [%s]", e_item) + if obj['Location'] == "Virtual": LOG.info("Skipping virtual episode %s: %s", obj['Title'], obj['Id']) From 0473c1eb7790209dd88c18f52f63b8ef6305ba81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Thu, 4 May 2023 20:07:33 +0200 Subject: [PATCH 04/19] Revert "Feat: added idParentPath to tvshows" This reverts commit 63d40810e85850642ad0b48e196b9a07cd379b7d. --- jellyfin_kodi/objects/kodi/queries.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index f80bc7c3..1e652381 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -348,14 +348,14 @@ VALUES (?, ?, ?, ?) update_path = """ UPDATE path -SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?, idParentPath = ? +SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ? WHERE idPath = ? """ -update_path_movie_obj = ["{Path}", "movies", "metadata.local", 1, None, "{PathId}"] -update_path_toptvshow_obj = ["{TopLevel}", "tvshows", "metadata.local", 1, None, "{TopPathId}"] -update_path_tvshow_obj = ["{Path}", None, None, 1, "{TopPathId}", "{PathId}"] -update_path_episode_obj = ["{Path}", None, None, 1, None, "{PathId}"] -update_path_mvideo_obj = ["{Path}", "musicvideos", None, 1, None, "{PathId}"] +update_path_movie_obj = ["{Path}", "movies", "metadata.local", 1, "{PathId}"] +update_path_toptvshow_obj = ["{TopLevel}", "tvshows", "metadata.local", 1, "{TopPathId}"] +update_path_tvshow_obj = ["{Path}", None, None, 1, "{PathId}"] +update_path_episode_obj = ["{Path}", None, None, 1, "{PathId}"] +update_path_mvideo_obj = ["{Path}", "musicvideos", None, 1, "{PathId}"] update_file = """ UPDATE files SET idPath = ?, strFilename = ?, dateAdded = ? From 1a3f3120577077ead334fdb1bba697bc59df283f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Fri, 5 May 2023 18:24:10 +0200 Subject: [PATCH 05/19] WIP: parent path id --- jellyfin_kodi/database/jellyfin_db.py | 11 +---------- jellyfin_kodi/database/queries.py | 21 ++++++--------------- jellyfin_kodi/objects/kodi/kodi.py | 3 +++ jellyfin_kodi/objects/kodi/queries.py | 5 +++++ jellyfin_kodi/objects/tvshows.py | 17 ++++++++++++++--- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/jellyfin_kodi/database/jellyfin_db.py b/jellyfin_kodi/database/jellyfin_db.py index c7a0ba36..0cbe9dd6 100644 --- a/jellyfin_kodi/database/jellyfin_db.py +++ b/jellyfin_kodi/database/jellyfin_db.py @@ -71,19 +71,10 @@ class JellyfinDatabase(): except TypeError: return - def get_season_kodi_parent_path_id(self, *args): - - try: - self.cursor.execute(QU.get_season_kodi_parent_path_id_obj, args) - - return self.cursor.fetchone()[0] - except TypeError: - return - def get_episode_kodi_parent_path_id(self, *args): try: - self.cursor.execute(QU.get_episode_kodi_parent_path_id_obj, args) + self.cursor.execute(QU.get_episode_kodi_parent_path_id, args) return self.cursor.fetchone()[0] except TypeError: diff --git a/jellyfin_kodi/database/queries.py b/jellyfin_kodi/database/queries.py index 36dc50ba..6136a50e 100644 --- a/jellyfin_kodi/database/queries.py +++ b/jellyfin_kodi/database/queries.py @@ -166,16 +166,7 @@ WHERE jellyfin_parent_id = ? delete_version = """ DELETE FROM version """ -get_season_kodi_parent_path_id = """ -SELECT sh.kodi_pathid -FROM jellyfin s -JOIN jellyfin sh -ON s.parent_id = sh.kodi_id -WHERE s.media_type = ? -AND sh.media_type = ? -AND s.id = ? -""" -get_season_kodi_parent_path_id_obj = ["season", "tvshow", "{SeasonId}"] + get_episode_kodi_parent_path_id = """ SELECT sh.kodi_pathid FROM jellyfin e @@ -183,9 +174,9 @@ JOIN jellyfin s ON e.parent_id = s.kodi_id JOIN jellyfin sh ON s.parent_id = sh.kodi_id -WHERE e.media_type = "episode" -AND s.media_type = "season" -AND sh.media_type = "tvshow" -AND e.kodi_fileid = 698; +WHERE e.media_type = ? +AND s.media_type = ? +AND sh.media_type = ? +AND e.jellyfin_id = ?; """ -get_episode_kodi_parent_path_id = ["episode", "season", "tvshow", "{EpisodeId}"] \ No newline at end of file +get_episode_kodi_parent_path_id_obj = ["episode", "season", "tvshow", "{Id}"] \ No newline at end of file diff --git a/jellyfin_kodi/objects/kodi/kodi.py b/jellyfin_kodi/objects/kodi/kodi.py index b9650149..09909a50 100644 --- a/jellyfin_kodi/objects/kodi/kodi.py +++ b/jellyfin_kodi/objects/kodi/kodi.py @@ -77,6 +77,9 @@ class Kodi(object): except TypeError: return + def update_path_parent_id(self, path_id, parent_path_id): + self.cursor.execute(QU.update_path_parent_id, (parent_path_id, path_id)) + def update_path(self, *args): self.cursor.execute(QU.update_path, args) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index 1e652381..e73a6bf3 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -345,6 +345,11 @@ INSERT INTO art(media_id, media_type, type, url) VALUES (?, ?, ?, ?) """ +update_path_parent_id = """ +UPDATE path +SET idParentPath = ? +where idPath = ? +""" update_path = """ UPDATE path diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index 33f06b75..36237f4b 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -116,7 +116,6 @@ class TVShows(KodiDb): self.tvshow_add(obj) self.link(*values(obj, QU.update_tvshow_link_obj)) - # Ne marche pas en mode update... self.update_path(*values(obj, QU.update_path_tvshow_obj)) self.add_tags(*values(obj, QU.add_tags_tvshow_obj)) self.add_people(*values(obj, QU.add_people_tvshow_obj)) @@ -153,8 +152,6 @@ class TVShows(KodiDb): season_id = self.get_season(*values(obj, QU.get_season_special_obj)) self.artwork.add(obj['Artwork'], season_id, "season") -# verifier ici - for season in season_episodes: for episodes in server.get_episode_by_season(season_episodes[season], season): @@ -180,6 +177,9 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_tvshow_obj)) LOG.debug("ADD tvshow [%s/%s/%s] %s: %s", obj['TopPathId'], obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) + # TODO: Greg + self.update_path_parent_id(obj['PathId'], obj['TopPathId']) + def tvshow_update(self, obj): ''' Update object to kodi. @@ -190,10 +190,15 @@ class TVShows(KodiDb): obj['Unique'] = self.get_unique_id(*values(obj, QU.get_unique_id_tvshow_obj)) self.update_unique_id(*values(obj, QU.update_unique_id_tvshow_obj)) + obj['TopPathId'] = self.get_path(obj['TopLevel']) + self.update(*values(obj, QU.update_tvshow_obj)) self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("UPDATE tvshow [%s/%s] %s: %s", obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) + # TODO: Greg + self.update_path_parent_id(obj['PathId'], obj['TopPathId']) + def get_path_filename(self, obj): ''' Get the path and build it into protocol://path @@ -383,6 +388,12 @@ class TVShows(KodiDb): return self.episode_add(obj) self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_episode_obj)) + + # TODO Greg + parentPathId = self.jellyfin_db.get_episode_kodi_parent_path_id(*values(obj, QUEM.get_episode_kodi_parent_path_id_obj)) + LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) + self.update_path_parent_id(obj['PathId'], parentPathId) + LOG.debug("ADD episode [%s/%s] %s: %s", obj['PathId'], obj['FileId'], obj['Id'], obj['Title']) def episode_update(self, obj): From 8de0a022b6a89d75526d317ebd7f45fff4bc4a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sat, 6 May 2023 09:59:09 +0200 Subject: [PATCH 06/19] Feat: Set mediaType and scrapper to all paths for movies and tvshows --- jellyfin_kodi/objects/kodi/queries.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index f35f333b..8764a963 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -353,9 +353,10 @@ WHERE idPath = ? """ update_path_movie_obj = ["{Path}", "movies", "metadata.local", 1, "{PathId}"] update_path_toptvshow_obj = ["{TopLevel}", "tvshows", "metadata.local", 1, "{TopPathId}"] -update_path_tvshow_obj = ["{Path}", None, None, 1, "{PathId}"] -update_path_episode_obj = ["{Path}", None, None, 1, "{PathId}"] -update_path_mvideo_obj = ["{Path}", "musicvideos", None, 1, "{PathId}"] +update_path_tvshow_obj = ["{Path}", "tvshows", "metadata.local", 1, "{PathId}"] +update_path_episode_obj = ["{Path}", "tvshows", "metadata.local", 1, "{PathId}"] +update_path_mvideo_obj = ["{Path}", "musicvideos", "metadata.local", 1, "{PathId}"] + update_file = """ UPDATE files SET idPath = ?, strFilename = ?, dateAdded = ? From da6a725b4d4b2aca4eb4b5baf50240b34abbc25b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 01:51:21 +0200 Subject: [PATCH 07/19] Remove TODO tags --- jellyfin_kodi/objects/tvshows.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index 36237f4b..fbcbc295 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -177,7 +177,6 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_tvshow_obj)) LOG.debug("ADD tvshow [%s/%s/%s] %s: %s", obj['TopPathId'], obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) - # TODO: Greg self.update_path_parent_id(obj['PathId'], obj['TopPathId']) def tvshow_update(self, obj): @@ -196,7 +195,6 @@ class TVShows(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("UPDATE tvshow [%s/%s] %s: %s", obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) - # TODO: Greg self.update_path_parent_id(obj['PathId'], obj['TopPathId']) def get_path_filename(self, obj): @@ -389,7 +387,6 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_episode_obj)) - # TODO Greg parentPathId = self.jellyfin_db.get_episode_kodi_parent_path_id(*values(obj, QUEM.get_episode_kodi_parent_path_id_obj)) LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) self.update_path_parent_id(obj['PathId'], parentPathId) From 5b14abb53f4cd4401fa38ccc1c0a7b226c68b94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 02:04:58 +0200 Subject: [PATCH 08/19] Set pathId to the episode --- jellyfin_kodi/objects/kodi/queries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index 817576a8..1be45489 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -334,12 +334,12 @@ VALUES (?, ?, ?) """ add_episode = """ INSERT INTO episode(idEpisode, idFile, c00, c01, c03, c04, c05, c09, c10, c12, c13, c14, - idShow, c15, c16, idSeason, c18, c20) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + idShow, c15, c16, idSeason, c18, c19, c20) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """ add_episode_obj = ["{EpisodeId}", "{FileId}", "{Title}", "{Plot}", "{RatingId}", "{Writers}", "{Premiere}", "{Runtime}", "{Directors}", "{Season}", "{Index}", "{Title}", "{ShowId}", "{AirsBeforeSeason}", - "{AirsBeforeEpisode}", "{SeasonId}", "{Filename}", "{Unique}"] + "{AirsBeforeEpisode}", "{SeasonId}", "{Filename}", "{PathId}", "{Unique}"] add_art = """ INSERT INTO art(media_id, media_type, type, url) VALUES (?, ?, ?, ?) From ff95157315a160bb9b6cef452a8012fb5026daae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 12:28:18 +0200 Subject: [PATCH 09/19] Set parent pathId only when in native mode Also do not set content and scrapper from path not being top paths --- jellyfin_kodi/objects/kodi/queries.py | 4 ++-- jellyfin_kodi/objects/tvshows.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index 1be45489..1216c17b 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -358,8 +358,8 @@ WHERE idPath = ? """ update_path_movie_obj = ["{Path}", "movies", "metadata.local", 1, "{PathId}"] update_path_toptvshow_obj = ["{TopLevel}", "tvshows", "metadata.local", 1, "{TopPathId}"] -update_path_tvshow_obj = ["{Path}", "tvshows", "metadata.local", 1, "{PathId}"] -update_path_episode_obj = ["{Path}", "tvshows", "metadata.local", 1, "{PathId}"] +update_path_tvshow_obj = ["{Path}", None, None, 1, "{PathId}"] +update_path_episode_obj = ["{Path}", None, None, 1, "{PathId}"] update_path_mvideo_obj = ["{Path}", "musicvideos", "metadata.local", 1, "{PathId}"] update_file = """ diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index fbcbc295..29706469 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -177,7 +177,8 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_tvshow_obj)) LOG.debug("ADD tvshow [%s/%s/%s] %s: %s", obj['TopPathId'], obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) - self.update_path_parent_id(obj['PathId'], obj['TopPathId']) + if self.direct_path: + self.update_path_parent_id(obj['PathId'], obj['TopPathId']) def tvshow_update(self, obj): @@ -195,7 +196,8 @@ class TVShows(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("UPDATE tvshow [%s/%s] %s: %s", obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) - self.update_path_parent_id(obj['PathId'], obj['TopPathId']) + if self.direct_path: + self.update_path_parent_id(obj['PathId'], obj['TopPathId']) def get_path_filename(self, obj): @@ -206,6 +208,9 @@ class TVShows(KodiDb): if '\\' in obj['Path']: obj['Path'] = "%s\\" % obj['Path'] obj['TopLevel'] = "%s\\" % dirname(dirname(obj['Path'])) + elif 'smb://' in obj['Path'] or 'nfs://' in obj['Path']: + obj['Path'] = "%s/" % obj['Path'] + obj['TopLevel'] = "%s/" % dirname(dirname(obj['Path'])) else: obj['Path'] = "%s/" % obj['Path'] obj['TopLevel'] = "plugin://plugin.video.jellyfin/" @@ -387,9 +392,10 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_episode_obj)) - parentPathId = self.jellyfin_db.get_episode_kodi_parent_path_id(*values(obj, QUEM.get_episode_kodi_parent_path_id_obj)) - LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) - self.update_path_parent_id(obj['PathId'], parentPathId) + if self.direct_path: + parentPathId = self.jellyfin_db.get_episode_kodi_parent_path_id(*values(obj, QUEM.get_episode_kodi_parent_path_id_obj)) + LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) + self.update_path_parent_id(obj['PathId'], parentPathId) LOG.debug("ADD episode [%s/%s] %s: %s", obj['PathId'], obj['FileId'], obj['Id'], obj['Title']) From e28a04128796ab91f027b723e8504e6836d2368b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 12:51:38 +0200 Subject: [PATCH 10/19] Set full path in episode --- jellyfin_kodi/objects/kodi/queries.py | 7 ++++--- jellyfin_kodi/objects/tvshows.py | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index 1216c17b..e9f1f7c9 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -339,7 +339,7 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """ add_episode_obj = ["{EpisodeId}", "{FileId}", "{Title}", "{Plot}", "{RatingId}", "{Writers}", "{Premiere}", "{Runtime}", "{Directors}", "{Season}", "{Index}", "{Title}", "{ShowId}", "{AirsBeforeSeason}", - "{AirsBeforeEpisode}", "{SeasonId}", "{Filename}", "{PathId}", "{Unique}"] + "{AirsBeforeEpisode}", "{SeasonId}", "{FullFilePath}", "{PathId}", "{Unique}"] add_art = """ INSERT INTO art(media_id, media_type, type, url) VALUES (?, ?, ?, ?) @@ -474,12 +474,13 @@ WHERE idSeason = ? update_episode = """ UPDATE episode SET c00 = ?, c01 = ?, c03 = ?, c04 = ?, c05 = ?, c09 = ?, c10 = ?, - c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?, idSeason = ?, idShow = ? + c12 = ?, c13 = ?, c14 = ?, c15 = ?, c16 = ?, idSeason = ?, idShow = ?, + c18 = ?, c19 = ?, c20 = ? WHERE idEpisode = ? """ update_episode_obj = ["{Title}", "{Plot}", "{RatingId}", "{Writers}", "{Premiere}", "{Runtime}", "{Directors}", "{Season}", "{Index}", "{Title}", "{AirsBeforeSeason}", "{AirsBeforeEpisode}", "{SeasonId}", - "{ShowId}", "{EpisodeId}"] + "{ShowId}", "{FullFilePath}", "{PathId}", "{Unique}", "{EpisodeId}"] delete_path = """ diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index 29706469..aeb3b9e0 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -443,6 +443,8 @@ class TVShows(KodiDb): obj['Filename'] = 'index.bdmv' LOG.debug("Bluray directory %s", obj['Path']) + obj['FullFilePath'] = obj['Path'] + obj['Filename'] + else: obj['Path'] = "plugin://plugin.video.jellyfin/%s/" % obj['SeriesId'] params = { @@ -452,6 +454,7 @@ class TVShows(KodiDb): 'mode': "play" } obj['Filename'] = "%s?%s" % (obj['Path'], urlencode(params)) + obj['FullFilePath'] = obj['Filename'] def get_show_id(self, obj): obj['ShowId'] = self.jellyfin_db.get_item_by_id(*values(obj, QUEM.get_item_series_obj)) From 435ad781322e5ca569090dc10a6b0d03842f9a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 13:02:54 +0200 Subject: [PATCH 11/19] Set idParentPath even in add-on mode Does not seem to harm anything even if it does not fix the infos --- jellyfin_kodi/objects/tvshows.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index aeb3b9e0..e71e1379 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -177,8 +177,7 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_tvshow_obj)) LOG.debug("ADD tvshow [%s/%s/%s] %s: %s", obj['TopPathId'], obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) - if self.direct_path: - self.update_path_parent_id(obj['PathId'], obj['TopPathId']) + self.update_path_parent_id(obj['PathId'], obj['TopPathId']) def tvshow_update(self, obj): @@ -196,8 +195,7 @@ class TVShows(KodiDb): self.jellyfin_db.update_reference(*values(obj, QUEM.update_reference_obj)) LOG.debug("UPDATE tvshow [%s/%s] %s: %s", obj['PathId'], obj['ShowId'], obj['Title'], obj['Id']) - if self.direct_path: - self.update_path_parent_id(obj['PathId'], obj['TopPathId']) + self.update_path_parent_id(obj['PathId'], obj['TopPathId']) def get_path_filename(self, obj): @@ -392,10 +390,9 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_episode_obj)) - if self.direct_path: - parentPathId = self.jellyfin_db.get_episode_kodi_parent_path_id(*values(obj, QUEM.get_episode_kodi_parent_path_id_obj)) - LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) - self.update_path_parent_id(obj['PathId'], parentPathId) + parentPathId = self.jellyfin_db.get_episode_kodi_parent_path_id(*values(obj, QUEM.get_episode_kodi_parent_path_id_obj)) + LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) + self.update_path_parent_id(obj['PathId'], parentPathId) LOG.debug("ADD episode [%s/%s] %s: %s", obj['PathId'], obj['FileId'], obj['Id'], obj['Title']) From e8188cacb141b2f1b045522993356554997d6160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 16:31:14 +0200 Subject: [PATCH 12/19] WIP add-on mode Context menus are working again Still no cast information Issue with idParentPath to fix tvshow path to check --- jellyfin_kodi/objects/tvshows.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index ac445df0..fcef66fa 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -201,6 +201,8 @@ class TVShows(KodiDb): ''' Get the path and build it into protocol://path ''' + LOG.debug("get_path_filename: path is [%s]", obj['Path']) + if self.direct_path: if '\\' in obj['Path']: @@ -217,7 +219,11 @@ class TVShows(KodiDb): raise PathValidationException("Failed to validate path. User stopped.") else: obj['TopLevel'] = "plugin://plugin.video.jellyfin/%s/" % obj['LibraryId'] - obj['Path'] = "%s%s/" % (obj['TopLevel'], obj['Id']) + # TV Show path is not containing the collection id aka toplevel + # obj['Path'] = "%s%s/" % (obj['TopLevel'], obj['Id']) + obj['Path'] = "plugin://plugin.video.jellyfin/%s/" % obj['Id'] + + LOG.debug("get_path_filename AFTER: path is [%s]", obj['Path']) @stop def season(self, item, show_id=None): From a7e2060c5c681998c058a6047c5e82e26c60350f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 16:44:36 +0200 Subject: [PATCH 13/19] Fix idParentPath addon mode --- jellyfin_kodi/objects/tvshows.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index fcef66fa..ecd34a14 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -394,8 +394,9 @@ class TVShows(KodiDb): self.jellyfin_db.add_reference(*values(obj, QUEM.add_reference_episode_obj)) parentPathId = self.jellyfin_db.get_episode_kodi_parent_path_id(*values(obj, QUEM.get_episode_kodi_parent_path_id_obj)) - LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) - self.update_path_parent_id(obj['PathId'], parentPathId) + if obj['PathId'] != parentPathId: + LOG.debug("Setting episode pathParentId, episode %s, title %s, pathId %s, pathParentId %s", obj['Id'], obj['Title'], obj['PathId'], parentPathId) + self.update_path_parent_id(obj['PathId'], parentPathId) LOG.debug("ADD episode [%s/%s] %s: %s", obj['PathId'], obj['FileId'], obj['Id'], obj['Title']) From a8f2935790649dc7f6dce81037d7fcec52f83ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 7 May 2023 20:18:20 +0200 Subject: [PATCH 14/19] Fix add-on mode. Hacky, to be tested --- jellyfin_kodi/objects/kodi/queries.py | 1 + jellyfin_kodi/objects/tvshows.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py index e9f1f7c9..940b07bd 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -358,6 +358,7 @@ WHERE idPath = ? """ update_path_movie_obj = ["{Path}", "movies", "metadata.local", 1, "{PathId}"] update_path_toptvshow_obj = ["{TopLevel}", "tvshows", "metadata.local", 1, "{TopPathId}"] +update_path_toptvshow_addon_obj = ["{TopLevel}", None, None, 1, "{TopPathId}"] update_path_tvshow_obj = ["{Path}", None, None, 1, "{PathId}"] update_path_episode_obj = ["{Path}", None, None, 1, "{PathId}"] update_path_mvideo_obj = ["{Path}", "musicvideos", "metadata.local", 1, "{PathId}"] diff --git a/jellyfin_kodi/objects/tvshows.py b/jellyfin_kodi/objects/tvshows.py index ecd34a14..99a7ead6 100644 --- a/jellyfin_kodi/objects/tvshows.py +++ b/jellyfin_kodi/objects/tvshows.py @@ -169,7 +169,19 @@ class TVShows(KodiDb): self.add_unique_id(*values(obj, QU.add_unique_id_tvshow_obj)) obj['TopPathId'] = self.add_path(obj['TopLevel']) - self.update_path(*values(obj, QU.update_path_toptvshow_obj)) + + if self.direct_path: + # Normal way, we use the actual top path + self.update_path(*values(obj, QU.update_path_toptvshow_obj)) + else: + # Hack to allow cast information in add-on mode + # We create a path on top of all others that holds mediaType and scrapper + self.update_path(*values(obj, QU.update_path_toptvshow_addon_obj)) + temp_obj = dict() + temp_obj['TopLevel'] = 'plugin://plugin.video.jellyfin/' + temp_obj['TopPathId'] = self.add_path(temp_obj['TopLevel']) + self.update_path(*values(temp_obj, QU.update_path_toptvshow_obj)) + self.update_path_parent_id(obj['TopPathId'], temp_obj['TopPathId']) obj['PathId'] = self.add_path(*values(obj, QU.get_path_obj)) From 7f11de708fa1ccdad5f66220320aead95304bc8d 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 15/19] 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 09909a50..9f7c9dad 100644 --- a/jellyfin_kodi/objects/kodi/kodi.py +++ b/jellyfin_kodi/objects/kodi/kodi.py @@ -150,8 +150,8 @@ class Kodi(object): 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 940b07bd..905edbce 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -402,6 +402,13 @@ update_link = """ 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 d1fab6cf39e9abc8705cd69974cffc1f1e3aafc6 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 16/19] 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 32f76967..93cc7b60 100644 --- a/jellyfin_kodi/objects/musicvideos.py +++ b/jellyfin_kodi/objects/musicvideos.py @@ -86,8 +86,6 @@ class MusicVideos(KodiDb): 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 [])] From 748683024dbf1416bfc8d531cde99956b196229f 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 17/19] Revert "Fix duplicate artist links" This reverts commit 7f11de708fa1ccdad5f66220320aead95304bc8d. --- jellyfin_kodi/objects/kodi/kodi.py | 4 ++-- jellyfin_kodi/objects/kodi/queries.py | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/kodi.py b/jellyfin_kodi/objects/kodi/kodi.py index 9f7c9dad..09909a50 100644 --- a/jellyfin_kodi/objects/kodi/kodi.py +++ b/jellyfin_kodi/objects/kodi/kodi.py @@ -150,8 +150,8 @@ class Kodi(object): bulk_updates.setdefault(sql, []).append((person_id,) + args) elif person['Type'] == 'Artist': - sql = QU.insert_link_if_not_exists.replace("{LinkType}", 'actor_link') - bulk_updates.setdefault(sql, []).append((person_id,) + args + (person_id,) + args) + sql = QU.update_link.replace("{LinkType}", 'actor_link') + bulk_updates.setdefault(sql, []).append((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 905edbce..940b07bd 100644 --- a/jellyfin_kodi/objects/kodi/queries.py +++ b/jellyfin_kodi/objects/kodi/queries.py @@ -402,13 +402,6 @@ update_link = """ 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 628debe984990ce183f0a583909ebf831142950b 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 18/19] Revert "Fix: remove override of previously set libraryId and name" This reverts commit d1fab6cf39e9abc8705cd69974cffc1f1e3aafc6. --- jellyfin_kodi/objects/musicvideos.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jellyfin_kodi/objects/musicvideos.py b/jellyfin_kodi/objects/musicvideos.py index 93cc7b60..32f76967 100644 --- a/jellyfin_kodi/objects/musicvideos.py +++ b/jellyfin_kodi/objects/musicvideos.py @@ -86,6 +86,8 @@ class MusicVideos(KodiDb): 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 [])] From abda9754c8d32167753ff0ecd4af51f69d4d4866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goireDruant?= Date: Sun, 27 Aug 2023 17:08:26 +0200 Subject: [PATCH 19/19] Chore: added new line at the end of file --- jellyfin_kodi/database/queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jellyfin_kodi/database/queries.py b/jellyfin_kodi/database/queries.py index 6136a50e..52d68846 100644 --- a/jellyfin_kodi/database/queries.py +++ b/jellyfin_kodi/database/queries.py @@ -179,4 +179,4 @@ AND s.media_type = ? AND sh.media_type = ? AND e.jellyfin_id = ?; """ -get_episode_kodi_parent_path_id_obj = ["episode", "season", "tvshow", "{Id}"] \ No newline at end of file +get_episode_kodi_parent_path_id_obj = ["episode", "season", "tvshow", "{Id}"]