From a8ace58b20dc4bf481ba9d0eb96f94cb01944ed0 Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Thu, 23 Jun 2011 04:59:11 +0400 Subject: [PATCH] Scrobbling fixes --- app/controllers/last_fm_controller.rb | 4 ++-- public/javascripts/beathaven/audio.js | 14 +++++++------- public/javascripts/beathaven/player.js | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/last_fm_controller.rb b/app/controllers/last_fm_controller.rb index b5919ee..f6c4091 100644 --- a/app/controllers/last_fm_controller.rb +++ b/app/controllers/last_fm_controller.rb @@ -82,9 +82,9 @@ class LastFmController < ApplicationController lastfm = Lastfm.new(@@api_key, @@secret) lastfm.session = user.lastfm_key - r = lastfm.track.scrobble(params[:artist], params[:track]) + r = lastfm.track.scrobble(params[:artist], params[:track], nil, Time.now.utc.to_i) - render :json => {:status => r ? 'success' : 'failed'} + render :json => {:status => r ? 'success' : 'failed', time: Time.now.utc} return end diff --git a/public/javascripts/beathaven/audio.js b/public/javascripts/beathaven/audio.js index 5260539..f55326f 100644 --- a/public/javascripts/beathaven/audio.js +++ b/public/javascripts/beathaven/audio.js @@ -58,12 +58,12 @@ var Audio = { getListenedPercent: function() { try { - if (Audio.audio.duration < 30) { + if (Audio.audio.duration < 30 || Audio.ttime < 0) { return -1; } return Audio.ttime / 1000 / Audio.audio.duration; } catch(e) {} - return 0; + return -1; }, setPlayedPercent: function(val) { @@ -86,15 +86,15 @@ var Audio = { if (Audio.ttime !== -1) { Audio.ttime += Audio.tinterval; } - var pp = Audio.getListenedPercent(); - if (pp > 0.4) { - Audio.ttime = -1; - } Player.updateUI( Audio.getLoadedPercent(), Audio.getPlayedPercent(), - pp + Audio.getListenedPercent() ); + var pp = Audio.getPlayedPercent(); + if (pp > 0.5) { + Audio.ttime = -1; + } }, killListener: function() { diff --git a/public/javascripts/beathaven/player.js b/public/javascripts/beathaven/player.js index 5adb3d9..42f5849 100644 --- a/public/javascripts/beathaven/player.js +++ b/public/javascripts/beathaven/player.js @@ -74,7 +74,7 @@ var Player = { Audio.killListener(); Player.setTrack(Player.nextTrack()); } - if (listened > 0.4) { + if (played > 0.5 && listened > 0) { var tmp = $('#player .now-playing').text().split(' — '); Player.scrobble(tmp[0], tmp[1]); } @@ -88,11 +88,11 @@ var Player = { }, updateNowListening: function(artist, track) { - Session.query('/lastfm/listening', {'artist': artist, 'track': track}) + Session.query('/lastfm/listening?r='+ Math.random(), {'artist': artist, 'track': track}) }, scrobble: function(artist, track) { - Session.query('/lastfm/scrobble', {'artist': artist, 'track': track}) + Session.query('/lastfm/scrobble?r='+ Math.random(), {'artist': artist, 'track': track}) } }