1
0
Fork 0

Scrobble and length fix

This commit is contained in:
Gregory Eremin 2011-10-12 13:33:25 +04:00
parent 0ec0b14172
commit 99fc62cde9
3 changed files with 14 additions and 13 deletions

View File

@ -83,6 +83,7 @@ class window.Player
$obj.addClass 'now'
_vk_music.search track.artist, track.name, track.duration, (audio) ->
_player.playSource audio.url
console.log(track)
if track.length == 0
len = parseInt(audio.duration, 10)
duration = Math.floor(len / 60)+':'+(len - Math.floor(len / 60) * 60)
@ -117,17 +118,17 @@ class window.Player
nextTrack: (manual) ->
manual = manual?
cnt = $('.playlist li').length
if not this.onShuffle() # Shuffle off
if $('.playlist .now').next().length == 0 # Last track and repeat is on
if _player.onRepeat() or manual # Repeat or manual click
if not this.onShuffle() # Shuffle off
if $('.playlist .now').next().length == 0 # Last track and repeat is on
if _player.onRepeat() or manual # Repeat or manual click
return $('.playlist li').first().attr('id').split('i')[1]
else
false
else
return $('.playlist .now').next().attr('id').split('i')[1]
else if cnt == 1 # Single track in the playlist
else if cnt == 1 # Single track in the playlist
return $('.playlist li').first().attr('id').split('i')[1]
else # Shuffle on
else # Shuffle on
while true
rnd = Math.floor(Math.random() * (cnt + .999))
$li = $('.playlist li').eq rnd
@ -137,14 +138,14 @@ class window.Player
prevTrack: ->
cnt = $('.playlist li').length
if not _player.onShuffle() # Shuffle off
if $('.playlist .now').prev().length == 0 # First track in the playlist
if not _player.onShuffle() # Shuffle off
if $('.playlist .now').prev().length == 0 # First track in the playlist
return $('.playlist li').last().attr('id').split('i')[1]
else
return $('.playlist .now').prev().attr('id').split('i')[1]
else if cnt == 1 # Single track in the playlist
else if cnt == 1 # Single track in the playlist
return $('.playlist li').first().attr('id').split('i')[1]
else # Shuffle on
else # Shuffle on
while true
rnd = Math.floor(Math.random() * (cnt + .999))
$li = $('.playlist li').eq rnd

View File

@ -94,7 +94,7 @@ class ArtistController < ApplicationController
tmp_album = {:id => album.id, :name => album.name, :year => album.year, :pic => album.pic_url, :tracks => []}
album.tracks.each do |track|
tmp_track = {id: track.id, name: track.name, live: track.live, acoustic: track.acoustic}
tmp_track[:length] = (track.length / 1000).round unless track.length.nil?
tmp_track[:length] = track.length unless track.length.nil?
tmp_track[:duration] = formatTrackDuration(track.length)
tmp_track[:position] = track.position.to_s 36
# tmp_track[:mbid] = track.mbid

View File

@ -59,13 +59,13 @@ class LastFmController < ApplicationController
:track => params[:name],
:artist => params[:artist],
:album => params[:album],
:trackNumber => params[:position],
:trackNumber => params[:position].to_i,
# :mbid => params[:mbid],
:duration => params[:length],
:duration => params[:length].to_i,
:sk => user.lastfm_key # Auth session key
)
render :json => { :status => r['error'].nil? ? 'success' : 'failed' }
render :json => { :status => r['error'].nil? ? 'success' : r }
return
end