Tons of fixes
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
module ApplicationHelper
|
||||
def navigation
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class Numeric
|
||||
|
||||
+11
-29
@@ -2,38 +2,34 @@ 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
|
||||
def self.get(artist, track, length)
|
||||
self.randomBot()
|
||||
html = self.getHtml(artist << ' - ' << track).force_encoding("WINDOWS-1251").encode("UTF-8")
|
||||
#pp html.encoding
|
||||
#File.open('/Users/chez/Sites/beathaven/tmp/vkres1.html', 'w') {|f| f.write(html) }
|
||||
#html = open('/Users/chez/Sites/beathaven/tmp/vkres1.html').read
|
||||
files = self.parseHtml(html)
|
||||
files = self.calcWeight(files, artist, track, length)
|
||||
#self.stream files.first['url']
|
||||
|
||||
files = self.calcWeight(files, artist, track, length)
|
||||
return {
|
||||
'url' => files.first['url'],
|
||||
'remixsid' => @@bot['remixsid'],
|
||||
'remixchk' => @@bot['remixchk']
|
||||
'url' => files.first['url'],
|
||||
'remixsid' => @@bot['remixsid'],
|
||||
'remixchk' => @@bot['remixchk']
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def self.randomBot
|
||||
def self.randomBot()
|
||||
botname = @@accounts.keys[rand(@@accounts.keys.length - 1)]
|
||||
@@bot = @@accounts[botname]
|
||||
pp 'Using bot ' << botname
|
||||
end
|
||||
|
||||
def self.getHtml q
|
||||
def self.getHtml(q)
|
||||
headers = {
|
||||
'Cookie' => 'remixsid='+ @@bot['remixsid'] + ';remixchk='+ @@bot['remixchk'].to_s,
|
||||
'Referer' => 'http://vkontakte.ru/audio?album_id=0',
|
||||
@@ -60,7 +56,7 @@ module Vkontakte
|
||||
data
|
||||
end
|
||||
|
||||
def self.parseHtml html
|
||||
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)
|
||||
@@ -76,7 +72,7 @@ module Vkontakte
|
||||
files
|
||||
end
|
||||
|
||||
def self.calcWeight files, artist, track, length
|
||||
def self.calcWeight(files, artist, track, length)
|
||||
files.each do |file|
|
||||
weight = 0
|
||||
|
||||
@@ -99,18 +95,4 @@ module Vkontakte
|
||||
|
||||
files.sort_by{|file| file['weight']}.reverse
|
||||
end
|
||||
|
||||
def self.stream url
|
||||
headers = {
|
||||
'Cookie' => 'remixsid='+ @@bot['remixsid'] + ';remixchk='+ @@bot['remixchk'].to_s,
|
||||
'Referer' => 'http://vkontakte.ru/audio?album_id=0',
|
||||
'User-Agent' => @@bot['user_agent'],
|
||||
}
|
||||
|
||||
uri = URI.parse(url)
|
||||
http = Net::HTTP.new(uri.host, 80)
|
||||
resp, data = http.get2(uri.path, headers)
|
||||
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user