Update track length in db if empty. Closes #107
This commit is contained in:
parent
20ee424e7f
commit
0ec0b14172
1
Gemfile
1
Gemfile
|
@ -1,6 +1,5 @@
|
||||||
source 'http://rubygems.org'
|
source 'http://rubygems.org'
|
||||||
|
|
||||||
gem 'rack', '1.3.3'
|
|
||||||
gem 'rails', '3.1.0'
|
gem 'rails', '3.1.0'
|
||||||
gem 'unicorn'
|
gem 'unicorn'
|
||||||
|
|
||||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -66,13 +66,13 @@ GEM
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.16)
|
mime-types (1.16)
|
||||||
multi_json (1.0.3)
|
multi_json (1.0.3)
|
||||||
musicbrainz (0.4.10)
|
musicbrainz (0.5.0)
|
||||||
nokogiri
|
nokogiri
|
||||||
mysql2 (0.3.7)
|
mysql2 (0.3.7)
|
||||||
nokogiri (1.5.0)
|
nokogiri (1.5.0)
|
||||||
pg (0.11.0)
|
pg (0.11.0)
|
||||||
polyglot (0.3.2)
|
polyglot (0.3.2)
|
||||||
rack (1.3.3)
|
rack (1.3.4)
|
||||||
rack-cache (1.0.3)
|
rack-cache (1.0.3)
|
||||||
rack (>= 0.4)
|
rack (>= 0.4)
|
||||||
rack-mount (0.8.3)
|
rack-mount (0.8.3)
|
||||||
|
@ -98,13 +98,14 @@ GEM
|
||||||
thor (~> 0.14.6)
|
thor (~> 0.14.6)
|
||||||
raindrops (0.7.0)
|
raindrops (0.7.0)
|
||||||
rake (0.9.2)
|
rake (0.9.2)
|
||||||
rdoc (3.9.4)
|
rdoc (3.10)
|
||||||
sass (3.1.8)
|
json (~> 1.4)
|
||||||
|
sass (3.1.10)
|
||||||
sprockets (2.0.2)
|
sprockets (2.0.2)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
therubyracer (0.9.5)
|
therubyracer (0.9.8)
|
||||||
libv8 (~> 3.3.10)
|
libv8 (~> 3.3.10)
|
||||||
thor (0.14.6)
|
thor (0.14.6)
|
||||||
tilt (1.3.3)
|
tilt (1.3.3)
|
||||||
|
@ -135,7 +136,6 @@ DEPENDENCIES
|
||||||
mysql2 (= 0.3.7)
|
mysql2 (= 0.3.7)
|
||||||
nokogiri
|
nokogiri
|
||||||
pg
|
pg
|
||||||
rack (= 1.3.3)
|
|
||||||
rails (= 3.1.0)
|
rails (= 3.1.0)
|
||||||
sass
|
sass
|
||||||
therubyracer
|
therubyracer
|
||||||
|
|
|
@ -81,8 +81,16 @@ 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'
|
||||||
_vk_music.search track.artist, track.name, track.duration, (url) ->
|
_vk_music.search track.artist, track.name, track.duration, (audio) ->
|
||||||
_player.playSource url
|
_player.playSource audio.url
|
||||||
|
if track.length == 0
|
||||||
|
len = parseInt(audio.duration, 10)
|
||||||
|
duration = Math.floor(len / 60)+':'+(len - Math.floor(len / 60) * 60)
|
||||||
|
_session.query '/track/update_length', { track_id: track.id, length: len }, (r) ->
|
||||||
|
if r.result is 'success'
|
||||||
|
$('.playlist li[data-id="'+track.id+'"] .song-duration').text(duration)
|
||||||
|
$($('.album div[data-id="'+track.id+'"]').siblings()[0]).text(duration)
|
||||||
|
|
||||||
this.updateNowListening track
|
this.updateNowListening track
|
||||||
false
|
false
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
Copyright (c) 2011 Gregory Eremin
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
@ -1,28 +0,0 @@
|
||||||
# Vkontakte (VK.com) API music search tool
|
|
||||||
|
|
||||||
Don't forget to log in to [vk.com API](http://vk.com/developers.php?oid=-17680044&p=Open_API)
|
|
||||||
|
|
||||||
### CoffeeScript example
|
|
||||||
```coffeescript
|
|
||||||
vk_music = new VkontakteMusic
|
|
||||||
vk_music.search "Kasabian", "L.S.F. (Lost Souls Forever)", "2:17", (url) ->
|
|
||||||
audio = document.createElement "audio"
|
|
||||||
audio.setAttribute "src", url
|
|
||||||
document.getElementsByTagName("body")[0].appendChild audio
|
|
||||||
audio.play()
|
|
||||||
false
|
|
||||||
```
|
|
||||||
|
|
||||||
### JavaScript example
|
|
||||||
```javascript
|
|
||||||
var vk_music;
|
|
||||||
vk_music = new VkontakteMusic;
|
|
||||||
vk_music.search("Kasabian", "L.S.F. (Lost Souls Forever)", "2:17", function(url) {
|
|
||||||
var audio;
|
|
||||||
audio = document.createElement("audio");
|
|
||||||
audio.setAttribute("src", url);
|
|
||||||
document.getElementsByTagName("body")[0].appendChild(audio);
|
|
||||||
audio.play();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
```
|
|
|
@ -1,9 +0,0 @@
|
||||||
/*
|
|
||||||
* Vkontakte (VK.com) API music search tool
|
|
||||||
* https://github.com/magnolia-fan/vkontakte_music_search
|
|
||||||
*
|
|
||||||
* Copyright 2011, Gregory Eremin
|
|
||||||
* Licensed under the MIT license.
|
|
||||||
* https://raw.github.com/magnolia-fan/vkontakte_music_search/master/LICENSE
|
|
||||||
*/
|
|
||||||
var VkontakteMusic;VkontakteMusic=function(){function a(){}return a.prototype.query_results={},a.prototype.search=function(a,b,c,d,e){var f,g;return e==null&&(e=!1),f=this.prepareQuery(a,b),this.query_results[f]!=null&&!e&&d(this.query_results[f]),g=this,VK.Api.call("audio.search",{q:f},function(h){var i,j;return i=g.range(h.response,a,b,c),j=null,i.length>0&&(j=i[0].url),g.query_results[f]=i,d(e?i:j)})},a.prototype.range=function(a,b,c,d){var e,f,g,h,i;typeof d=="string"&&(d=d.split(":"),d=parseInt(d[0],10)*60+parseInt(d[1],10));for(f=0,i=a.length;f<i;f++){g=a[f];if(typeof g!="object")continue;g.score=0,g.artist=this.trim(g.artist),g.title=this.trim(g.title),h=0,g.artist.length>0&&(g.artist===b?h+=10:g.artist.split(b).length===2?h+=5:g.title.split(b).length===2&&(h+=4)),g.artist.length>0&&(g.title===c?h+=10:g.title.split(c).length===2&&(h+=5)),parseInt(g.duration,10)===d?h+=15:(e=Math.abs(parseInt(g.duration,10)-d),e<10&&(h+=10-e)),a[f].score=h}return a.length>0&&typeof a[0]!="object"&&(a.splice(0,1),a.sort(function(a,b){return b.score-a.score})),a},a.prototype.prepareQuery=function(a,b){return a+" "+b.replace(/\(.*\)/i,"").split("/")[0]},a.prototype.trim=function(a){while(a.indexOf(" ")!==-1)a=a.replace(" "," ");return a.charAt(0)===" "&&(a=a.substring(1)),a.charAt(a.length-1)===" "&&(a=a.substring(0,a.length-1)),a},a}()
|
|
|
@ -1,70 +0,0 @@
|
||||||
###
|
|
||||||
* Vkontakte (VK.com) API music search tool
|
|
||||||
* https://github.com/magnolia-fan/vkontakte_music_search
|
|
||||||
*
|
|
||||||
* Copyright 2011, Gregory Eremin
|
|
||||||
* Licensed under the MIT license.
|
|
||||||
* https://raw.github.com/magnolia-fan/vkontakte_music_search/master/LICENSE
|
|
||||||
###
|
|
||||||
class window.VkontakteMusic
|
|
||||||
query_results: {}
|
|
||||||
|
|
||||||
search: (artist, track, duration, callback, return_all = false) ->
|
|
||||||
query = this.prepareQuery artist, track
|
|
||||||
if @query_results[query]? and not return_all
|
|
||||||
callback @query_results[query]
|
|
||||||
that = this
|
|
||||||
VK.Api.call 'audio.search', q: query, (r) ->
|
|
||||||
results = that.range r.response, artist, track, duration
|
|
||||||
top_result = null
|
|
||||||
if results.length > 0
|
|
||||||
top_result = results[0].url
|
|
||||||
that.query_results[query] = results
|
|
||||||
callback if return_all then results else top_result
|
|
||||||
|
|
||||||
range: (data, artist, track, duration) ->
|
|
||||||
if typeof duration is 'string'
|
|
||||||
duration = duration.split ':'
|
|
||||||
duration = parseInt(duration[0], 10) * 60 + parseInt(duration[1], 10)
|
|
||||||
for item, i in data
|
|
||||||
if typeof item isnt 'object'
|
|
||||||
continue
|
|
||||||
item.score = 0;
|
|
||||||
item.artist = this.trim(item.artist);
|
|
||||||
item.title = this.trim(item.title);
|
|
||||||
score = 0
|
|
||||||
if item.artist.length > 0
|
|
||||||
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.artist.length > 0
|
|
||||||
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
|
|
||||||
data[i].score = score
|
|
||||||
if data.length > 0 and typeof data[0] isnt 'object'
|
|
||||||
data.splice 0, 1
|
|
||||||
data.sort (a, b) ->
|
|
||||||
b.score - a.score
|
|
||||||
data
|
|
||||||
|
|
||||||
prepareQuery: (artist, track) ->
|
|
||||||
artist+" "+track.replace(/\(.*\)/i, '').split('/')[0]
|
|
||||||
|
|
||||||
trim: (str) ->
|
|
||||||
while str.indexOf(' ') isnt -1
|
|
||||||
str = str.replace ' ', ' '
|
|
||||||
if str.charAt(0) is ' '
|
|
||||||
str = str.substring 1
|
|
||||||
if str.charAt(str.length - 1) is ' '
|
|
||||||
str = str.substring 0, str.length - 1
|
|
||||||
str
|
|
|
@ -18,7 +18,7 @@ class window.VkontakteMusic
|
||||||
results = that.range r.response, artist, track, duration
|
results = that.range r.response, artist, track, duration
|
||||||
top_result = null
|
top_result = null
|
||||||
if results.length > 0
|
if results.length > 0
|
||||||
top_result = results[0].url
|
top_result = results[0]
|
||||||
that.query_results[query] = results
|
that.query_results[query] = results
|
||||||
callback if return_all then results else top_result
|
callback if return_all then results else top_result
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ class window.VkontakteMusic
|
||||||
for item, i in data
|
for item, i in data
|
||||||
if typeof item isnt 'object'
|
if typeof item isnt 'object'
|
||||||
continue
|
continue
|
||||||
item.score = 0;
|
item.score = 0
|
||||||
item.artist = this.trim(item.artist);
|
item.artist = this.trim(item.artist)
|
||||||
item.title = this.trim(item.title);
|
item.title = this.trim(item.title)
|
||||||
score = 0
|
score = 0
|
||||||
if item.artist.length > 0
|
if item.artist.length > 0
|
||||||
if item.artist == artist
|
if item.artist == artist
|
||||||
|
@ -45,14 +45,15 @@ class window.VkontakteMusic
|
||||||
score += 10
|
score += 10
|
||||||
else if item.title.split(track).length is 2
|
else if item.title.split(track).length is 2
|
||||||
score += 5
|
score += 5
|
||||||
if parseInt(item.duration, 10) == duration
|
if duration != 0 and parseInt(item.duration, 10) == duration
|
||||||
score += 15
|
score += 15
|
||||||
else
|
else
|
||||||
delta = Math.abs parseInt(item.duration, 10) - duration
|
delta = Math.abs parseInt(item.duration, 10) - duration
|
||||||
score += (10 - delta) if delta < 10
|
score += (10 - delta) if delta < 10
|
||||||
data[i].score = score
|
data[i].score = score
|
||||||
if data.length > 0 and typeof data[0] isnt 'object'
|
if data.length > 0
|
||||||
data.splice 0, 1
|
if typeof data[0] isnt 'object'
|
||||||
|
data.splice(0, 1)
|
||||||
data.sort (a, b) ->
|
data.sort (a, b) ->
|
||||||
b.score - a.score
|
b.score - a.score
|
||||||
data
|
data
|
||||||
|
@ -62,9 +63,9 @@ class window.VkontakteMusic
|
||||||
|
|
||||||
trim: (str) ->
|
trim: (str) ->
|
||||||
while str.indexOf(' ') isnt -1
|
while str.indexOf(' ') isnt -1
|
||||||
str = str.replace ' ', ' '
|
str = str.replace(' ', ' ')
|
||||||
if str.charAt(0) is ' '
|
if str.charAt(0) is ' '
|
||||||
str = str.substring 1
|
str = str.substring(1)
|
||||||
if str.charAt(str.length - 1) is ' '
|
if str.charAt(str.length - 1) is ' '
|
||||||
str = str.substring 0, str.length - 1
|
str = str.substring(0, str.length - 1)
|
||||||
str
|
str
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
class TrackController < ApplicationController
|
||||||
|
before_filter :authorize
|
||||||
|
|
||||||
|
def update_length
|
||||||
|
unless params[:track_id].nil?
|
||||||
|
track = Track.find(params[:track_id])
|
||||||
|
unless track.nil? or params[:length].nil?
|
||||||
|
if track.length == nil or track.length.to_i == 0 and params[:length].to_i > 0
|
||||||
|
track.length = params[:length].to_i
|
||||||
|
track.save
|
||||||
|
render :json => { :result => :success }
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
render :json => { :result => :failed }
|
||||||
|
end
|
||||||
|
end
|
|
@ -68,6 +68,8 @@ Beathaven::Application.routes.draw do
|
||||||
match 'lastfm/listening' => 'last_fm#listening'
|
match 'lastfm/listening' => 'last_fm#listening'
|
||||||
match 'lastfm/scrobble' => 'last_fm#scrobble'
|
match 'lastfm/scrobble' => 'last_fm#scrobble'
|
||||||
|
|
||||||
|
match 'track/update_length' => 'track#update_length'
|
||||||
|
|
||||||
match 'settings' => 'user#settings'
|
match 'settings' => 'user#settings'
|
||||||
|
|
||||||
match 'artist/autocomplete' => 'artist#autocomplete'
|
match 'artist/autocomplete' => 'artist#autocomplete'
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
worker_processes 1;
|
|
||||||
error_log logs/error.log debug;
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
default_type application/octet-stream;
|
|
||||||
sendfile on;
|
|
||||||
#tcp_nopush on;
|
|
||||||
keepalive_timeout 65;
|
|
||||||
tcp_nodelay on;
|
|
||||||
|
|
||||||
gzip on;
|
|
||||||
gzip_min_length 1100;
|
|
||||||
gzip_buffers 4 8k;
|
|
||||||
gzip_types text/plain;
|
|
||||||
|
|
||||||
upstream mongrel {
|
|
||||||
server 127.0.0.1:3000;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name bh.vim.me localhost susanna brooklyn;
|
|
||||||
#root /Users/chez/Sites;
|
|
||||||
#index index.html index.htm;
|
|
||||||
|
|
||||||
try_files $uri @mongrel;
|
|
||||||
|
|
||||||
location @mongrel {
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header Host $http_host;
|
|
||||||
proxy_redirect off;
|
|
||||||
proxy_pass http://mongrel;
|
|
||||||
}
|
|
||||||
|
|
||||||
include proxy.conf;
|
|
||||||
|
|
||||||
#error_page 500 502 503 504 /50x.html;
|
|
||||||
location = /50x.html {
|
|
||||||
root html;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
# Proxy download
|
|
||||||
location ~* ^/proxy-stream/(.*?)/(.*?)/(.*?)/(.*?)/(.*) {
|
|
||||||
# Do not allow people to mess with this location directly
|
|
||||||
# Only internal redirects are allowed
|
|
||||||
internal;
|
|
||||||
|
|
||||||
# Location-specific logging
|
|
||||||
#access_log logs/proxy_stream.access.log debug;
|
|
||||||
#error_log logs/proxy_stream.error.log debug;
|
|
||||||
|
|
||||||
# Extract download url from the request
|
|
||||||
set $token $1;
|
|
||||||
set $remixsid $2;
|
|
||||||
set $remixchk $3;
|
|
||||||
set $download_host $4;
|
|
||||||
set $download_uri $5;
|
|
||||||
|
|
||||||
# Compose download url
|
|
||||||
set $download_url http://$download_host/$download_uri;
|
|
||||||
|
|
||||||
# Compose cookie string
|
|
||||||
set $cookie "remixsid=$remixsid;remixchk=$remixchk";
|
|
||||||
|
|
||||||
# Set download request headers
|
|
||||||
proxy_set_header Host $download_host;
|
|
||||||
proxy_set_header Cookie $cookie;
|
|
||||||
proxy_set_header Referer "http://vkontakte.ru/audio?album_id=0";
|
|
||||||
|
|
||||||
# The next two lines could be used if your storage
|
|
||||||
# backend does not support Content-Disposition
|
|
||||||
# headers used to specify file name browsers use
|
|
||||||
# when save content to the disk
|
|
||||||
proxy_ignore_headers Cache-Control Expires;
|
|
||||||
|
|
||||||
|
|
||||||
# Do not touch local disks when proxying
|
|
||||||
# content to clients
|
|
||||||
proxy_max_temp_file_size 0;
|
|
||||||
|
|
||||||
# Download the file and send it to client
|
|
||||||
resolver 192.168.0.1;
|
|
||||||
proxy_pass $download_url;
|
|
||||||
}
|
|
Loading…
Reference in New Issue