Try to play radio
This commit is contained in:
29
mumbleBot.py
29
mumbleBot.py
@ -27,7 +27,7 @@ import media.file
|
|||||||
import media.playlist
|
import media.playlist
|
||||||
import media.radio
|
import media.radio
|
||||||
import media.system
|
import media.system
|
||||||
from radiobrowser import getstations_byname
|
from radiobrowser import getstations_byname, geturl_byid
|
||||||
|
|
||||||
"""
|
"""
|
||||||
FORMAT OF A MUSIC INTO THE PLAYLIST
|
FORMAT OF A MUSIC INTO THE PLAYLIST
|
||||||
@ -361,20 +361,43 @@ class MumbleBot:
|
|||||||
self.async_download_next()
|
self.async_download_next()
|
||||||
else:
|
else:
|
||||||
self.send_msg(var.config.get('strings', 'bad_url'))
|
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'):
|
elif command == var.config.get('command', 'rb_query'):
|
||||||
logging.info('Querying radio stations')
|
logging.info('Querying radio stations')
|
||||||
msg = var.config.get(
|
msg = var.config.get(
|
||||||
'strings', 'rbqueryresult') + " :"
|
'strings', 'rbqueryresult') + " :"
|
||||||
if not parameter:
|
if not parameter:
|
||||||
logging.info('rbquery without 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:
|
else:
|
||||||
logging.info('Found query parameter: ' + parameter)
|
logging.info('Found query parameter: ' + parameter)
|
||||||
stations = getstations_byname(parameter)
|
rb_stations = getstations_byname(parameter)
|
||||||
msg += '\n<table><tr><th>ID</th><th>Station Name</th></tr>'
|
msg += '\n<table><tr><th>ID</th><th>Station Name</th></tr>'
|
||||||
for s in stations:
|
for s in rb_stations:
|
||||||
msg += '<tr><td>' + s['id'] + '</td><td>' + s['stationname'] + '</td></tr>'
|
msg += '<tr><td>' + s['id'] + '</td><td>' + s['stationname'] + '</td></tr>'
|
||||||
msg += '</table>'
|
msg += '</table>'
|
||||||
self.send_msg(msg, text)
|
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'):
|
elif command == var.config.get('command', 'help'):
|
||||||
self.send_msg(var.config.get('strings', 'help'), text)
|
self.send_msg(var.config.get('strings', 'help'), text)
|
||||||
|
@ -14,6 +14,13 @@ def getstations_byname(query):
|
|||||||
pass
|
pass
|
||||||
return stations
|
return stations
|
||||||
|
|
||||||
|
def geturl_byid(id):
|
||||||
|
url = rb.playable_station(id)['url']
|
||||||
|
if url != None:
|
||||||
|
return url
|
||||||
|
else:
|
||||||
|
return "-1"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
r = getstations_byname('r.sh')
|
r = getstations_byname('r.sh')
|
||||||
|
Reference in New Issue
Block a user