Integrated vkontakte music search from submodule
This commit is contained in:
parent
8f3de7cac8
commit
023e405563
app/assets/javascripts
@ -1,6 +1,8 @@
|
|||||||
//= require jquery/jquery.autocomplete
|
//= require jquery/jquery.autocomplete
|
||||||
//= require jquery/jplayer/jquery.jplayer/jquery.jplayer
|
//= require jquery/jplayer/jquery.jplayer/jquery.jplayer
|
||||||
|
|
||||||
|
//= require vksearch/src/vkontakte_music
|
||||||
|
|
||||||
//= require locale
|
//= require locale
|
||||||
//= require session
|
//= require session
|
||||||
//= require vkontakte
|
//= require vkontakte
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
window._beathaven = null
|
window._beathaven = null
|
||||||
window._session = null
|
window._session = null
|
||||||
window._vkontakte = null
|
window._vkontakte = null
|
||||||
|
window._vk_music = null
|
||||||
window._ajax = null
|
window._ajax = null
|
||||||
window._player = null
|
window._player = null
|
||||||
window._search = null
|
window._search = null
|
||||||
@ -24,6 +25,7 @@ class window.BeatHaven
|
|||||||
init: ->
|
init: ->
|
||||||
window._vkontakte = new Vkontakte(2335068)
|
window._vkontakte = new Vkontakte(2335068)
|
||||||
window._vkontakte.init()
|
window._vkontakte.init()
|
||||||
|
window._vk_music = new VkontakteMusic
|
||||||
|
|
||||||
window._ajax = new Ajax()
|
window._ajax = new Ajax()
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class window.Player
|
|||||||
$('.player .now-playing').html query
|
$('.player .now-playing').html query
|
||||||
$('.playlist li').removeClass 'now'
|
$('.playlist li').removeClass 'now'
|
||||||
$obj.addClass '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
|
_player.playSource url
|
||||||
this.updateNowListening track
|
this.updateNowListening track
|
||||||
false
|
false
|
||||||
|
@ -20,14 +20,15 @@ class window.Search
|
|||||||
_ajax.setArchor '/artist/' +name+ '/'
|
_ajax.setArchor '/artist/' +name+ '/'
|
||||||
_page.print data.html
|
_page.print data.html
|
||||||
if _session.getUser().id
|
if _session.getUser().id
|
||||||
for album in data.albums
|
if data.albums?
|
||||||
_player.albums[album.id] = album
|
for album in data.albums
|
||||||
|
_player.albums[album.id] = album
|
||||||
$('.button-container').show()
|
$('.button-container').show()
|
||||||
_search.hideSpinner()
|
_search.hideSpinner()
|
||||||
if data.status is 'loading'
|
if data.status is 'loading'
|
||||||
setTimeout () ->
|
setTimeout () ->
|
||||||
_search.loadArtistData name
|
_search.loadArtistData name
|
||||||
, 5000
|
, 10000
|
||||||
else if data.status is 'corrected'
|
else if data.status is 'corrected'
|
||||||
_search.loadArtistData data.correct_name
|
_search.loadArtistData data.correct_name
|
||||||
else if data.status is 'suggestions'
|
else if data.status is 'suggestions'
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
class window.Vkontakte
|
class window.Vkontakte
|
||||||
|
|
||||||
qr: null
|
|
||||||
api_id: null
|
api_id: null
|
||||||
|
|
||||||
constructor: (@api_id) ->
|
constructor: (@api_id) ->
|
||||||
@ -9,14 +8,12 @@ class window.Vkontakte
|
|||||||
@api_id
|
@api_id
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
@qr = {}
|
|
||||||
|
|
||||||
window.vkAsyncInit = ->
|
window.vkAsyncInit = ->
|
||||||
VK.init apiId: _vkontakte.getApiId()
|
VK.init apiId: _vkontakte.getApiId()
|
||||||
VK.Auth.getLoginStatus (response) ->
|
VK.Auth.getLoginStatus (response) ->
|
||||||
_vkontakte.authInfo(response)
|
_vkontakte.authInfo(response)
|
||||||
|
|
||||||
|
|
||||||
setTimeout ->
|
setTimeout ->
|
||||||
$('#vk_api_transport').append('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js"></script>')
|
$('#vk_api_transport').append('<script async="async" type="text/javascript" src="http://vkontakte.ru/js/api/openapi.js"></script>')
|
||||||
, 0
|
, 0
|
||||||
@ -67,63 +64,6 @@ class window.Vkontakte
|
|||||||
false
|
false
|
||||||
, 8
|
, 8
|
||||||
false
|
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', ->
|
$('#login').live 'click', ->
|
||||||
VK.Auth.login (response) ->
|
VK.Auth.login (response) ->
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 1e7ebeb23fc4d0f49ef521323292fdbb378618c6
|
Subproject commit 26de82ee6b4fa694e56a8f46462d8df1ce9e5e26
|
Loading…
x
Reference in New Issue
Block a user