diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d9cea56..472b857 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,6 +1,8 @@ //= require jquery/jquery.autocomplete //= require jquery/jplayer/jquery.jplayer/jquery.jplayer +//= require vksearch/src/vkontakte_music + //= require locale //= require session //= require vkontakte diff --git a/app/assets/javascripts/beathaven.coffee b/app/assets/javascripts/beathaven.coffee index 3f31d0f..7f8779f 100644 --- a/app/assets/javascripts/beathaven.coffee +++ b/app/assets/javascripts/beathaven.coffee @@ -2,6 +2,7 @@ window._beathaven = null window._session = null window._vkontakte = null +window._vk_music = null window._ajax = null window._player = null window._search = null @@ -24,6 +25,7 @@ class window.BeatHaven init: -> window._vkontakte = new Vkontakte(2335068) window._vkontakte.init() + window._vk_music = new VkontakteMusic window._ajax = new Ajax() diff --git a/app/assets/javascripts/player.coffee b/app/assets/javascripts/player.coffee index 1028749..d32521f 100644 --- a/app/assets/javascripts/player.coffee +++ b/app/assets/javascripts/player.coffee @@ -82,7 +82,7 @@ class window.Player $('.player .now-playing').html query $('.playlist li').removeClass 'now' $obj.addClass 'now' - _vkontakte.loadTracksData track.artist, track.name, track.duration, (url) -> + _vk_music.search track.artist, track.name, track.duration, (url) -> _player.playSource url this.updateNowListening track false diff --git a/app/assets/javascripts/search.coffee b/app/assets/javascripts/search.coffee index decbbc9..507f4c1 100644 --- a/app/assets/javascripts/search.coffee +++ b/app/assets/javascripts/search.coffee @@ -20,14 +20,15 @@ class window.Search _ajax.setArchor '/artist/' +name+ '/' _page.print data.html if _session.getUser().id - for album in data.albums - _player.albums[album.id] = album + if data.albums? + for album in data.albums + _player.albums[album.id] = album $('.button-container').show() _search.hideSpinner() if data.status is 'loading' setTimeout () -> _search.loadArtistData name - , 5000 + , 10000 else if data.status is 'corrected' _search.loadArtistData data.correct_name else if data.status is 'suggestions' diff --git a/app/assets/javascripts/vkontakte.coffee b/app/assets/javascripts/vkontakte.coffee index f9f07fd..1d0d51d 100644 --- a/app/assets/javascripts/vkontakte.coffee +++ b/app/assets/javascripts/vkontakte.coffee @@ -1,6 +1,5 @@ class window.Vkontakte - qr: null api_id: null constructor: (@api_id) -> @@ -9,14 +8,12 @@ class window.Vkontakte @api_id init: -> - @qr = {} window.vkAsyncInit = -> VK.init apiId: _vkontakte.getApiId() VK.Auth.getLoginStatus (response) -> _vkontakte.authInfo(response) - setTimeout -> $('#vk_api_transport').append('') , 0 @@ -67,63 +64,6 @@ class window.Vkontakte false , 8 false - - loadTracksData: (artist, track, duration, callback) -> - track_prepared = track.replace(/\(.*\)/i, '').split('/')[0]; - query = artist+' '+track_prepared; - if url = _vkontakte.getQR query - callback url - else - VK.Api.call 'audio.search', q: query, (r) -> - url = _vkontakte.matchPerfectResult r.response, artist, track, duration - _vkontakte.addQR query, url - callback url - - matchPerfectResult: (data, artist, track, duration) -> - duration = duration.split ':' - duration = parseInt(duration[0], 10) * 60 + parseInt(duration[1], 10) - best_score = 0; - best_result = null; - for item in data - if typeof item is 'object' - score = 0; - item.artist = item.artist.trim(); - item.title = item.title.trim(); - - if item.artist == artist - score += 10 - else if item.artist.split(artist).length is 2 - score += 5 - else if item.title.split(artist).length is 2 - score += 4 - - if item.title == track - score += 10 - else if item.title.split(track).length is 2 - score += 5 - - if parseInt(item.duration, 10) == duration - score += 15 - else - delta = Math.abs parseInt(item.duration, 10) - duration - score += (10 - delta) if delta < 10 - - if score > best_score - best_score = score - best_result = item - - if score is 35 - return best_result.url - - return best_result.url - - addQR: (query, url) -> - _vkontakte.qr[query] = url; - - getQR: (query) -> - if _vkontakte.qr[query]? - _vkontakte.qr[query] - false $('#login').live 'click', -> VK.Auth.login (response) -> diff --git a/app/assets/javascripts/vksearch b/app/assets/javascripts/vksearch index 1e7ebeb..26de82e 160000 --- a/app/assets/javascripts/vksearch +++ b/app/assets/javascripts/vksearch @@ -1 +1 @@ -Subproject commit 1e7ebeb23fc4d0f49ef521323292fdbb378618c6 +Subproject commit 26de82ee6b4fa694e56a8f46462d8df1ce9e5e26