From: Matthias H Date: Thu, 20 Feb 2014 22:28:52 +0000 (+0100) Subject: [plugin] spotify plugin removed X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=8fcda482961f90edad361dd7a47fb2a8dfeb5c70;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git [plugin] spotify plugin removed --- diff --git a/data/rbot/plugins/lib_spotify.rb b/data/rbot/plugins/lib_spotify.rb deleted file mode 100644 index 24caf428..00000000 --- a/data/rbot/plugins/lib_spotify.rb +++ /dev/null @@ -1,84 +0,0 @@ -#-- vim:sw=2:et -#++ -# -# :title: spotify library used at least in spotify and lastfm plugins -# -# Author:: Raine Virta -# -# Copyright:: (C) 2009 Raine Virta -# -# License:: GPL v2 - -require 'rexml/document' -require 'cgi' - -module ::Spotify - class SpotifyObject - def initialize(xml) - @spotify_id = xml.attributes["href"] - end - - def url - id = @spotify_id[@spotify_id.rindex(':')+1..-1] - method = self.class.to_s.split('::').last.downcase - return "http://open.spotify.com/#{method}/#{id}" - end - end - - class Album < SpotifyObject - attr_reader :name, :released, :artist - - def initialize(xml) - super - @name = xml.elements["name"].text - if e = xml.elements["artist"] - @artist = Artist.new(xml.elements["artist"]) - end - if e = xml.elements["released"] - @released = e.text.to_i - end - end - end - - class Artist < SpotifyObject - attr_reader :name - - def initialize(xml) - super - @name = xml.elements["name"].text - end - end - - class Track < SpotifyObject - attr_reader :name, :artist, :album, :track_number - - def initialize(xml) - super - @name = xml.elements["name"].text - @artist = Artist.new(xml.elements["artist"]) - @album = Album.new(xml.elements["album"]) - @track_number = xml.elements["track-number"].text.to_i - @length = xml.elements["length"].text.to_f - end - - def to_s - str = "#{artist.name} – #{name} [#{album.name}" - str << ", #{album.released}" if album.released - str << "]" - end - end - - 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(url) - raise unless xml - return REXML::Document.new(xml).root - end - - def self.search(method, query, page=1) - doc = get(:search, method, query, page) - return nil if doc.elements["opensearch:totalResults"].text.to_i.zero? - return Spotify.const_get(method.to_s.capitalize).new(doc.elements[method.to_s]) - end -end diff --git a/data/rbot/plugins/spotify.rb b/data/rbot/plugins/spotify.rb deleted file mode 100644 index 29331c00..00000000 --- a/data/rbot/plugins/spotify.rb +++ /dev/null @@ -1,78 +0,0 @@ -#-- vim:sw=2:et -#++ -# -# :title: spotify plugin for rbot -# -# Author:: Raine Virta -# -# Copyright:: (C) 2009 Raine Virta -# -# License:: GPL v2 - -class SpotifyPlugin < Plugin - def initialize - super - - unless Object.const_defined?('Spotify') - raise 'Spotify module not found (lib_spotify plugin probably not enabled)' - end - end - - def help(plugin, topic) - _("spotify plugin - usage: spotify , spotify artist , spotify 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/ }