From d87f3038d91f67ff6e3fa013263564ad5023336d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=A9tous?= Date: Tue, 27 Apr 2021 23:13:43 +0200 Subject: [PATCH] Fix an unreachable branch in the search function The warning notification was never displayed because PeerTube class always returned a value even if no videos matching the keywords were found. --- resources/lib/addon.py | 3 ++- resources/lib/peertube.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/resources/lib/addon.py b/resources/lib/addon.py index a3cefe9..82eabaa 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -323,7 +323,8 @@ class PeerTubeAddon(): if not results: kodi.notif_warning( title="No videos found", - message="No videos found matching the keywords.") + message="No videos found matching the keywords '{}'" + .format(keywords)) return # Extract the information of each video from the API response diff --git a/resources/lib/peertube.py b/resources/lib/peertube.py index af88411..5c1a4ef 100644 --- a/resources/lib/peertube.py +++ b/resources/lib/peertube.py @@ -198,14 +198,22 @@ class PeerTube: :param str keywords: keywords to seach for :param int start: index of the first video to display :return: the videos matching the keywords as returned by the REST API + or None if there are no matches returned :rtype: dict """ - # Build the parameters that will be send in the request + # Build the parameters that will be sent in the request params = self._build_params(search=keywords, filter=self.filter, start=start) - return self._request(method="GET", url="search/videos", params=params) + response = self._request(method="GET", + url="search/videos", + params=params) + + if response["total"] == 0: + return None + else: + return response def set_instance(self, instance): """Set the URL of the current instance with the right format