This commit is contained in:
magnolia-fan
2011-06-13 16:30:49 +04:00
parent d635b321f4
commit 1d9a0398c6
51 changed files with 0 additions and 1297 deletions
-54
View File
@@ -1,54 +0,0 @@
# encoding: utf-8
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
# Dirty auth block END
if params[:name].nil?
name = ''
else
if request.request_method == 'POST'
redirect_to :action => 'view', :name => params[:name].gsub(' ', '+')
end
name = params[:name].gsub('+', ' ')
end
@artist = Artist.getByName(name)
if @artist.nil?
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
else
@albums = []
@artist.albums.each do |album|
unless album.releases.empty?
tracks = album.tracksInDb()
@albums << {
:object => album,
:tracks => tracks
}
end
end
end
end
def autocomplete
autocomplete = Artist.getLastFmAutocomplete(params[:query])
return render :nothing => true if autocomplete.nil?
suggestions = []
autocomplete["response"]["docs"].each do |doc|
suggestions << doc["artist"] unless suggestions.include?(doc["artist"])
end
render :json => {
:query => params[:query],
:suggestions => suggestions
}
end
end
-131
View File
@@ -1,131 +0,0 @@
class BotController < ApplicationController
require 'daemons'
PIDS_PATH = "#{Rails.root.to_s}/tmp/pids"
@@accounts = YAML.load_file("#{Rails.root.to_s}/config/vk_accounts.yml")
@error = ""
def list
@bots = []
@@accounts.each do |bot_name, data|
bot = Bot.new(bot_name)
@bots << {
:name => bot_name,
:started => bot.running?,
:current_track => bot.getCurrentTrack,
:started_at => bot.running? ? bot.startedAt : nil
}
end
pp @bots
end
def stats
end
def queue
bot_name = params['bot_name']
group_by_artist = params['group_by_artist']
limit = params['limit']
if not bot_name.nil?
if not @@accounts.include?(bot_name)
throw "Wrong bot name."
end
end
if not group_by_artist.nil?
group_by_artist = true
end
if params['limit'].to_i != 0
limit = params['limit'].to_i
end
statuses = [0, 1, 4]
data = ParseQueue.any_in(status: statuses)
if not bot_name.nil?
data = data.where(:bot_name => bot_name)
end
# if group_by_artist
# data = data.only(:artist_name).group
# end
if not limit.nil?
data = data.limit(limit)
end
@queue = []
unless data.nil?
data.each do |track|
@queue << track
end
end
pp @queue
end
def start
name = params['name']
begin
if name.nil? or name.strip.empty?
throw "Empty bot name"
end
bot = Bot.new(name)
bot.start
rescue
return render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
def stop
name = params['name']
begin
if name.nil? or name.strip.empty?
throw "Empty bot name"
end
bot = Bot.new(name)
bot.stop
rescue
return render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
# Add artist to parse_queue
def add
name = params['name']
if name.nil? or name.strip.empty?
redirect_to '/'
end
artist = Artist.getByName(name)
if artist.nil?
@error = "There is no such artist."
else
data = ParseQueue.where(:artist_id => artist.id).first
if not data.nil?
throw "This artist already exist in queue."
else
tracks = []
artist.albums.each do |album|
unless album.releases.empty?
album.releases.first.tracks.each do |track|
tracks << track
end
end
end
tracks.each do |track|
ParseQueue.collection.insert({
:track_id => track.id,
:artist_id => artist.id,
:artist_name => artist.name,
:track_name => track.name,
:bot_name => nil,
:status => 0,
:date => nil,
:times_failed => 0
})
end
end
end
end
end
-7
View File
@@ -1,7 +0,0 @@
class MainController < ApplicationController
def index
# unless User.logged_in
# redirect_to '/login'
# end
end
end
-20
View File
@@ -1,20 +0,0 @@
class TrackController < ApplicationController
require 'net/http'
require 'uri'
@@token_salt = '8FW*W#dWOH*FHW4j:Q@RQ{Qo[qF;fw0`0w4fkl'
def listen
pp track = Track.where(:id => params[:id].to_i).first
data = Vkontakte.get(track.artist_name, track.name, (track.length / 1000).round)
# data = Vkontakte.get(1, 1, 1)
url = URI.parse(data['url'])
token = Digest::SHA256.hexdigest(params[:id] << @@token_salt)
nginx_url = '/proxy-stream/' << token << '/' << data['remixsid'] << '/' << '5' << '/' << url.host << url.path
headers['Content-Type'] = 'audio/mpeg'
headers['X-Accel-Redirect'] = nginx_url
render :nothing => true
end
end
-92
View File
@@ -1,92 +0,0 @@
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?
user_data = User.collection.find({email: params[:email], password: Digest::SHA256.hexdigest(params[:password])}).first
unless user_data.nil?
user_data['session_key'] = Digest::SHA256.hexdigest(request.session['session_id'])
User.collection.update({_id: user_data._id}, user_data.attributes)
redirect_to '/'
else
redirect_to '/login'
end
end
end
def register
@hide_player = 1
data = Invite.where(:email => params[:email], :code => params[:code]).first
unless data.nil?
@code = data.code
@email = data.email
else
redirect_to '/login'
end
end
def complete
@hide_player = 1
data = Invite.where(:email => params[:invite_email], :code => params[:invite_code]).first
unless data.nil?
if params[:email].match(@@email_regex).nil? or
params[:password].length < 6 or
params[:password] != params[:password_c]
redirect_to '/'
end
User.collection.insert({
email: params[:email],
password: Digest::SHA256.hexdigest(params[:password]),
name: '',
regdate: Time.now(),
referer: data.referer,
lastvisit: Time.now(),
invites: 0
})
Invite.collection.remove({email: params[:invite_email], code: params[:invite_code]})
else
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