A web-based tool for making rough sketches of songs with a primitive multitracker
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

107 lines
3.8 KiB

#!/usr/bin/env python
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornado.httpclient
import tornado.httpserver
import tornado.gen
import os
from datetime import datetime
# import random
# import shutil
# import json
# import multiprocessing
#
# Tornado handlers
#
class HomeHandler(tornado.web.RequestHandler):
def get(self):
self.render('song-sketcher.html')
class UploadHandler(tornado.web.RequestHandler):
def post(self):
recording = self.request.files['recording'][0]
original_filename = recording['filename']
# TODO Actually look at what type the file is!
outputFilename = ('output/' + original_filename +
datetime.now().strftime("_%Y_%m_%d_%H_%M_%S") + '.ogg')
output_file = open(outputFilename, 'wb')
output_file.write(recording['body'])
print('File ' + outputFilename + ' uploaded')
self.finish('File ' + outputFilename + ' uploaded')
#
# Startup
#
def make_app():
return tornado.web.Application([
# Home page
(r'/', HomeHandler),
# # Configure the script
# (r'/settings', SettingsHandler),
# # Handles messages for run script
# (r'/runScriptWebSocket', RunScriptWebSocket),
# # Handles messages for randomImageBrowser
# (r'/randomImageBrowserWebSocket', RandomImageBrowserWebSocket),
# Upload handler
(r'/upload', UploadHandler),
# # Don't change this 'output' here without changing the other places as well
(r'/output/(.*)', tornado.web.StaticFileHandler, {'path' : 'output'}),
# Static files. Keep this at the bottom because it handles everything else
# TODO put these in a subdir so everything isn't accessible
(r'/webResources/(.*)', tornado.web.StaticFileHandler, {'path' : 'webResources'}),
],
xsrf_cookies=True,
cookie_secret='dooblydoo')
if __name__ == '__main__':
print('\n\tWARNING: Do NOT run this server on the internet (e.g. port-forwarded)'
' nor when\n\t connected to an insecure LAN! It is not protected against malicious use.\n')
port = 8888
print('\nStarting Song Sketcher Server on port {}...'.format(port))
app = make_app()
#
# Notes on SSL
#
# Certificate generation (for localhost) (didn't actually work):
# https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec?gi=bd966500e56a
# Tornado instructions:
# https://stackoverflow.com/questions/18307131/how-to-create-https-tornado-server
# Note that I added the rootCA to Certificates trust in Firefox Preferences as well (didn't do anything)
#
# What I actually did:
# openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout certificates/server_jupyter_based.crt.key -out certificates/server_jupyter_based.crt.pem
# (from https://jupyter-notebook.readthedocs.io/en/latest/public_server.html)
# I then had to tell Firefox to truse this certificate even though it is self-signing (because
# I want a free certificate for this non-serious project)
useSSL = True
if useSSL:
app.listen(port, ssl_options={"certfile":"certificates/server_jupyter_based.crt.pem",
"keyfile":"certificates/server_jupyter_based.crt.key"})
else:
# The problem with non-ssl version is that Firefox will ask every time whether it can use
# the microphone, which gets everything out of sync
app.listen(port)
ioLoop = tornado.ioloop.IOLoop.current()
# updateStatusCallback = tornado.ioloop.PeriodicCallback(updateScriptStatus, 100)
# updateStatusCallback.start()
ioLoop.start()