Merge branch 'master' of github.com:magnolia-fan/BeatHaven

Conflicts:
	config/routes.rb
This commit is contained in:
Hipster Hitman
2011-04-28 03:24:41 +04:00
24 changed files with 361 additions and 138 deletions
+9 -9
View File
@@ -3,15 +3,15 @@ class ArtistController < ApplicationController
require 'open-uri'
def view
# Dirty auth block START
unless request.session['session_id'].nil? or MainController.logged_in request.session['session_id']
redirect_to '/login'
return
else
if request.session['session_id'].nil?
redirect_to '/login'
return
end
end
# unless request.session['session_id'].nil? or MainController.logged_in request.session['session_id']
# redirect_to '/login'
# return
# else
# if request.session['session_id'].nil?
# redirect_to '/login'
# return
# end
# end
# Dirty auth block END
if params[:name].nil?
name = ''
+3 -19
View File
@@ -1,23 +1,7 @@
class MainController < ApplicationController
def index
# Dirty auth block START
unless request.session['session_id'].nil? or MainController.logged_in request.session['session_id']
redirect_to '/login'
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
# unless User.logged_in
# redirect_to '/login'
# end
end
end
+3 -7
View File
@@ -3,18 +3,14 @@ class TrackController < ApplicationController
require 'uri'
def listen
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'])
nginx_url = '/proxy-stream/no-token/' << data['remixsid'] << '/' << '5' << '/' << url.host << url.path
#render :inline => nginx_url
headers['Content-Type'] = 'audio/mpeg'
headers['X-Accel-Redirect'] = nginx_url
headers['Connection'] = 'close'
render :nothing => true
end
end
+41 -1
View File
@@ -1,4 +1,8 @@
class UserController < ApplicationController
@@invite_salt = 'Gouranga gives a fuck?!'
@@email_regex = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
def login
@hide_player = 1
unless params[:email].nil? or params[:password].nil?
@@ -28,7 +32,7 @@ class UserController < ApplicationController
@hide_player = 1
data = Invite.where(:email => params[:invite_email], :code => params[:invite_code]).first
unless data.nil?
if params[:email].match(/\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\z/).nil? or
if params[:email].match(@@email_regex).nil? or
params[:password].length < 6 or
params[:password] != params[:password_c]
redirect_to '/'
@@ -49,4 +53,40 @@ class UserController < ApplicationController
redirect_to '/login'
end
end
def update
@data = User.collection.find({session_key: Digest::SHA256.hexdigest(request.session['session_id'])}).first
unless @data.nil?
if request.request_method == 'POST'
if params[:name]
@data.name = params[:name]
end
User.collection.update({_id: @data._id}, @data.attributes)
end
else
render :json => 'wtf?'
end
end
def invite
@data = User.collection.find({session_key: Digest::SHA256.hexdigest(request.session['session_id'])}).first
unless @data.nil?
if @data.invites > 0
pp 1
if request.request_method == 'POST'
unless params[:email].nil?
if params[:email].match(@@email_regex)
Invite.collection.insert({email: params[:email], code: Digest::SHA256.hexdigest(params[:email] << @@invite_salt), referer: @data._id})
@data.invites -= 1
User.collection.update({_id: @data._id}, @data.attributes)
@ok = true
end
end
end
pp 2
else
render :json => 'wtf?'
end
end
end
end
+3
View File
@@ -1,4 +1,7 @@
module ApplicationHelper
def navigation
end
end
class Numeric
+11 -29
View File
@@ -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
+4 -4
View File
@@ -10,10 +10,10 @@ class Artist < ActiveRecord::Base
return nil if query.nil? or query.strip.empty?
json = ActiveSupport::JSON.decode(open(
'http://www.last.fm/search/autocomplete' <<
'?q=' << URI.escape(query)
).read)
return nil if json.empty? else return json
'http://www.last.fm/search/autocomplete' <<
'?q=' << URI.escape(query)
).read)
return json.empty? ? nil : json
end
end
+12
View File
@@ -9,4 +9,16 @@ class User
key :invites, Integer
key :referer, 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
+39 -28
View File
@@ -9,36 +9,47 @@
<%= 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">
<% if @hide_player.nil? -%>
<div id="player">
<audio autoplay preload></audio>
<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/shuffle.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>
<%- end %>
<%= yield %>
</div>
</div>
+7
View 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>
+23
View File
@@ -0,0 +1,23 @@
<div id="registration">
<h1>Help BeatHaven dominate those lousy humans!</h1>
<%= form_tag('/reg/complete', :method => 'post') do -%>
<%= label_tag 'email', 'E-mail' %><%= email_field_tag 'email', @email %><div id="email_error"></div>
<div class="complete">
<%= submit_tag 'I wanna get this guy in!' %>
</div>
<% end -%>
</div>
<script type="text/javascript" charset="utf-8">
$(function(){
$('#email').focus();
$('form').submit(function(){
$('#email, #email_error').html('');
if (! $('#email').val().match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/)) {
$('#email_error').html('* Invalid email');
$('#email').focus();
return false;
}
return true;
})
})
</script>
+31
View File
@@ -0,0 +1,31 @@
<div id="registration">
<h1>Update ur profile!</h1>
<%= form_tag('/user/profile', :method => 'post') do -%>
<%= label_tag 'email', 'E-mail' %><%= email_field_tag 'email', @data.email %>
<%= label_tag 'name', 'Name' %><%= text_field_tag 'name', @data.name %>
<%= label_tag 'password', 'Password' %><%= password_field_tag 'password', nil %><div id="password_error"></div>
<%= label_tag 'password_c', 'Confirm' %><%= password_field_tag 'password_c', nil %><div id="password_c_error"></div>
<div class="complete">
<%= submit_tag 'I\'m done!' %>
</div>
<% end -%>
</div>
<script type="text/javascript" charset="utf-8">
$(function(){
$('#password').focus();
$('form').submit(function(){
$('#password_error, #password_c_error').html('');
if ($('#password').val().length > 0 && $('#password').val().length < 6) {
$('#password_error').html('* Password must be 6+ characters length');
$('#password').focus();
return false;
} else if ($('#password').val().length > 0 && $('#password').val() != $('#password_c').val()) {
$('#password_c_error').html('* Password and confirmation doesn\'t match');
$('#password_c').focus();
return false;
}
return true;
})
})
</script>