From 675a2b12a2bfb4e7d1948f68f034d2fb3a7f9424 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 6 Mar 2012 21:58:56 +0100 Subject: 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. --- app.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app.py') 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): -- cgit v1.2.3