Updated readme, discography method moved to Artist model, version bump
This commit is contained in:
parent
0477633f8f
commit
7fdde0dfa1
16
README.rdoc
16
README.rdoc
@ -7,17 +7,23 @@
|
|||||||
=== Usage
|
=== Usage
|
||||||
|
|
||||||
require 'musicbrainz'
|
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')
|
@kasabian = MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
|
||||||
|
|
||||||
|
# Use them like ActiveRecord models
|
||||||
@empire_tracks = @kasabian.release_groups[8].releases.first.tracks
|
@empire_tracks = @kasabian.release_groups[8].releases.first.tracks
|
||||||
|
|
||||||
=== Future
|
|
||||||
|
|
||||||
It should work all like ActiveRecord models.
|
|
||||||
|
|
||||||
=== Api
|
=== Api
|
||||||
|
|
||||||
MusicBrainzArtist
|
MusicBrainzArtist
|
||||||
|
|
||||||
|
@artists = MusicBrainz::Artist.search(query)
|
||||||
|
@artist = MusicBrainz::Artist.find_by_name(name)
|
||||||
@artist = MusicBrainz::Artist.find(mbid)
|
@artist = MusicBrainz::Artist.find(mbid)
|
||||||
@artist.id
|
@artist.id
|
||||||
@artist.type
|
@artist.type
|
||||||
|
@ -1,21 +1,14 @@
|
|||||||
module MusicBrainz
|
module MusicBrainz
|
||||||
@@last_query_time = 0
|
@@last_query_time = 0
|
||||||
|
@@query_interval = 1.1
|
||||||
def self.last_query_time
|
|
||||||
@@last_query_time
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.last_query_time= time
|
|
||||||
@@last_query_time = time
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.load url
|
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
|
response = nil
|
||||||
5.times do
|
5.times do
|
||||||
begin
|
begin
|
||||||
response = open(url, "User-Agent" => "gem musicbrainz (https://github.com/magnolia-fan/musicbrainz) @ " + Socket.gethostname)
|
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
|
rescue => e
|
||||||
p "MusicBrainz: 503"
|
p "MusicBrainz: 503"
|
||||||
end
|
end
|
||||||
@ -23,10 +16,4 @@ module MusicBrainz
|
|||||||
end
|
end
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.discography mbid
|
|
||||||
artist = MusicBrainz::Artist.find(mbid)
|
|
||||||
artist.release_groups.each {|rg| rg.releases.each {|r| r.tracks } }
|
|
||||||
artist
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -30,6 +30,12 @@ module MusicBrainz
|
|||||||
@artist
|
@artist
|
||||||
end
|
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
|
def self.find_by_name name
|
||||||
matches = self.search name
|
matches = self.search name
|
||||||
matches.length.zero? ? nil : self.find(matches.first[:mbid])
|
matches.length.zero? ? nil : self.find(matches.first[:mbid])
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{musicbrainz}
|
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.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = [%q{Gregory Eremin}]
|
s.authors = [%q{Gregory Eremin}]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user