-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
56 lines (40 loc) · 1.18 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
server.py
"""
import os
import server.importer
import sys
sys.path.append(os.path.abspath('server'))
from server.bottle import route, run, request, response, static_file, abort
server.bottle.debug(True)
def web_root():
return os.path.abspath('web')
def server_root():
return os.path.abspath('server')
def samples_dir():
return os.path.abspath('samples')
@route('/')
def index():
return static_file('index.html', root=web_root())
@route('/request_samples')
def request_song():
hash = request.GET.get('id')
if ((hash == None) or (hash.strip() == '')):
hash = server.importer.main(samples_dir())
else:
hash = request.GET.get('id')
return { 'poll_url': '/samples/' + hash, 'source_id': hash, 'metadata_url': '/samples/' + hash + '/metadata.json' }
@route('/samples/:id')
def samples(id):
try:
response.content_type = 'application/json'
return open(os.path.join(samples_dir(), id, 'processed')).read()
except:
abort(404)
@route('/samples/:id/:path')
def sample(id, path):
return static_file(path, root=os.path.join(samples_dir(), id))
@route('/:path#.+#')
def static(path):
return static_file(path, root=web_root())
run(host='localhost', port='8080')