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