1
0
Fork 0

Integrated vkontakte music search from submodule

This commit is contained in:
Gregory Eremin 2011-09-26 13:58:04 +04:00
parent 8f3de7cac8
commit 023e405563
6 changed files with 10 additions and 65 deletions

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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'

View File

@ -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('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js"></script>')
, 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) ->

@ -1 +1 @@
Subproject commit 1e7ebeb23fc4d0f49ef521323292fdbb378618c6
Subproject commit 26de82ee6b4fa694e56a8f46462d8df1ce9e5e26