#
# License:: GPL v2
-module Spotify
- def self.get(service, method, query, page=1)
- query.tr!('-','')
- url = "http://ws.spotify.com/#{service}/1/#{method}?q=#{CGI.escape(query)}&page=#{page}"
- xml = Irc::Utils.bot.httputil.get_response(url).body
- return REXML::Document.new(xml).root
- end
-
- # returns a Spotify URL, e.g. 'http://open.spotify.com/track/3y6EhoUO3A8bPr3zt3Tm9b'
- def self.search(method, query, page=1)
- doc = get(:search, method, query, page)
- return nil if doc.elements["opensearch:totalResults"].text.to_i.zero?
- uri = doc.elements[method.to_s].attributes["href"]
- id = uri[uri.rindex(':')+1..-1]
- return URI.escape("http://open.spotify.com/#{method}/#{id}")
- end
-end
-
require 'rexml/document'
require 'cgi'
elsif venue
begin
venues = search_venue_by(:name => venue.to_s, :limit => 1)
- rescue Exception => e
- error e
+ rescue Exception => err
+ error err
m.reply _("an error occurred looking for venue %{venue}: %{e}") % {
:venue => venue.to_s,
- :e => e.message
+ :e => err.message
}
end
end
if xml.class == Net::HTTPBadRequest
if doc.root.elements["error"].attributes["code"] == "6" then
- m.reply _("%{user} doesn't exist on last.fm, perhaps they need to: lastfm user <username>") % {
- :user => user
+ m.reply _("%{user} doesn't exist on last.fm, perhaps they need to: %{prefix}lastfm set user <username>") % {
+ :user => user,
+ :prefix => @bot.config['core.address_prefix'].first
}
return
else
end
first = doc.root.elements[1].elements[1]
now = first.attributes["nowplaying"]
- artist = first.elements["artist"].text
+ artist = first.elements["artist/name"].text
track = first.elements["name"].text
albumtxt = first.elements["album"].text
album = if albumtxt
reply = _("%{u} %{v} \"%{t}\" by %{bold}%{a}%{bold}%{b} %{p};") % {:u => user, :v => verb, :t => track, :a => artist, :b => album, :p => ago, :bold => Bold}
end
- if (spotify_url = Spotify.search(:track, "#{artist} #{track}"))
- reply << _(" [%{u}%{url}%{u}]") % {:u => Underline, :url => spotify_url}
+ if @bot.plugins['spotify'] && Object.const_defined?('Spotify')
+ if track = Spotify.search(:track, "#{artist} #{track}")
+ reply << _(" [%{u}%{url}%{u}]") % {:u => Underline, :url => track.url}
+ end
end
reply << _(" -- see %{uri} for more") % { :uri => "http://www.last.fm/user/#{CGI.escape user}"}
tags_xml = @bot.httputil.get("#{APIURL}method=artist.gettoptags&artist=#{CGI.escape params[:artist].to_s}")
tags_doc = Document.new tags_xml
- first = info_doc.root.elements["artist"]
+ first = info_doc.root.elements["artist/name"]
artist = first.elements["name"].text
url = first.elements["url"].text
stats = {}
if results > 0
begin
hits = []
- doc.root.each_element("results/trackmatches/track") do |track|
+ doc.root.each_element("results/trackmatches/track") do |trck|
hits << _("%{bold}%{t}%{bold} by %{bold}%{a}%{bold} (%{n} listeners)") % {
- :t => track.elements["name"].text,
- :a => track.elements["artist"].text,
- :n => track.elements["listeners"].text,
+ :t => trck.elements["name"].text,
+ :a => trck.elements["artist/name"].text,
+ :n => trck.elements["listeners"].text,
:bold => Bold
}
end
begin
res = @bot.httputil.get_response(uri)
raise _("no response body") unless res.body
- rescue Exception => e
- m.reply _("I had problems accessing last.fm: %{e}") % {:e => e.message}
+ rescue Exception => err
+ m.reply _("I had problems accessing last.fm: %{e}") % {:e => err.message}
return
end
doc = Document.new(res.body)
}
when :recenttracks
tracks = doc.root.get_elements("recenttracks/track").map do |track|
- [track.elements["artist"].text, track.elements["name"].text].join(" - ")
+ [track.elements["artist/name"].text, track.elements["name"].text].join(" - ")
end
counts = []
case action
when :weeklytrackchart, :weeklyalbumchart
format = "%{artist} - %{title} (%{bold}%{plays}%{bold})"
- artist = item.elements["artist"].text
+ artist = item.elements["artist/name"].text
when :weeklyartistchart, :topartists
format = "%{artist} (%{bold}%{plays}%{bold})"
artist = item.elements["name"].text