summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2012-03-06 21:58:56 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2012-03-06 21:58:56 +0100
commit675a2b12a2bfb4e7d1948f68f034d2fb3a7f9424 (patch)
treea68637eafba8aa466e7910daf8e06f81337edb1a /app.py
parent9e5cafbde816d6c3535fa7d3cc97a3f9c0fe265a (diff)
Added hints to tell the server which track we want next.
This lets the server recode the next track behind the scenes while we're listening to the current track.
Diffstat (limited to 'app.py')
-rwxr-xr-xapp.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/app.py b/app.py
index 7d88ebe..6ea7082 100755
--- a/app.py
+++ b/app.py
@@ -38,8 +38,25 @@ class JSONApplication(object):
start_response('200 OK', [('Content-Type', 'application/json'), ('Content-Length', str(len(contents)))])
return [contents]
+ def hint(self, environ, start_response, path):
+ track_id = int(path[1])
+ session = db.Session()
+ try:
+ track = db.Track.get_by_id(session, track_id)
+ cached = self.cache_check(track)
+ finally:
+ session.close()
+
+ if not cached:
+ r = codec.Recoder(track.get_path(), config.get('encoder'), track.file_index, os.path.join(config.get('cache_dir'), str(track.id)))
+ r.recode()
+
+ start_response('200 OK', [('Content-Type', 'application/json')])
+ return [json.dumps({'recoded': not cached})]
+
handlers = {
'list': list,
+ 'hint': hint,
}
def __call__(self, environ, start_response, path):