total cleanup

This commit is contained in:
magnolia-fan
2011-06-13 16:54:56 +04:00
parent 1d9a0398c6
commit 447239f824
49 changed files with 571 additions and 1854 deletions
@@ -1,6 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
require 'beatdb'
require 'pp'
#require 'cobravsmongoose'
end
-5
View File
@@ -1,5 +0,0 @@
class ErrorsController < ApplicationController
def routing
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
-16
View File
@@ -1,18 +1,2 @@
module ApplicationHelper
def navigation
end
end
class Numeric
def toSeconds
(self / 1000).round
end
def toTime
s = self.toSeconds
m = (s / 60).floor
s -= m * 60
m.to_s << ':' << (s < 10 ? '0' : '') << s.to_s
end
end
-98
View File
@@ -1,98 +0,0 @@
module Vkontakte
require 'uri'
require 'net/http'
require 'erb'
require 'pp'
#require 'nokogiri'
@@accounts = YAML.load_file("#{Rails.root.to_s}/config/vk_accounts.yml")
@@bot = nil
def self.get(artist, track, length)
self.randomBot()
html = self.getHtml(artist << ' - ' << track).force_encoding("WINDOWS-1251").encode("UTF-8")
files = self.parseHtml(html)
files = self.calcWeight(files, artist, track, length)
return {
'url' => files.first['url'],
'remixsid' => @@bot['remixsid'],
'remixchk' => @@bot['remixchk']
}
end
private
def self.randomBot()
botname = @@accounts.keys[rand(@@accounts.keys.length - 1)]
@@bot = @@accounts[botname]
pp 'Using bot ' << botname
end
def self.getHtml(q)
headers = {
'Cookie' => 'remixsid='+ @@bot['remixsid'] + ';remixchk='+ @@bot['remixchk'].to_s,
'Referer' => 'http://vkontakte.ru/audio?album_id=0',
'X-Requested-With' => 'XMLHttpRequest',
'Origin' => 'http://vkontakte.ru',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => @@bot['user_agent'],
'Connection' => 'close'
}
data = {
'act' => 'search',
'al' => 1,
'gid' => 0,
'id' => @@bot['user_id'],
'offset' => 0,
'q' => q,
'sort' => 2
}
data_str = []
data.each {|k, v| data_str << k +'='+ ERB::Util.url_encode(v.to_s)}
http = Net::HTTP.new('vkontakte.ru', 80)
resp, data = http.post('/audio', data_str.join('&'), headers)
data
end
def self.parseHtml(html)
files = []
html
.scan(/<table.*?<input.*?value=\"(.*?)\,\d{1,4}\".*?>.*?<div\sclass=\"duration.*?>(.*?)<\/div>.*?<div\sclass=\"title_wrap\".*?>.*?selectPerformer\(event\,\s\'(.*?)\'\).*?<span\sclass=\"title\">(.*?)<\/span><\/div>.*?<\/table>/mi)
.each do |item|
t = item[1].split(':')
files << {
'url' => item[0],
'length' => (t[0].to_i * 60) + t[1].to_i,
'artist' => item[2],
'track' => item[3].gsub(/<.*?>/, '')
}
end
files
end
def self.calcWeight(files, artist, track, length)
files.each do |file|
weight = 0
if file['artist'] == artist then weight += 10 else
if file['artist'].include? artist then weight += 5 else
if file['track'].include? artist then weight += 4
end end end
if file['track'] == track then weight += 10 else
if file['track'].include? track then weight += 5
end end
if file['length'] == length then weight +=10 else
delta = (length - file['length']).abs
if delta < 5 then weight += (5 - delta) end
end
file['weight'] = weight
end
files.sort_by{|file| file['weight']}.reverse
end
end
+7 -50
View File
@@ -1,57 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>BeatHaven</title>
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :all %>
<%= csrf_meta_tag %>
<title>Beathaven</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<div id="nav">
<ul>
<li><a href="/">Search</a></li>
<li><a href="/user/profile">Profile</a></li>
<li><a href="/logout">Logout</a></li>
</ul>
</div>
<% if @hide_player.nil? -%>
<div id="player">
<div id="audiobox"></div>
<div class="prev" title="Play Previous Track"><img src="/images/player/prev.svg" alt="prv" /></div>
<div class="play" title="Play"><img src="/images/player/play.svg" alt="ply" /></div>
<div class="pause" title="Pause" style="display:none"><img src="/images/player/pause.svg" alt="pause" /></div>
<div class="next" title="Play Next Track"><img src="/images/player/next.svg" alt="pse" /></div>
<div class="time-played">0:00</div>
<div class="progress">
<div class="track-title">No track</div>
<div class="progress-bar">
<div class="progress-loaded">
<div title="Drag It Now!" class="progress-point"></div>
</div>
</div>
</div>
<div class="time-left">0:00</div>
<div title="Play Tracks In Random Order" class="shuffle"><img src="/images/player/shuffle.svg" alt="shu" /></div>
<div title="Repeat Playlist" class="repeat"><img src="/images/player/repeat.svg" alt="rep" /></div>
<div title="Show/Hide Playlist" class="playlist">
<img src="/images/player/playlist.svg" alt="pls" />
<div class="count">0</div>
</div>
</div>
<div id="playlist">
<ul class="list"></ul>
</div>
<div class="corner-fix left"></div>
<div class="corner-fix right"></div>
<%- end %>
<div id="contents">
<div class="inner-1">
<%= yield %>
</div>
</div>
<%= yield %>
</body>
</html>