From 4c6b69abf656217a98aa8376277732c65ca93011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Fri, 17 May 2024 05:41:36 +0200 Subject: [PATCH 1/3] Check KodiSyncQueue GetPluginSettings endpoint to determine whether the plugin is enabled or not Fixes #861 --- jellyfin_kodi/jellyfin/api.py | 33 ++++++++------------------------- jellyfin_kodi/library.py | 2 +- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/jellyfin_kodi/jellyfin/api.py b/jellyfin_kodi/jellyfin/api.py index d28b7ca32..8d9f2cae4 100644 --- a/jellyfin_kodi/jellyfin/api.py +++ b/jellyfin_kodi/jellyfin/api.py @@ -254,37 +254,20 @@ def get_items_theme_song(self, parent_id): 'ParentId': parent_id }) - def get_plugins(self): - return self._get("Plugins") - - def check_companion_installed(self): + def check_companion_enabled(self): """ + True = Enabled + False = Not enabled None = Unknown - True = Installed, but possibly not loaded right now - False = Not installed, scheduled for uninstalling or disabled """ try: - kodi_sync_queue = [ - x - for x in self.get_plugins() - if x.get("Id") == "771e19d653854cafb35c28a0e865cf63" - ] - - LOG.debug("KodiSyncQueue Plugins result: %s", kodi_sync_queue) - - kodi_sync_queue_filtered = [ - x - for x in kodi_sync_queue - if x.get("Status") - in ["Active", "Restart", "Malfunctioned", "NotSupported"] - ] - - if kodi_sync_queue_filtered: - return True - else: - return False + plugin_settings = self._get("Jellyfin.Plugin.KodiSyncQueue/GetPluginSettings") or {} + return plugin_settings.get('IsEnabled') + except requests.RequestException as e: LOG.warning("Error checking companion installed state: %s", e) + if e.response.status_code == 404: + return False return None diff --git a/jellyfin_kodi/library.py b/jellyfin_kodi/library.py index 7e6bcf577..c31276641 100644 --- a/jellyfin_kodi/library.py +++ b/jellyfin_kodi/library.py @@ -353,7 +353,7 @@ def startup(self): 'kodiCompanion.bool' ): # None == Unknown - if self.server.jellyfin.check_companion_installed() is not False: + if self.server.jellyfin.check_companion_enabled() is not False: if not self.fast_sync(): dialog("ok", "{jellyfin}", translate(33128)) From 704c8829f0645a6541322cbe26cabda2f468e3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sat, 18 May 2024 01:50:50 +0200 Subject: [PATCH 2/3] Mark helper.exceptions.HTTPException as deprecated --- jellyfin_kodi/helper/exceptions.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jellyfin_kodi/helper/exceptions.py b/jellyfin_kodi/helper/exceptions.py index 2a53b0082..12105ed80 100644 --- a/jellyfin_kodi/helper/exceptions.py +++ b/jellyfin_kodi/helper/exceptions.py @@ -1,12 +1,15 @@ # -*- coding: utf-8 -*- from __future__ import division, absolute_import, print_function, unicode_literals +import warnings + ################################################################################################# class HTTPException(Exception): # Jellyfin HTTP exception def __init__(self, status, message): + warnings.warn(f'{self.__class__.__name__} will be deprecated.', DeprecationWarning, stacklevel=2) self.status = status self.message = message From 1899ecb9991f8babc05c84962a40748234c8f8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sat, 18 May 2024 01:54:06 +0200 Subject: [PATCH 3/3] Also catch HTTPException in API.check_companion_enabled --- jellyfin_kodi/jellyfin/api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jellyfin_kodi/jellyfin/api.py b/jellyfin_kodi/jellyfin/api.py index 8d9f2cae4..a65c5836f 100644 --- a/jellyfin_kodi/jellyfin/api.py +++ b/jellyfin_kodi/jellyfin/api.py @@ -6,6 +6,7 @@ import requests from six import ensure_str +from ..helper.exceptions import HTTPException from ..helper.utils import settings from ..helper import LazyLogger @@ -268,6 +269,10 @@ def check_companion_enabled(self): LOG.warning("Error checking companion installed state: %s", e) if e.response.status_code == 404: return False + except HTTPException as e: + LOG.warning("Error checking companion installed state: %s", e) + if e.status == 404: + return False return None