Scrobbling fixes
This commit is contained in:
parent
672276d37d
commit
a8ace58b20
|
@ -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
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue