1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-26 09:37:25 +00:00

Initial commit

This commit is contained in:
morpheus65535 2018-11-29 21:24:48 -05:00
parent 552cae7483
commit 005b78f350
3 changed files with 29 additions and 4 deletions

View file

@ -78,6 +78,7 @@ def configure_logging(debug=False):
logging.getLogger("guessit").setLevel(logging.WARNING)
logging.getLogger("rebulk").setLevel(logging.WARNING)
logging.getLogger("stevedore.extension").setLevel(logging.CRITICAL)
logging.getLogger("geventwebsocket.handler").setLevel(logging.WARNING)
fh.setLevel(log_level)
logger.addHandler(fh)

View file

@ -37,7 +37,7 @@ if get_proxy_settings()[0] != 'None':
os.environ['HTTPS_PROXY'] = str(proxy)
os.environ['NO_PROXY'] = str(get_proxy_settings()[5])
from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app, hook
from bottle import route, run, template, static_file, request, redirect, response, HTTPError, app, hook, abort
import bottle
bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__), '../views/'))
if "PYCHARM_HOSTED" in os.environ:
@ -46,7 +46,10 @@ if "PYCHARM_HOSTED" in os.environ:
else:
bottle.ERROR_PAGE_TEMPLATE = bottle.ERROR_PAGE_TEMPLATE.replace('if DEBUG and', 'if')
from cherrypy.wsgiserver import CherryPyWSGIServer
from gevent.pywsgi import WSGIServer
from geventwebsocket import WebSocketError
from geventwebsocket.handler import WebSocketHandler
#from cherrypy.wsgiserver import CherryPyWSGIServer
from beaker.middleware import SessionMiddleware
from cork import Cork
@ -1729,14 +1732,28 @@ def test_url(protocol, url):
else:
return dict(status=True, version=result)
@route(base_url + 'websocket')
def handle_websocket():
wsock = request.environ.get('wsgi.websocket')
if not wsock:
abort(400, 'Expected WebSocket request.')
while True:
try:
message = wsock.receive()
wsock.send("Your message was: %r" % message)
except WebSocketError:
break
import warnings
# Mute DeprecationWarning
warnings.simplefilter("ignore", DeprecationWarning)
server = CherryPyWSGIServer((str(ip), int(port)), app)
server = WSGIServer((str(ip), int(port)), app, handler_class=WebSocketHandler)
try:
logging.info('BAZARR is started and waiting for request on http://' + str(ip) + ':' + str(port) + str(base_url))
# print 'Bazarr is started and waiting for request on http://' + str(ip) + ':' + str(port) + str(base_url)
server.start()
server.serve_forever()
except KeyboardInterrupt:
shutdown()

View file

@ -206,4 +206,11 @@
}
});
}
</script>
<script type="text/javascript">
var ws = new WebSocket("ws://" + window.location.host + "{{base_url}}websocket");
ws.onmessage = function (evt) {
console.log(evt.data);
};
</script>