Fixed favorites inconsistent results
Should look up station by slug instead of search for station
This commit is contained in:
@@ -259,34 +259,37 @@ class RadioNetClient(object):
|
|||||||
self.favorites = favorites
|
self.favorites = favorites
|
||||||
|
|
||||||
def get_favorites(self):
|
def get_favorites(self):
|
||||||
logger.error(str(self.favorites))
|
|
||||||
cache_key = "favorites"
|
cache_key = "favorites"
|
||||||
cache = self.get_cache(cache_key)
|
cache = self.get_cache(cache_key)
|
||||||
if cache is not None:
|
if cache is not None:
|
||||||
return cache
|
return cache
|
||||||
|
|
||||||
favorite_stations = []
|
favorite_stations = []
|
||||||
for station in self.favorites:
|
for station_slug 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)
|
|
||||||
|
|
||||||
if response.status_code != 200:
|
station = self.get_station_by_id(station_slug)
|
||||||
logger.error("Radio.net: Search error " + response.text)
|
|
||||||
else:
|
|
||||||
logger.debug("Radio.net: Done search")
|
|
||||||
json = response.json()
|
|
||||||
|
|
||||||
# take only the first match!
|
if station is False:
|
||||||
station = self.get_station_by_id(
|
api_suffix = "/search/stationsonly"
|
||||||
json["categories"][0]["matches"][0]["id"]
|
url_params = {
|
||||||
)
|
"query": station_slug,
|
||||||
if station and station.playable:
|
"pageindex": 1,
|
||||||
favorite_stations.append(station)
|
}
|
||||||
|
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(
|
logger.info(
|
||||||
"Radio.net: Loaded " + str(len(favorite_stations)) + " favorite stations."
|
"Radio.net: Loaded " + str(len(favorite_stations)) + " favorite stations."
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ def test_do_search(radionet):
|
|||||||
|
|
||||||
|
|
||||||
def test_get_favorites(radionet):
|
def test_get_favorites(radionet):
|
||||||
test_favorites = ("Rock Antenne", "radio ram")
|
test_favorites = ("Rock Antenne", "radio ram", "eska")
|
||||||
radionet.set_favorites(test_favorites)
|
radionet.set_favorites(test_favorites)
|
||||||
result = radionet.get_favorites()
|
result = radionet.get_favorites()
|
||||||
assert len(result) == len(test_favorites)
|
assert len(result) == len(test_favorites)
|
||||||
|
|
||||||
|
assert result[2].name == 'Eska'
|
||||||
Reference in New Issue
Block a user