Permalink
Browse files

Sometimes, for no apparent reason, TuneIn searches are grouped in a s…

…tation list and sometimes they're not. Why?! Either way, flattern the list and return only the stations.
  • Loading branch information...
1 parent ed569f7 commit adbd29604de52d9fa8cba1ddf1fbb8a79d25414f @kingosticks committed Feb 23, 2014
Showing with 12 additions and 1 deletion.
  1. +12 −1 mopidy_tunein/tunein.py
@@ -133,6 +133,15 @@ def reload(self):
self._tunein.clear()
self._get_playlist.clear()
+ def _flatten(self, data):
+ results = []
+ for item in data:
+ if 'children' in item:
+ results.extend(item['children'])
+ else:
+ results.append(item)
+ return results
+
def _filter_results(self, data, section_name=None, map_func=None):
results = []
@@ -270,9 +279,11 @@ def station(self, station_id):
def search(self, query):
# "Search.ashx?query=" + query + filterVal
+ logger.debug('Searching for "%s"' % query)
args = '&query=' + query
+ search_results = self._tunein('Search.ashx', args)
results = []
- for item in self._tunein('Search.ashx', args):
+ for item in self._flatten(search_results):
if item.get('type', '') == 'audio':
# Only return stations
self._stations[item['guide_id']] = item

0 comments on commit adbd296

Please sign in to comment.