diff --git a/mopidy_radionet/library.py b/mopidy_radionet/library.py index d62788a..6512b8c 100644 --- a/mopidy_radionet/library.py +++ b/mopidy_radionet/library.py @@ -209,9 +209,7 @@ class RadioNetLibraryProvider(backend.LibraryProvider): result = [] - self.backend.radionet.do_search(" ".join(query["any"])) - - for station in self.backend.radionet.search_results: + for station in self.backend.radionet.do_search(" ".join(query["any"])): result.append(self.station_to_track(station)) return SearchResult(tracks=result) diff --git a/mopidy_radionet/radionet.py b/mopidy_radionet/radionet.py index 54d6404..5c30418 100644 --- a/mopidy_radionet/radionet.py +++ b/mopidy_radionet/radionet.py @@ -293,7 +293,7 @@ class RadioNetClient(object): ) return self.set_cache(cache_key, favorite_stations, 1440) - def do_search(self, query_string, page_index=1, search_results=[]): + def do_search(self, query_string, page_index=1, search_results=None): api_suffix = "/search/stationsonly" url_params = { @@ -308,6 +308,8 @@ class RadioNetClient(object): logger.error("Radio.net: Search error " + response.text) else: logger.debug("Radio.net: Done search") + if search_results is None: + search_results = [] json = response.json() for match in json["categories"][0]["matches"]: station = self.get_station_by_id(match["id"]) diff --git a/tests/test_library.py b/tests/test_library.py index 38455e4..492a23a 100644 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -140,3 +140,15 @@ def test_browse_countries(library): def test_browse_favorites(library): results = library.browse('radionet:favorites'); assert 1 == len(results) + + +def test_search(library): + result = library.search({'any': ['radio ram']}) + + assert len(result.tracks) > 0 + + old_length = len(result.tracks) + + result = library.search({'any': ['radio ram']}) + + assert len(result.tracks) == old_length \ No newline at end of file