diff --git a/mumbleBot.py b/mumbleBot.py
index fc9d944..e9e9904 100644
--- a/mumbleBot.py
+++ b/mumbleBot.py
@@ -27,7 +27,7 @@ import media.file
import media.playlist
import media.radio
import media.system
-from radiobrowser import getstations_byname
+from radiobrowser import getstations_byname, geturl_byid
"""
FORMAT OF A MUSIC INTO THE PLAYLIST
@@ -361,20 +361,43 @@ class MumbleBot:
self.async_download_next()
else:
self.send_msg(var.config.get('strings', 'bad_url'))
+ # query http://www.radio-browser.info API for a radio station
elif command == var.config.get('command', 'rb_query'):
logging.info('Querying radio stations')
msg = var.config.get(
'strings', 'rbqueryresult') + " :"
if not parameter:
logging.info('rbquery without parameter')
+ msg += 'You have to add a query text to search for a specific radio station.'
+ self.send_msg(msg, text)
else:
logging.info('Found query parameter: ' + parameter)
- stations = getstations_byname(parameter)
+ rb_stations = getstations_byname(parameter)
msg += '\n
ID | Station Name |
'
- for s in stations:
+ for s in rb_stations:
msg += '' + s['id'] + ' | ' + s['stationname'] + ' |
'
msg += '
'
self.send_msg(msg, text)
+ # Play a secific station (by id) from http://www.radio-browser.info API
+ elif command == var.config.get('command', 'rb_play'):
+ logging.info('Play a station by ID')
+ if not parameter:
+ logging.info('rbplay withou parameter')
+ msg += 'Please enter a station ID from rbquery. Example: !rbplay 96748'
+ self.send_msg(msg, text)
+ else:
+ logging.info('Retreiving url for station ID ' + parameter)
+ url = geturl_byid(parameter)
+ if url != "-1":
+ logging.info('Found url: ' + url)
+ music = {'type': 'radio',
+ 'url': url,
+ 'user': user}
+ var.playlist.append(music)
+ self.async_download_next()
+ else:
+ logging.info('No playable url found.')
+ pass
elif command == var.config.get('command', 'help'):
self.send_msg(var.config.get('strings', 'help'), text)
diff --git a/radiobrowser.py b/radiobrowser.py
index 14df93a..c9bf04f 100644
--- a/radiobrowser.py
+++ b/radiobrowser.py
@@ -14,6 +14,13 @@ def getstations_byname(query):
pass
return stations
+def geturl_byid(id):
+ url = rb.playable_station(id)['url']
+ if url != None:
+ return url
+ else:
+ return "-1"
+
if __name__ == "__main__":
r = getstations_byname('r.sh')