diff --git a/README.rdoc b/README.rdoc index 142b2b7..00ecebd 100644 --- a/README.rdoc +++ b/README.rdoc @@ -7,17 +7,23 @@ === Usage require 'musicbrainz' + + # Search for artists + @suggestions = MusicBrainz::Artist.search('Jet') + + # Find artist by name or mbid + @foo_fighters = MusicBrainz::Artist.find_by_name('Foo Fighters') @kasabian = MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033') + + # Use them like ActiveRecord models @empire_tracks = @kasabian.release_groups[8].releases.first.tracks -=== Future - -It should work all like ActiveRecord models. - === Api MusicBrainzArtist - + + @artists = MusicBrainz::Artist.search(query) + @artist = MusicBrainz::Artist.find_by_name(name) @artist = MusicBrainz::Artist.find(mbid) @artist.id @artist.type diff --git a/VERSION b/VERSION index 60a2d3e..44bb5d1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.0 \ No newline at end of file +0.4.1 \ No newline at end of file diff --git a/lib/models/music_brainz.rb b/lib/models/music_brainz.rb index ae65601..ae9268f 100644 --- a/lib/models/music_brainz.rb +++ b/lib/models/music_brainz.rb @@ -1,21 +1,14 @@ module MusicBrainz @@last_query_time = 0 - - def self.last_query_time - @@last_query_time - end - - def self.last_query_time= time - @@last_query_time = time - end + @@query_interval = 1.1 def self.load url - sleep 1.1 - (Time.now.to_f - self.last_query_time) if Time.now.to_f - self.last_query_time < 1.1 + sleep @@query_interval - (Time.now.to_f - @@last_query_time) if Time.now.to_f - @@last_query_time < @@query_interval response = nil 5.times do begin response = open(url, "User-Agent" => "gem musicbrainz (https://github.com/magnolia-fan/musicbrainz) @ " + Socket.gethostname) - self.last_query_time = Time.now.to_f + @@last_query_time = Time.now.to_f rescue => e p "MusicBrainz: 503" end @@ -23,10 +16,4 @@ module MusicBrainz end response end - - def self.discography mbid - artist = MusicBrainz::Artist.find(mbid) - artist.release_groups.each {|rg| rg.releases.each {|r| r.tracks } } - artist - end end diff --git a/lib/models/music_brainz/artist.rb b/lib/models/music_brainz/artist.rb index 6284fa6..03e78c4 100644 --- a/lib/models/music_brainz/artist.rb +++ b/lib/models/music_brainz/artist.rb @@ -30,6 +30,12 @@ module MusicBrainz @artist end + def self.discography mbid + artist = self.find(mbid) + artist.release_groups.each {|rg| rg.releases.each {|r| r.tracks } } + artist + end + def self.find_by_name name matches = self.search name matches.length.zero? ? nil : self.find(matches.first[:mbid]) diff --git a/musicbrainz.gemspec b/musicbrainz.gemspec index 7c049a4..7424121 100644 --- a/musicbrainz.gemspec +++ b/musicbrainz.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{musicbrainz} - s.version = "0.4.0" + s.version = "0.4.1" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = [%q{Gregory Eremin}]