1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#-- vim:sw=2:et
#++
#
# :title: spotify plugin for rbot
#
# Author:: Raine Virta <raine.virta@gmail.com>
#
# Copyright:: (C) 2009 Raine Virta
#
# License:: GPL v2
class SpotifyPlugin < Plugin
def help(plugin, topic)
_("spotify plugin - usage: spotify <spotify>, spotify artist <artist>, spotify album <album>")
end
def search(m, params)
method = params[:method] || 'track'
begin
result = Spotify.search(method, params[:query].to_s)
rescue
m.reply "problems connecting to Spotify"
end
if result.nil?
m.reply "no results"
return
end
case method
when 'track'
reply = _("%{b}%{artist}%{b} – %{track}") % {
:artist => result.artist.name,
:track => result.name,
:b => Bold
}
if result.album.released
reply << _(" [%{u}%{album}%{u}, %{released}]") % {
:released => result.album.released,
:album => result.album.name,
:u => Underline
}
else
reply << _(" [%{u}%{album}%{u}]") % { :album => result.album.name, :u => Underline }
end
reply << _(" — %{url}") % { :url => result.url }
when 'artist'
reply = _("%{b}%{artist}%{b} — %{url}") % {
:b => Bold,
:artist => result.name,
:url => result.url
}
when 'album'
reply = _("%{b}%{artist}%{b} – %{u}%{album}%{u} — %{url}") % {
:b => Bold,
:u => Underline,
:artist => result.artist.name,
:album => result.name,
:url => result.url
}
end
m.reply reply
end
end
plugin = SpotifyPlugin.new
plugin.map 'spotify [:method] *query', :action => :search, :requirements => { :method => /track|artist|album/ }
|