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
-61
View File
@@ -1,61 +0,0 @@
# encoding: UTF-8
class Album < ActiveRecord::Base
set_table_name 'musicbrainz.bh_release_group'
belongs_to :artist
has_many :releases, :conditions => "release_type = 1", :order => 'date ASC, id ASC'
require 'iconv'
def cover artist
covers = AlbumPic.where(album_id: id).first
unless covers.nil?
covers.extralarge
else
q_artist = CGI::escape(artist)
q_album = CGI::escape(name)
path = open(
'http://ws.audioscrobbler.com/2.0/' <<
'?method=album.getinfo' <<
'&api_key=04fda005dbf61a50af5abc3e90f111f2' <<
'&artist=' << q_artist <<
'&album=' << q_album
).read
m = path.scan(/<image\ssize=\"(.*)\">(.*)<\/image>/i)
AlbumPic.where(
album_id: id,
small: m[0][1],
medium: m[1][1],
large: m[2][1],
extralarge: m[3][1],
mega: m[4][1]
).create
m[3][1]
end
end
def tracksInDb
tracks = []
result = []
tracks_in_db = []
track_ids = []
self.releases.first.tracks.each do |track|
tracks << track
track_ids << track.id.to_s
end
in_db = TrackData.any_in(id: track_ids).only("id")
unless in_db.nil?
in_db.each do |track|
tracks_in_db << track["id"].to_i;
end
end
tracks.each do |track|
result << {
:object => track,
:in_db => tracks_in_db.include?(track.id) ? nil : true
}
end
result
end
end
-11
View File
@@ -1,11 +0,0 @@
class AlbumPic
include Mongoid::Document
store_in :album_pics
key :album_id, Integer
key :small, String
key :medium, String
key :large, String
key :extralarge, String
key :mega, String
end
-19
View File
@@ -1,19 +0,0 @@
class Artist < ActiveRecord::Base
set_table_name 'musicbrainz.bh_artist'
has_many :albums, :conditions => "release_type = 1", :order => 'year ASC, id ASC'
def self.getByName(name)
Artist.first(:conditions => ['name = ? AND id=credit_id', name], :order => 'rating DESC')
end
def self.getLastFmAutocomplete(query)
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 json.empty? ? nil : json
end
end
-33
View File
@@ -1,33 +0,0 @@
class BeatDB
@@db_root = '/www/beatdb'
def self.get key
unless self.exists(key) || File.readable?(self.filePathByKey(key))
return false
end
h = File.open(self.filePathByKey(key), 'r')
JSON.decode(h.readline)
end
def self.set key, data
unless self.exists(key) || File.writable?(self.filePathByKey(key))
return false
end
h = File.open(self.filePathByKey(key), 'w')
h.puts(JSON.encode(data))
end
def self.delete key
end
def self.exists key
File.exists?(self.filePathByKey(key))
end
def self.filePathByKey key
path = ''
key.to_s.each_char {|c| path << '/' + c}
@@db_root + path[0..(path.length-2)] << key.to_s + '.json'
end
end
-54
View File
@@ -1,54 +0,0 @@
# encoding: UTF-8
class Bot < Daemons::PidFile
require "daemons"
PIDS_PATH = "#{Rails.root.to_s}/tmp/pids"
DAEMON_PATH = "#{Rails.root.to_s}/lib/daemons"
@@accounts = YAML.load_file("#{Rails.root.to_s}/config/vk_accounts.yml")
def initialize(name)
unless @@accounts.include?(name)
throw "Empty bot name."
end
@dir = File.expand_path(PIDS_PATH)
@progname = name
@multiple = false
@number = nil
end
def getCurrentTrack
current_track = ParseQueue.where(:status => 4, :bot_name => @progname).first
end
def startedAt
unless self.running?
return false
end
ts = eval('`date -d "\`ps -p ' + self.pid.to_s + ' -o lstart=\`" +"%Y-%m-%d %H:%M:%S"`')
ts = ts.strip
end
def start
if bot.running?
throw "This bot already started."
end
eval('`ruby ' + DAEMON_PATH + '/parse_controller.rb ' + Rails.root.to_s + ' ' + name + '`')
end
def stop
if not self.running?
throw "This bot already stopped."
end
signal = (RUBY_PLATFORM =~ /win32/ ? 'KILL' : 'TERM')
pid = self.pid
begin
Process.kill(signal, self.pid)
self.cleanup
rescue Errno::ESRCH => e
throw "#{e} #{pid}"
end
end
end
-9
View File
@@ -1,9 +0,0 @@
class Invite
include Mongoid::Document
store_in :invites
key :referer, Integer
key :email, String
key :code, String
key :date, Date
end
-14
View File
@@ -1,14 +0,0 @@
class ParseQueue
include Mongoid::Document
store_in :bot_parse_queue
key :track_id, Integer
key :artist_id, Integer
key :artist_name, String
key :track_name, String
key :bot_name, String
key :status, Integer
key :date, Array
key :times_failed, Integer
end
-5
View File
@@ -1,5 +0,0 @@
class Release < ActiveRecord::Base
set_table_name 'musicbrainz.bh_release'
belongs_to :album
has_many :tracks, :order => 'position ASC'
end
-5
View File
@@ -1,5 +0,0 @@
class Track < ActiveRecord::Base
set_table_name 'musicbrainz.bh_track'
belongs_to :release
end
-10
View File
@@ -1,10 +0,0 @@
class TrackData
include Mongoid::Document
store_in :track_data
key :id, Integer
key :artist, String
key :title, String
key :length, Integer
key :files, Array
end
-24
View File
@@ -1,24 +0,0 @@
class User
include Mongoid::Document
store_in :users
key :name, String
key :password, String
key :email, String
key :regdate, Date
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