Tons of fixes
This commit is contained in:
parent
8425168638
commit
f6b34b3960
@ -3,15 +3,15 @@ class ArtistController < ApplicationController
|
|||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
def view
|
def view
|
||||||
# Dirty auth block START
|
# Dirty auth block START
|
||||||
unless request.session['session_id'].nil? or MainController.logged_in request.session['session_id']
|
# unless request.session['session_id'].nil? or MainController.logged_in request.session['session_id']
|
||||||
redirect_to '/login'
|
# redirect_to '/login'
|
||||||
return
|
# return
|
||||||
else
|
# else
|
||||||
if request.session['session_id'].nil?
|
# if request.session['session_id'].nil?
|
||||||
redirect_to '/login'
|
# redirect_to '/login'
|
||||||
return
|
# return
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
# Dirty auth block END
|
# Dirty auth block END
|
||||||
if params[:name].nil?
|
if params[:name].nil?
|
||||||
name = ''
|
name = ''
|
||||||
|
@ -1,23 +1,7 @@
|
|||||||
class MainController < ApplicationController
|
class MainController < ApplicationController
|
||||||
def index
|
def index
|
||||||
# Dirty auth block START
|
# unless User.logged_in
|
||||||
unless request.session['session_id'].nil? or MainController.logged_in request.session['session_id']
|
# redirect_to '/login'
|
||||||
redirect_to '/login'
|
# end
|
||||||
else
|
|
||||||
if request.session['session_id'].nil?
|
|
||||||
redirect_to '/login'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# Dirty auth block END
|
|
||||||
end
|
|
||||||
def self.logged_in session_id
|
|
||||||
user_data = User.collection.find({session_key: Digest::SHA256.hexdigest(session_id)}).first
|
|
||||||
unless user_data.nil?
|
|
||||||
user_data['lastvisit'] = Time.now()
|
|
||||||
User.collection.update({_id: user_data._id}, user_data.attributes)
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -3,18 +3,14 @@ class TrackController < ApplicationController
|
|||||||
require 'uri'
|
require 'uri'
|
||||||
def listen
|
def listen
|
||||||
pp track = Track.where(:id => params[:id].to_i).first
|
pp track = Track.where(:id => params[:id].to_i).first
|
||||||
pp release = Release.where(:id => track.release_id).first
|
|
||||||
pp album = Album.where(:id => release.album_id).first
|
|
||||||
pp artist = Artist.where(:id => album.artist_id).first
|
|
||||||
|
|
||||||
data = Vkontakte.get(artist.name, track.name, (track.length / 1000).round)
|
data = Vkontakte.get(track.artist_name, track.name, (track.length / 1000).round)
|
||||||
|
# data = Vkontakte.get(1, 1, 1)
|
||||||
url = URI.parse(data['url'])
|
url = URI.parse(data['url'])
|
||||||
nginx_url = '/proxy-stream/no-token/' << data['remixsid'] << '/' << '5' << '/' << url.host << url.path
|
nginx_url = '/proxy-stream/no-token/' << data['remixsid'] << '/' << '5' << '/' << url.host << url.path
|
||||||
#render :inline => nginx_url
|
|
||||||
headers['Content-Type'] = 'audio/mpeg'
|
headers['Content-Type'] = 'audio/mpeg'
|
||||||
headers['X-Accel-Redirect'] = nginx_url
|
headers['X-Accel-Redirect'] = nginx_url
|
||||||
headers['Connection'] = 'close'
|
|
||||||
render :nothing => true
|
render :nothing => true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
def navigation
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Numeric
|
class Numeric
|
||||||
|
@ -2,38 +2,34 @@ module Vkontakte
|
|||||||
require 'uri'
|
require 'uri'
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'erb'
|
require 'erb'
|
||||||
|
require 'pp'
|
||||||
#require 'nokogiri'
|
#require 'nokogiri'
|
||||||
|
|
||||||
@@accounts = YAML.load_file("#{Rails.root.to_s}/config/vk_accounts.yml")
|
@@accounts = YAML.load_file("#{Rails.root.to_s}/config/vk_accounts.yml")
|
||||||
@@bot = nil
|
@@bot = nil
|
||||||
|
|
||||||
def self.get artist, track, length
|
def self.get(artist, track, length)
|
||||||
self.randomBot
|
self.randomBot()
|
||||||
html = self.getHtml(artist << ' - ' << track).force_encoding("WINDOWS-1251").encode("UTF-8")
|
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.parseHtml(html)
|
||||||
files = self.calcWeight(files, artist, track, length)
|
files = self.calcWeight(files, artist, track, length)
|
||||||
#self.stream files.first['url']
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'url' => files.first['url'],
|
'url' => files.first['url'],
|
||||||
'remixsid' => @@bot['remixsid'],
|
'remixsid' => @@bot['remixsid'],
|
||||||
'remixchk' => @@bot['remixchk']
|
'remixchk' => @@bot['remixchk']
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.randomBot
|
def self.randomBot()
|
||||||
botname = @@accounts.keys[rand(@@accounts.keys.length - 1)]
|
botname = @@accounts.keys[rand(@@accounts.keys.length - 1)]
|
||||||
@@bot = @@accounts[botname]
|
@@bot = @@accounts[botname]
|
||||||
pp 'Using bot ' << botname
|
pp 'Using bot ' << botname
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.getHtml q
|
def self.getHtml(q)
|
||||||
headers = {
|
headers = {
|
||||||
'Cookie' => 'remixsid='+ @@bot['remixsid'] + ';remixchk='+ @@bot['remixchk'].to_s,
|
'Cookie' => 'remixsid='+ @@bot['remixsid'] + ';remixchk='+ @@bot['remixchk'].to_s,
|
||||||
'Referer' => 'http://vkontakte.ru/audio?album_id=0',
|
'Referer' => 'http://vkontakte.ru/audio?album_id=0',
|
||||||
@ -60,7 +56,7 @@ module Vkontakte
|
|||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parseHtml html
|
def self.parseHtml(html)
|
||||||
files = []
|
files = []
|
||||||
html
|
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)
|
.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
|
files
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.calcWeight files, artist, track, length
|
def self.calcWeight(files, artist, track, length)
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
weight = 0
|
weight = 0
|
||||||
|
|
||||||
@ -99,18 +95,4 @@ module Vkontakte
|
|||||||
|
|
||||||
files.sort_by{|file| file['weight']}.reverse
|
files.sort_by{|file| file['weight']}.reverse
|
||||||
end
|
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
|
end
|
||||||
|
@ -10,10 +10,10 @@ class Artist < ActiveRecord::Base
|
|||||||
return nil if query.nil? or query.strip.empty?
|
return nil if query.nil? or query.strip.empty?
|
||||||
|
|
||||||
json = ActiveSupport::JSON.decode(open(
|
json = ActiveSupport::JSON.decode(open(
|
||||||
'http://www.last.fm/search/autocomplete' <<
|
'http://www.last.fm/search/autocomplete' <<
|
||||||
'?q=' << URI.escape(query)
|
'?q=' << URI.escape(query)
|
||||||
).read)
|
).read)
|
||||||
return nil if json.empty? else return json
|
return json.empty? ? nil : json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,4 +9,16 @@ class User
|
|||||||
key :invites, Integer
|
key :invites, Integer
|
||||||
key :referer, Integer
|
key :referer, Integer
|
||||||
key :active, Integer
|
key :active, Integer
|
||||||
|
|
||||||
|
def logged_in
|
||||||
|
unless request.session['session_id'].nil? or MainController.logged_in session['session_id']
|
||||||
|
redirect_to '/login'
|
||||||
|
return
|
||||||
|
else
|
||||||
|
if request.session['session_id'].nil?
|
||||||
|
redirect_to '/login'
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
@ -9,6 +9,7 @@
|
|||||||
<%= csrf_meta_tag %>
|
<%= csrf_meta_tag %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="nav">
|
<div id="nav">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/">Search</a></li>
|
<li><a href="/">Search</a></li>
|
||||||
@ -16,6 +17,7 @@
|
|||||||
<li><a href="/logout">Logout</a></li>
|
<li><a href="/logout">Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if @hide_player.nil? -%>
|
<% if @hide_player.nil? -%>
|
||||||
<div id="player">
|
<div id="player">
|
||||||
<div id="audiobox"></div>
|
<div id="audiobox"></div>
|
||||||
|
7
app/views/main/navigation.html.erb
Normal file
7
app/views/main/navigation.html.erb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<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>
|
Loading…
x
Reference in New Issue
Block a user