Discogs artist search

This commit is contained in:
Gregory Eremin
2011-10-24 11:33:32 +04:00
parent d5992c31b4
commit 7bad8f16e0
5 changed files with 31 additions and 8 deletions
+18 -1
View File
@@ -1,3 +1,5 @@
require 'zlib'
class Discogs
def self.artists
@@ -148,7 +150,22 @@ class Discogs
albums
end
private
def self.search_for_artist name
url = 'http://api.discogs.com/search?q=' << CGI::escape(name) << '&f=xml'
stream = open(url,
'User-Agent' => 'Haven Import Bot',
'Accept-Encoding' => 'gzip, deflate'
)
if (stream.content_encoding.empty?)
body = stream.read
else
body = Zlib::GzipReader.new(stream).read
end
x = Nokogiri::XML(body)
x.css('exactresults > result[type=artist] > uri, searchresults > result[type=artist] > uri').map{|n| n.text}.first
end
private
def self.get_nodes filename, nodename, &block
File.open(filename) do |file|