require "xmpp4r/client" require "drb" module Saber class Server def self.start # register on_finished event. Retort::Service.call("system.method.set_key", "event.download.finished", "saber-download", "execute= /usr/bin/saber-drb_add, $d.get_hash=, $d.get_custom1=") s = Server.new DRbServer.start(s) s.start Thread.list.each {|v| v.join} end attr_reader :client def initialize @client = Jabber::Client.new(Jabber::JID.new(Rc.server.xmpp.jid)) end def start client.connect Rc.server.xmpp.host, Rc.server.xmpp.port client.auth Rc.server.xmpp.password client.send Jabber::Presence.new Saber.ui.say ">> Connected to xmpp with #{Rc.server.xmpp.jid}" end def send(files) $log.debug %~::send::\n #{files.join("\n")}~ client.send Jabber::Message.new(Rc.client.xmpp.jid, files.join("\n")) end end class DRbServer class << self def start(saber_server) DRbServer.new(saber_server).start end end attr_reader :saber_server # @params [Server] server def initialize(saber_server) @saber_server = saber_server end def start DRb.start_service Rc.drb_uri, self Saber.ui.say ">> DRbSever listening on #{Rc.drb_uri}" end # drb. add a complete torrent. def add(*names) $log.debug "::DRbServer add:: #{names.inspect}" files = build_files(*names) saber_server.send(files) end private # ["filea", "foo/filea", "foo/fileb"] def build_files(*names) Pa.ls2_r(*names, :base_dir => Rc.server.download, :file => true, :include => true) { |path| not Pa.directory?(path) } end end end