diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2012-03-06 21:58:56 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2012-03-06 21:58:56 +0100 |
commit | 675a2b12a2bfb4e7d1948f68f034d2fb3a7f9424 (patch) | |
tree | a68637eafba8aa466e7910daf8e06f81337edb1a | |
parent | 9e5cafbde816d6c3535fa7d3cc97a3f9c0fe265a (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.
-rwxr-xr-x | app.py | 17 | ||||
-rw-r--r-- | static/playlist.js | 8 | ||||
-rw-r--r-- | static/sound.js | 8 |
3 files changed, 33 insertions, 0 deletions
@@ -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): diff --git a/static/playlist.js b/static/playlist.js index 6f57075..b94de61 100644 --- a/static/playlist.js +++ b/static/playlist.js @@ -39,6 +39,9 @@ $(function(){ item.id = this.current_id; this.current_id++; var model = items.create(item); + if(items.indexOf(model) < 2) { + sound_hint(model); + } }, addOne: function(item) { var view = new PlaylistItemView({model: item}); @@ -60,6 +63,11 @@ $(function(){ items.remove(item); this.render(); return next; + }, + hintnext: function() { + var next = items.at(1); + if(next) + sound_hint(next); } }); diff --git a/static/sound.js b/static/sound.js index 874c213..c4f2dbf 100644 --- a/static/sound.js +++ b/static/sound.js @@ -1,4 +1,5 @@ function playsound(model) { + playlist.hintnext(); var item = model.toJSON(); var id = item.track_id; var cid = model.cid; @@ -51,3 +52,10 @@ function playsound(model) { sound.play(); $('#cid-' + cid).addClass('playing'); } + +function sound_hint(model) { + $('#cid-' + model.cid).addClass('loading'); + $.get('/json/hint/' + model.attributes.track_id, function(data) { + $('#cid-' + model.cid).removeClass('nocache').removeClass('loading'); + }); +} |