2011-06-14 16:05:12 +00:00
|
|
|
class MusicBrainzArtist < ActiveRecord::Base
|
|
|
|
establish_connection :musicbrainz
|
|
|
|
set_table_name 'musicbrainz.bh_artist'
|
|
|
|
|
|
|
|
has_many :albums, :conditions => "release_type = 1", :order => 'year ASC, id ASC'
|
|
|
|
|
|
|
|
def self.getByName(name)
|
2011-06-14 16:21:36 +00:00
|
|
|
MusicBrainzArtist.first(:conditions => ['name = ? AND id=credit_id', name], :order => 'rating DESC')
|
2011-06-14 16:05:12 +00:00
|
|
|
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
|