4 # :title: lastfm plugin for rbot
6 # Author:: Jeremy Voorhis
7 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
9 # Copyright:: (C) 2005 Jeremy Voorhis
10 # Copyright:: (C) 2007 Giuseppe Bilotta
16 class LastFmPlugin < Plugin
18 LASTFM = "http://www.last.fm"
20 def help(plugin, topic="")
23 "lastfm artist <name> => show information on artist/group <name> from last.fm"
25 "lastfm track <name> => show information on track/song <name> from last.fm [not implemented yet]"
27 "lastfm album <name> => show information on album <name> from last.fm"
29 "lastfm <function> <user> => lastfm data for <user> on last.fm where <function> in [recenttracks, topartists, topalbums, toptracks, tags, friends, neighbors]. other topics: artist, group, song, track, album"
34 action = params[:action].intern
35 action = :neighbours if action == :neighbors
41 esc = URI.escape(artist)
42 page = @bot.httputil.get "#{LASTFM}/music/#{esc}"
44 if page.match(/<h1 class="h1artist"><a href="([^"]+)">(.*?)<\/a><\/h1>/)
48 raise "No URL/Title found for #{artist}"
51 wiki = page.match(/<div class="wikiAbstract">(.*?)<\/div>/m)[1].ircify_html
52 m.reply "%s : %s\n%s" % [title, url, wiki]
54 m.reply "no data found on #{artist}"
57 m.reply "I had problems looking for #{artist}"
62 m.reply "not implemented yet, sorry"
64 m.reply "not implemented yet, sorry"
66 return usage unless what.length == 1
69 data = open("http://ws.audioscrobbler.com/1.0/user/#{user}/#{action}.txt")
70 m.reply "#{action} for #{user}:"
71 m.reply data.to_a[0..3].map{|l| l.split(',',2)[-1].chomp}.join(", ")
73 m.reply "could not find #{action} for #{user} (is #{user} a user?)"
79 plugin = LastFmPlugin.new
80 plugin.map 'lastfm :action *what'