From 99fc62cde94de4dd88ee75a8c249a100265e2365 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Wed, 12 Oct 2011 13:33:25 +0400 Subject: [PATCH] Scrobble and length fix --- app/assets/javascripts/player.coffee | 19 ++++++++++--------- app/controllers/artist_controller.rb | 2 +- app/controllers/last_fm_controller.rb | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/player.coffee b/app/assets/javascripts/player.coffee index 5e2bc8c..28a8321 100644 --- a/app/assets/javascripts/player.coffee +++ b/app/assets/javascripts/player.coffee @@ -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 diff --git a/app/controllers/artist_controller.rb b/app/controllers/artist_controller.rb index 247a3cf..89246a8 100644 --- a/app/controllers/artist_controller.rb +++ b/app/controllers/artist_controller.rb @@ -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 diff --git a/app/controllers/last_fm_controller.rb b/app/controllers/last_fm_controller.rb index b4e8a1a..49f5a76 100644 --- a/app/controllers/last_fm_controller.rb +++ b/app/controllers/last_fm_controller.rb @@ -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