Added MB models
This commit is contained in:
parent
2c52349576
commit
908f18c7de
|
@ -0,0 +1,61 @@
|
|||
class MusicBrainzAlbum < ActiveRecord::Base
|
||||
establish_connection :musicbrainz
|
||||
set_table_name 'musicbrainz.bh_release_group'
|
||||
|
||||
belongs_to :music_brainz_artist
|
||||
has_many :music_brainz_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
|
|
@ -1,12 +1,11 @@
|
|||
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)
|
||||
Artist.first(:conditions => ['name = ? AND id=credit_id', name], :order => 'rating DESC')
|
||||
MusicBrainzArtist.first(:conditions => ['name = ? AND id=credit_id', name], :order => 'rating DESC')
|
||||
end
|
||||
|
||||
def self.getLastFmAutocomplete(query)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class MusicBrainzRelease < ActiveRecord::Base
|
||||
establish_connection :musicbrainz
|
||||
set_table_name 'musicbrainz.bh_release'
|
||||
|
||||
belongs_to :music_brainz_album
|
||||
has_many :music_brainz_tracks, :order => 'position ASC'
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class MusicBrainzTrack < ActiveRecord::Base
|
||||
establish_connection :musicbrainz
|
||||
set_table_name 'musicbrainz.bh_track'
|
||||
|
||||
belongs_to :music_brainz_release
|
||||
end
|
Loading…
Reference in New Issue