Fixed favorites inconsistent results

Should look up station by slug instead of search for station
This commit is contained in:
Eric van Blokland
2021-09-08 20:25:52 +02:00
parent 76161adfdb
commit 10ead80966
2 changed files with 26 additions and 21 deletions

View File

@@ -259,18 +259,20 @@ 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))
for station_slug in self.favorites:
station = self.get_station_by_id(station_slug)
if station is False:
api_suffix = "/search/stationsonly"
url_params = {
"query": station,
"query": station_slug,
"pageindex": 1,
}
response = self.do_get(api_suffix, url_params)
@@ -280,11 +282,12 @@ class RadioNetClient(object):
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)

View File

@@ -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'