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 = Lastfm.new(@@api_key, @@secret)
|
||||||
lastfm.session = user.lastfm_key
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,12 @@ var Audio = {
|
||||||
|
|
||||||
getListenedPercent: function() {
|
getListenedPercent: function() {
|
||||||
try {
|
try {
|
||||||
if (Audio.audio.duration < 30) {
|
if (Audio.audio.duration < 30 || Audio.ttime < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return Audio.ttime / 1000 / Audio.audio.duration;
|
return Audio.ttime / 1000 / Audio.audio.duration;
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
return 0;
|
return -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
setPlayedPercent: function(val) {
|
setPlayedPercent: function(val) {
|
||||||
|
@ -86,15 +86,15 @@ var Audio = {
|
||||||
if (Audio.ttime !== -1) {
|
if (Audio.ttime !== -1) {
|
||||||
Audio.ttime += Audio.tinterval;
|
Audio.ttime += Audio.tinterval;
|
||||||
}
|
}
|
||||||
var pp = Audio.getListenedPercent();
|
|
||||||
if (pp > 0.4) {
|
|
||||||
Audio.ttime = -1;
|
|
||||||
}
|
|
||||||
Player.updateUI(
|
Player.updateUI(
|
||||||
Audio.getLoadedPercent(),
|
Audio.getLoadedPercent(),
|
||||||
Audio.getPlayedPercent(),
|
Audio.getPlayedPercent(),
|
||||||
pp
|
Audio.getListenedPercent()
|
||||||
);
|
);
|
||||||
|
var pp = Audio.getPlayedPercent();
|
||||||
|
if (pp > 0.5) {
|
||||||
|
Audio.ttime = -1;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
killListener: function() {
|
killListener: function() {
|
||||||
|
|
|
@ -74,7 +74,7 @@ var Player = {
|
||||||
Audio.killListener();
|
Audio.killListener();
|
||||||
Player.setTrack(Player.nextTrack());
|
Player.setTrack(Player.nextTrack());
|
||||||
}
|
}
|
||||||
if (listened > 0.4) {
|
if (played > 0.5 && listened > 0) {
|
||||||
var tmp = $('#player .now-playing').text().split(' — ');
|
var tmp = $('#player .now-playing').text().split(' — ');
|
||||||
Player.scrobble(tmp[0], tmp[1]);
|
Player.scrobble(tmp[0], tmp[1]);
|
||||||
}
|
}
|
||||||
|
@ -88,11 +88,11 @@ var Player = {
|
||||||
},
|
},
|
||||||
|
|
||||||
updateNowListening: function(artist, track) {
|
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) {
|
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