2011-04-06 22:02:48 +00:00
|
|
|
# encoding: UTF-8
|
2011-04-05 22:58:11 +00:00
|
|
|
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'
|
2011-04-06 22:02:48 +00:00
|
|
|
|
|
|
|
require 'iconv'
|
|
|
|
|
|
|
|
def cover artist
|
2011-04-07 04:02:49 +00:00
|
|
|
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
|
2011-04-06 22:02:48 +00:00
|
|
|
end
|
2011-04-05 22:58:11 +00:00
|
|
|
end
|