mirror of
https://github.com/fergalmoran/dss.radio.git
synced 2025-12-22 09:48:21 +00:00
Initial deploy
This commit is contained in:
71
server.py
71
server.py
@@ -1,28 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
import logging
|
||||
|
||||
from shout import ShoutException
|
||||
import os
|
||||
import signal
|
||||
import time
|
||||
import tornado
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
import tornado.escape
|
||||
from tornado.options import define, options, parse_command_line
|
||||
import os
|
||||
import signal
|
||||
from ice_client import IceClient
|
||||
|
||||
from ice_relay import IceRelay
|
||||
|
||||
define("port", default=8888, help="run on the given port", type=int)
|
||||
define("debug", default=True, help="run in debug mode")
|
||||
|
||||
define("ice_host", default='localhost', help="Icecast server host")
|
||||
define("ice_port", default=8999, help="Icecast server port")
|
||||
define("ice_user", default='source', help="Icecast user")
|
||||
define("ice_password", default='hackme', help="Icecast password")
|
||||
define("ice_mount", default='/mp3', help="Default icecast mount point")
|
||||
define("ice_format", default='mp3', help="Format of the icecast server (mp3, vorbis, flac)")
|
||||
define("ice_protocol", default='http', help="Protocol (currently only http)")
|
||||
is_closing = False
|
||||
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
@@ -37,7 +25,6 @@ class PlayAudioHandler(tornado.web.RequestHandler):
|
||||
in_file = data.get('audio_file')
|
||||
if in_file is not None:
|
||||
relay.set_audio_queue([in_file])
|
||||
relay.stop()
|
||||
time.sleep(10)
|
||||
except Exception, ex:
|
||||
raise tornado.web.HTTPError(500, ex.message)
|
||||
@@ -46,12 +33,10 @@ class PlayAudioHandler(tornado.web.RequestHandler):
|
||||
class StopAudioHandler(tornado.web.RequestHandler):
|
||||
def post(self, *args, **kwargs):
|
||||
try:
|
||||
relay.stop()
|
||||
relay.channel_close()
|
||||
except Exception, ex:
|
||||
raise tornado.web.HTTPError(500, ex.message)
|
||||
|
||||
is_closing = False
|
||||
|
||||
|
||||
def signal_handler(signum, frame):
|
||||
global is_closing
|
||||
@@ -63,14 +48,35 @@ def try_exit():
|
||||
global is_closing
|
||||
if is_closing:
|
||||
# clean up here
|
||||
streamer.stop()
|
||||
relay.stop()
|
||||
relay.channel_close()
|
||||
|
||||
tornado.ioloop.IOLoop.instance().stop()
|
||||
logging.info('exit success')
|
||||
|
||||
define("port", default=8888, help="run on the given port", type=int)
|
||||
define("debug", default=True, help="run in debug mode")
|
||||
|
||||
define("ice_host", default='localhost', help="Icecast server host")
|
||||
define("ice_port", default=8000, help="Icecast server port")
|
||||
define("ice_user", default='source', help="Icecast user")
|
||||
define("ice_password", default='hackme', help="Icecast password")
|
||||
define("ice_mount", default='/mp3', help="Default icecast mount point")
|
||||
define("ice_format", default='mp3', help="Format of the icecast server (mp3, vorbis, flac)")
|
||||
define("ice_protocol", default='http', help="Protocol (currently only http)")
|
||||
define("api_host", default='api.deepsouthsounds.com', help="API Host for serving audio")
|
||||
|
||||
#tornado.options.parse_command_line()
|
||||
tornado.options.parse_config_file("dss.radio.conf")
|
||||
relay = IceRelay(options=options)
|
||||
|
||||
|
||||
def main():
|
||||
if relay.channel_open():
|
||||
relay.start()
|
||||
else:
|
||||
logging.error("IceCast relay failed to start")
|
||||
exit()
|
||||
|
||||
app = tornado.web.Application(
|
||||
[
|
||||
(r"/", MainHandler),
|
||||
@@ -81,30 +87,13 @@ def main():
|
||||
template_path=os.path.join(os.path.dirname(__file__), "templates"),
|
||||
static_path=os.path.join(os.path.dirname(__file__), "static"),
|
||||
# xsrf_cookies=True,
|
||||
debug=options.debug
|
||||
debug=options['debug']
|
||||
)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
app.listen(options.port)
|
||||
app.listen(options['port'])
|
||||
tornado.ioloop.PeriodicCallback(try_exit, 100).start()
|
||||
tornado.ioloop.IOLoop.current().start()
|
||||
|
||||
parse_command_line()
|
||||
try:
|
||||
streamer = IceClient(
|
||||
host=options['ice_host'],
|
||||
port=options['ice_port'],
|
||||
user=options['ice_user'],
|
||||
password=options['ice_password'],
|
||||
mount=options['ice_mount'],
|
||||
format=options['ice_format'],
|
||||
protocol=options['ice_protocol']
|
||||
)
|
||||
relay = IceRelay(client=streamer)
|
||||
relay.start()
|
||||
|
||||
except ShoutException as ex:
|
||||
logging.info("Unable to connect to shout server {}:{} - {}".format(options['ice_host'], options['ice_port'], ex))
|
||||
exit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user