Mass move to root
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
# 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)
|
||||
unless covers.empty?
|
||||
covers.first.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.new(
|
||||
album_id: id,
|
||||
small: m[0][1],
|
||||
medium: m[1][1],
|
||||
large: m[2][1],
|
||||
extralarge: m[3][1],
|
||||
mega: m[4][1]
|
||||
)
|
||||
m[3][1]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
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
|
||||
@@ -0,0 +1,8 @@
|
||||
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
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
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
|
||||
@@ -0,0 +1,9 @@
|
||||
class Invite
|
||||
include Mongoid::Document
|
||||
store_in :invites
|
||||
|
||||
key :referer, Integer
|
||||
key :email, String
|
||||
key :code, String
|
||||
key :senton, Date
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class Release < ActiveRecord::Base
|
||||
set_table_name 'musicbrainz.bh_release'
|
||||
belongs_to :album
|
||||
has_many :tracks, :order => 'position ASC'
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class Track < ActiveRecord::Base
|
||||
set_table_name 'musicbrainz.bh_track'
|
||||
belongs_to :release
|
||||
|
||||
def inDb
|
||||
! TrackData.where(id: id.to_s).empty?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
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
|
||||
@@ -0,0 +1,12 @@
|
||||
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
|
||||
end
|
||||
Reference in New Issue
Block a user