diff --git a/mopidy_radionet/radionet.py b/mopidy_radionet/radionet.py index 5c30418..33a69a3 100644 --- a/mopidy_radionet/radionet.py +++ b/mopidy_radionet/radionet.py @@ -259,34 +259,37 @@ class RadioNetClient(object): self.favorites = favorites def get_favorites(self): - logger.error(str(self.favorites)) cache_key = "favorites" cache = self.get_cache(cache_key) if cache is not None: return cache favorite_stations = [] - for station in self.favorites: - logger.error(str(station)) - api_suffix = "/search/stationsonly" - url_params = { - "query": station, - "pageindex": 1, - } - response = self.do_get(api_suffix, url_params) + for station_slug in self.favorites: - if response.status_code != 200: - logger.error("Radio.net: Search error " + response.text) - else: - logger.debug("Radio.net: Done search") - json = response.json() + station = self.get_station_by_id(station_slug) - # take only the first match! - station = self.get_station_by_id( - json["categories"][0]["matches"][0]["id"] - ) - if station and station.playable: - favorite_stations.append(station) + if station is False: + api_suffix = "/search/stationsonly" + url_params = { + "query": station_slug, + "pageindex": 1, + } + response = self.do_get(api_suffix, url_params) + + if response.status_code != 200: + logger.error("Radio.net: Search error " + response.text) + else: + logger.debug("Radio.net: Done search") + json = response.json() + logger.error(response.text) + # take only the first match! + station = self.get_station_by_id( + json["categories"][0]["matches"][0]["id"] + ) + + if station and station.playable: + favorite_stations.append(station) logger.info( "Radio.net: Loaded " + str(len(favorite_stations)) + " favorite stations." diff --git a/tests/test_radionet.py b/tests/test_radionet.py index 48eebe1..3a0ce48 100644 --- a/tests/test_radionet.py +++ b/tests/test_radionet.py @@ -22,7 +22,9 @@ def test_do_search(radionet): def test_get_favorites(radionet): - test_favorites = ("Rock Antenne", "radio ram") + test_favorites = ("Rock Antenne", "radio ram", "eska") radionet.set_favorites(test_favorites) result = radionet.get_favorites() assert len(result) == len(test_favorites) + + assert result[2].name == 'Eska' \ No newline at end of file