From 34e489297586d31375e3c27fa569ee847fccbbae Mon Sep 17 00:00:00 2001 From: Eric van Blokland Date: Tue, 28 Sep 2021 16:18:29 +0200 Subject: [PATCH] Fixed error caused by unrecognized favorite not yielding result in search --- mopidy_radionet/radionet.py | 13 +++++++++---- tests/test_radionet.py | 9 ++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mopidy_radionet/radionet.py b/mopidy_radionet/radionet.py index 9a80275..79f600d 100644 --- a/mopidy_radionet/radionet.py +++ b/mopidy_radionet/radionet.py @@ -370,10 +370,15 @@ class RadioNetClient(object): logger.debug("Radio.net: Done search") json = response.json() - # take only the first match! - station = self._get_station_from_search_result( - json["categories"][0]["matches"][0] - ) + number_pages = int(json["numberPages"]) + logger.error(json) + if number_pages != 0: + # take only the first match! + station = self._get_station_from_search_result( + json["categories"][0]["matches"][0] + ) + else: + logger.warning("Radio.net: No results for %s", station_slug) if station and station.playable: favorite_stations.append(station) diff --git a/tests/test_radionet.py b/tests/test_radionet.py index cb2a816..f26a6d1 100644 --- a/tests/test_radionet.py +++ b/tests/test_radionet.py @@ -26,9 +26,16 @@ def test_do_search(radionet): def test_get_favorites(radionet): - test_favorites = ("Rock Antenne", "radio ram", "eska", "dancefm") + test_favorites = ["Rock Antenne", "radio ram", "eska", "dancefm"] radionet.set_favorites(test_favorites) result = radionet.get_favorites() assert len(result) == len(test_favorites) assert result[2].name == 'Eska' + + +def test_favorites_broken_slug(radionet): + test_favorites = ["radio357"] + radionet.set_favorites(test_favorites) + result = radionet.get_favorites() + assert len(result) == 0