Vkontakte html & parse
This commit is contained in:
@@ -8,6 +8,7 @@ class ArtistController < ApplicationController
|
||||
name = params[:name].gsub('+', ' ').gsub('%20', ' ')
|
||||
end
|
||||
@artist = Artist.getByName(name)
|
||||
pp @artist
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,6 +2,12 @@ class TrackController < ApplicationController
|
||||
require 'net/http'
|
||||
require 'uri'
|
||||
def listen
|
||||
artist = 'The White Stripes'
|
||||
track = 'Blue Orchid'
|
||||
length = 157
|
||||
|
||||
Vkontakte.get(artist, track, length)
|
||||
|
||||
render :json => 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,19 +1,70 @@
|
||||
module Vkontakte
|
||||
@@accounts = YAML.load_file("#{RAILS_ROOT}/config/vk_accounts.yml")
|
||||
require 'net/http'
|
||||
require 'erb'
|
||||
#require 'nokogiri'
|
||||
|
||||
def get artist, track, length
|
||||
|
||||
@@accounts = YAML.load_file("#{Rails.root.to_s}/config/vk_accounts.yml")
|
||||
|
||||
def self.get artist, track, length
|
||||
#html = self.getHtml artist +' - '+ track
|
||||
files = self.parseHtml 1 #html
|
||||
files = self.calcWeight files
|
||||
end
|
||||
|
||||
def getHtml q
|
||||
|
||||
|
||||
private
|
||||
|
||||
def self.randomBot
|
||||
@@accounts[@@accounts.keys[rand(@@accounts.keys.length - 1)]]
|
||||
end
|
||||
|
||||
def parseHtml html
|
||||
def self.getHtml q
|
||||
bot = self.randomBot
|
||||
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)
|
||||
pp data
|
||||
end
|
||||
|
||||
def calcWeight files
|
||||
|
||||
def self.parseHtml html
|
||||
html = open('/Users/chez/Sites/beathaven/tmp/vkres.txt').read
|
||||
files = []
|
||||
html
|
||||
.gsub(/\\/, '')
|
||||
.scan(/<table.*?<input.*?value=\"(.*?)\,\d{2,4}\".*?>.*?<div\sclass=\"duration.*?>(.*?)<\/div>.*?<div\sclass=\"title_wrap\".*?>.*?selectPerformer\(event\,\s\'(.*?)\'\).*?<span\sclass=\"title\">(.*?)<\/span><\/div>.*?<\/table>/i)
|
||||
.each do |item|
|
||||
t = item[1].split(':')
|
||||
files << {
|
||||
'url' => item[0],
|
||||
'length' => (t[0].to_i * 60) + t[1].to_i,
|
||||
'artist' => item[2],
|
||||
'title' => item[3].gsub(/<\/?span>/, '')
|
||||
}
|
||||
end
|
||||
files
|
||||
end
|
||||
|
||||
def self.calcWeight files
|
||||
pp files
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user