1
0
Fork 0

More stable, less errors. Full discography method.

This commit is contained in:
Gregory Eremin 2011-09-13 14:54:28 +04:00
parent 20a2391c0b
commit 4bb639d853
6 changed files with 28 additions and 14 deletions

View File

@ -23,4 +23,10 @@ module MusicBrainz
self.last_query_time = Time.now.to_f
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

View File

@ -22,9 +22,9 @@ module MusicBrainz
@artist.id = xml.css('artist').attr('id').value
@artist.type = xml.css('artist').attr('type').value
@artist.name = xml.css('artist > name').text
@artist.country = xml.css('artist > country').text || nil
@artist.date_begin = xml.css('artist > life-span > begin').text || nil
@artist.date_end = xml.css('artist > life-span > end').text || nil
@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?
@artist.date_end = xml.css('artist > life-span > end').text unless xml.css('artist > life-span > end').empty?
@artist
end
end

View File

@ -21,9 +21,10 @@ module MusicBrainz
def self.parse_xml xml
@release = MusicBrainz::Release.new
@release.id = xml.attr('id')
@release.title = xml.css('title').text
@release.status = xml.css('status').text
date = xml.css('date').text
@release.title = xml.css('title').text unless xml.css('title').empty?
@release.status = xml.css('status').text unless xml.css('status').empty?
date = nil
date = xml.css('date').text unless xml.css('date').empty?
unless date.nil? or date.empty?
if date.length == 4
date += '-01-01'
@ -33,7 +34,7 @@ module MusicBrainz
date = Time.parse(date)
end
@release.date = date
@release.country = xml.css('country').text
@release.country = xml.css('country').text unless xml.css('country').empty?
@release
end
end

View File

@ -22,8 +22,9 @@ module MusicBrainz
@release_group = MusicBrainz::ReleaseGroup.new
@release_group.id = xml.attr('id')
@release_group.type = xml.attr('type')
@release_group.title = xml.css('title').text
date = xml.css('first-release-date').text
@release_group.title = xml.css('title').text unless xml.css('title').empty?
date = nil
date = xml.css('first-release-date').text unless xml.css('first-release-date').empty?
unless date.nil? or date.empty?
if date.length == 4
date += '-01-01'

View File

@ -9,10 +9,11 @@ module MusicBrainz
def self.parse_xml xml
@track = MusicBrainz::Track.new
@track.position = xml.css('position').text.to_i || nil
@track.recording_id = xml.css('recording').attr('id').value
@track.title = xml.css('recording > title').text
@track.length = xml.css('length').first.text.to_i || 0
@track.position = xml.css('position').text.to_i unless xml.css('position').empty?
@track.recording_id = xml.css('recording').attr('id').value unless xml.css('recording').empty?
@track.title = xml.css('recording > title').text unless xml.css('recording > title').empty?
@track.length = xml.css('length').first.text.to_i unless xml.css('length').empty?
@track.length = xml.css('recording > length').first.text.to_i unless xml.css('recording > length').empty?
@track
end
end

View File

@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{musicbrainz}
s.version = "0.2.0"
s.version = "0.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Gregory Eremin}]
@ -24,6 +24,11 @@ Gem::Specification.new do |s|
"README.rdoc",
"Rakefile",
"VERSION",
"lib/models/music_brainz.rb",
"lib/models/music_brainz/artist.rb",
"lib/models/music_brainz/release.rb",
"lib/models/music_brainz/release_group.rb",
"lib/models/music_brainz/track.rb",
"lib/musicbrainz.rb",
"musicbrainz.gemspec",
"test/helper.rb",