From f5b077faa4824dc5be48702e2567ca763ba43062 Mon Sep 17 00:00:00 2001 From: Dmitrii Misharov Date: Wed, 23 Dec 2020 19:57:30 +0100 Subject: [PATCH] Fix toggle watched (#150) * Used native notification dialog * Removed unneeded string decoding * Fixed toggle watched --- src/resources/lib/client.py | 13 +++++++------ src/resources/lib/listitem.py | 8 ++++---- src/resources/lib/modeling.py | 4 +--- src/resources/lib/utils.py | 4 ++-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/resources/lib/client.py b/src/resources/lib/client.py index 612f75d..dd54daf 100644 --- a/src/resources/lib/client.py +++ b/src/resources/lib/client.py @@ -36,12 +36,13 @@ def _make_request(self, request, timeout=600): self.plugin.logger.error(f"{type(e).__name__}. Message: {e.message}") notice(e.message, "Ошибка") else: - response = json.loads(response.read()) - if response["status"] == 200: - return response - else: - self.plugin.logger.error(f"Unknown error. Code: {response['status']}") - notice(f"Код ответа сервера {response['status']}", "Неизвестная ошибка") + if r := response.read(): + response = json.loads(r) + if response["status"] == 200: + return response + else: + self.plugin.logger.error(f"Unknown error. Code: {response['status']}") + notice(f"Код ответа сервера {response['status']}", "Ошибка") def get(self, data=""): data = f"?{urllib.parse.urlencode(data)}" if data else "" diff --git a/src/resources/lib/listitem.py b/src/resources/lib/listitem.py index a0de113..480cf2d 100644 --- a/src/resources/lib/listitem.py +++ b/src/resources/lib/listitem.py @@ -49,7 +49,7 @@ def _addWatchlistContextMenuItem(self, menu_items): url = self.plugin.routing.build_url( "toggle_watchlist", self.getProperty("id"), added=int(not int(in_watchlist)) ) - menu_items.append((label, f"XBMC.RunPlugin({url})")) + menu_items.append((label, f"Container.Update({url})")) def _addWatchedContextMenuItem(self, menu_items): item_id = self.getProperty("id") @@ -69,7 +69,7 @@ def _addWatchedContextMenuItem(self, menu_items): else: kwargs = {"video": video_number} url = self.plugin.routing.build_url("toggle_watched", item_id, **kwargs) - menu_items.append((label, f"XBMC.RunPlugin({url})")) + menu_items.append((label, f"Container.Update({url})")) def _addBookmarksContextMenuItem(self, menu_items): if self.getVideoInfoTag().getMediaType() == "season": @@ -77,13 +77,13 @@ def _addBookmarksContextMenuItem(self, menu_items): item_id = self.getProperty("id") label = "Изменить закладки" url = self.plugin.routing.build_url("edit_bookmarks", item_id) - menu_items.append((label, f"XBMC.RunPlugin({url})")) + menu_items.append((label, f"Container.Update({url})")) def _addCommentsContextMenuItem(self, menu_items): item_id = self.getProperty("id") label = "Комментарии KinoPub" url = self.plugin.routing.build_url("comments", item_id) - menu_items.append((label, f"XBMC.RunPlugin({url})")) + menu_items.append((label, f"Container.Update({url})")) def _addSimilarContextMenuItem(self, menu_items): item_id = self.getProperty("id") diff --git a/src/resources/lib/modeling.py b/src/resources/lib/modeling.py index 46ffbff..b55bc4c 100644 --- a/src/resources/lib/modeling.py +++ b/src/resources/lib/modeling.py @@ -206,9 +206,7 @@ def __getstate__(self): return odict def __repr__(self): - return ( - f"{type(self).__name__}(item_id: {self.item_id}; title: {self.title.encode('utf-8')})" - ) + return f"{type(self).__name__}(item_id: {self.item_id}; title: {self.title})" class PlayableItem(ItemEntity): diff --git a/src/resources/lib/utils.py b/src/resources/lib/utils.py index c8a962c..fe35f91 100644 --- a/src/resources/lib/utils.py +++ b/src/resources/lib/utils.py @@ -1,5 +1,5 @@ -import xbmc +import xbmcgui def notice(message, heading="", time=4000): - xbmc.executebuiltin(f'XBMC.Notification("{heading}", "{message}", "{time}")') + xbmcgui.Dialog().notification(heading, message, time=time)