2011-09-13 10:06:52 +00:00
|
|
|
module MusicBrainz
|
|
|
|
class Track
|
|
|
|
attr_accessor :position, :recording_id, :title, :length
|
|
|
|
|
|
|
|
def self.find mbid
|
2011-09-14 07:45:42 +00:00
|
|
|
xml = Nokogiri::XML(MusicBrainz.load('http://musicbrainz.org/ws/2/recording/' + mbid + '?limit=100'))
|
2011-09-13 10:06:52 +00:00
|
|
|
self.parse_xml(xml) unless xml.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.parse_xml xml
|
|
|
|
@track = MusicBrainz::Track.new
|
2011-09-13 10:54:28 +00:00
|
|
|
@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?
|
2011-09-13 10:06:52 +00:00
|
|
|
@track
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|