1
0
Fork 0
This commit is contained in:
Gregory Eremin 2011-09-19 19:21:30 +04:00
commit 269613f8c3
3 changed files with 8 additions and 6 deletions

View File

@ -2,7 +2,7 @@ module MusicBrainz
@@last_query_time = 0
@@query_interval = 1.5 # Min: 1.0 Safe: 1.5
def self.query_interval sec
def self.query_interval= sec
@@query_interval = sec.to_f
end
@ -14,7 +14,7 @@ module MusicBrainz
response = open(url, "User-Agent" => "gem musicbrainz (https://github.com/magnolia-fan/musicbrainz) @ " + Socket.gethostname)
@@last_query_time = Time.now.to_f
rescue => e
# MusicBrainz: 503
return nil if e.io.status[0].to_i == 404
end
break unless response.nil?
end

View File

@ -16,13 +16,15 @@ module MusicBrainz
end
def self.find mbid
@artist = self.parse_xml(Nokogiri::XML(MusicBrainz.load('http://musicbrainz.org/ws/2/artist/' + mbid)))
res = MusicBrainz.load('http://musicbrainz.org/ws/2/artist/' + mbid)
return nil if res.nil?
@artist = self.parse_xml(Nokogiri::XML(res))
end
def self.parse_xml xml
@artist = MusicBrainz::Artist.new
@artist.id = xml.css('artist').attr('id').value
@artist.type = xml.css('artist').attr('type').value
@artist.type = xml.css('artist').attr('type').value unless xml.css('artist').nil? or xml.css('artist').attr('type').nil?
@artist.name = xml.css('artist > name').text
@artist.country = xml.css('artist > country').text unless xml.css('artist > country').empty?
@artist.date_begin = xml.css('artist > life-span > begin').text unless xml.css('artist > life-span > begin').empty?

View File

@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{musicbrainz}
s.version = "0.4.3"
s.version = "0.4.7"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gregory Eremin"]
s.date = %q{2011-09-14}
s.date = %q{2011-09-19}
s.description = %q{MusicBrainz Web Service wrapper with ActiveRecord-style models}
s.email = %q{magnolia_fan@me.com}
s.extra_rdoc_files = [