fixed apiUrl and added favorites
This commit is contained in:
@@ -6,7 +6,7 @@ import os
|
||||
from mopidy import config, ext
|
||||
|
||||
|
||||
__version__ = '0.2.1'
|
||||
__version__ = '0.2.2'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -26,6 +26,7 @@ class Extension(ext.Extension):
|
||||
schema = super(Extension, self).get_config_schema()
|
||||
schema['language'] = config.String()
|
||||
schema['min_bitrate'] = config.String()
|
||||
schema['favorite_stations'] = config.List()
|
||||
return schema
|
||||
|
||||
def setup(self, registry):
|
||||
|
||||
@@ -29,6 +29,7 @@ class RadioNetBackend(pykka.ThreadingActor, backend.Backend):
|
||||
|
||||
self.radionet.min_bitrate = int(config['radionet']['min_bitrate'])
|
||||
self.radionet.set_lang(str(config['radionet']['language']))
|
||||
self.radionet.set_favorites(tuple(file_ext.lower() for file_ext in config["radionet"]["favorite_stations"]))
|
||||
|
||||
def set_update_timeout(self, minutes=2):
|
||||
self.update_timeout = time.time() + 60 * minutes
|
||||
@@ -43,4 +44,5 @@ class RadioNetBackend(pykka.ThreadingActor, backend.Backend):
|
||||
if force or time.time() > self.update_timeout:
|
||||
self.radionet.get_top_stations()
|
||||
self.radionet.get_local_stations()
|
||||
self.radionet.get_favorites()
|
||||
self.set_update_timeout()
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
enabled = true
|
||||
language = pl
|
||||
min_bitrate = 96
|
||||
favorite_stations =
|
||||
@@ -62,6 +62,11 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
||||
self.ref_directory(
|
||||
"radionet:category:top100", "Top 100")
|
||||
)
|
||||
if self.backend.radionet.favorite_stations:
|
||||
directories.append(
|
||||
self.ref_directory(
|
||||
"radionet:category:favorites", "Favorites")
|
||||
)
|
||||
return directories
|
||||
elif variant == 'category' and identifier:
|
||||
if identifier == "localstations":
|
||||
@@ -70,6 +75,9 @@ class RadioNetLibraryProvider(backend.LibraryProvider):
|
||||
if identifier == "top100":
|
||||
for station in self.backend.radionet.top_stations:
|
||||
tracks.append(self.station_to_ref(station))
|
||||
if identifier == "favorites":
|
||||
for station in self.backend.radionet.favorite_stations:
|
||||
tracks.append(self.station_to_ref(station))
|
||||
tracks.sort(key=lambda ref: ref.name)
|
||||
return tracks
|
||||
else:
|
||||
|
||||
@@ -76,6 +76,7 @@ class RadioNetClient(object):
|
||||
|
||||
apiprefix_search = re.search('apiPrefix ?: ?\'(.*)\',?', tmp_str.content.decode())
|
||||
self.api_prefix = apiprefix_search.group(1)
|
||||
self.api_prefix = "https://api.radio." + 'de' + "/info/v2"
|
||||
|
||||
apikey_search = re.search('apiKey ?: ?[\'|"](.*)[\'|"],?', tmp_str.content.decode())
|
||||
self.api_key = apikey_search.group(1)
|
||||
@@ -170,6 +171,37 @@ class RadioNetClient(object):
|
||||
logger.info('Radio.net: Loaded ' + str(len(self.local_stations)) +
|
||||
' local stations.')
|
||||
|
||||
def set_favorites(self, favorites):
|
||||
self.favortes = favorites
|
||||
|
||||
def get_favorites(self):
|
||||
self.favorite_stations = []
|
||||
|
||||
for station in self.favortes:
|
||||
api_suffix = '/search/stationsonly'
|
||||
url_params = {
|
||||
'apikey': self.api_key,
|
||||
'_': self.current_milli_time(),
|
||||
'query': station,
|
||||
'pageindex': 1,
|
||||
}
|
||||
|
||||
response = self.do_post(api_suffix, url_params)
|
||||
|
||||
if response.status_code is not 200:
|
||||
logger.error('Radio.net: Search error ' + response.text)
|
||||
else:
|
||||
logger.debug('Radio.net: Done search')
|
||||
json = response.json()
|
||||
|
||||
# take only the first match!
|
||||
station = self.get_station_by_id(json['categories'][0]['matches'][0]['id'])
|
||||
if station and station.playable:
|
||||
self.favorite_stations.append(station)
|
||||
|
||||
logger.info('Radio.net: Loaded ' + str(len(self.favorite_stations)) +
|
||||
' favorite stations.')
|
||||
|
||||
def get_top_stations(self):
|
||||
self.top_stations = []
|
||||
api_suffix = '/search/topstations'
|
||||
|
||||
Reference in New Issue
Block a user