4 # :title: spotify plugin for rbot
6 # Author:: Raine Virta <raine.virta@gmail.com>
8 # Copyright:: (C) 2009 Raine Virta
12 class SpotifyPlugin < Plugin
16 unless Object.const_defined?('Spotify')
17 raise 'Spotify module not found (lib_spotify plugin probably not enabled)'
21 def help(plugin, topic)
22 _("spotify plugin - usage: spotify <spotify>, spotify artist <artist>, spotify album <album>")
26 method = params[:method] || 'track'
28 result = Spotify.search(method, params[:query].to_s)
30 m.reply "problems connecting to Spotify"
40 reply = _("%{b}%{artist}%{b} – %{track}") % {
41 :artist => result.artist.name,
42 :track => result.name,
46 if result.album.released
47 reply << _(" [%{u}%{album}%{u}, %{released}]") % {
48 :released => result.album.released,
49 :album => result.album.name,
53 reply << _(" [%{u}%{album}%{u}]") % { :album => result.album.name, :u => Underline }
56 reply << _(" — %{url}") % { :url => result.url }
58 reply = _("%{b}%{artist}%{b} — %{url}") % {
60 :artist => result.name,
64 reply = _("%{b}%{artist}%{b} – %{u}%{album}%{u} — %{url}") % {
67 :artist => result.artist.name,
68 :album => result.name,
77 plugin = SpotifyPlugin.new
78 plugin.map 'spotify [:method] *query', :action => :search, :requirements => { :method => /track|artist|album/ }