mirror of https://github.com/aria2/aria2
				
				
				
			2009-09-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added XML-RPC client scripts written in ruby. * doc/Makefile.am * doc/xmlrpc/aria2mon * doc/xmlrpc/aria2rpcpull/1/head
							parent
							
								
									ce25b54cfe
								
							
						
					
					
						commit
						d85743cd6d
					
				| 
						 | 
				
			
			@ -1,3 +1,10 @@
 | 
			
		|||
2009-09-01  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 | 
			
		||||
 | 
			
		||||
	Added XML-RPC client scripts written in ruby.
 | 
			
		||||
	* doc/Makefile.am
 | 
			
		||||
	* doc/xmlrpc/aria2mon
 | 
			
		||||
	* doc/xmlrpc/aria2rpc
 | 
			
		||||
 | 
			
		||||
2009-08-31  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 | 
			
		||||
 | 
			
		||||
	Added support for IPv6 literal address in URI. Now aria2 can
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,6 @@
 | 
			
		|||
man_MANS = aria2c.1
 | 
			
		||||
EXTRA_DIST = $(man_MANS)
 | 
			
		||||
dist_doc_DATA = aria2c.1.html
 | 
			
		||||
doc_xmlrpcdir = $(docdir)/xmlrpc
 | 
			
		||||
dist_doc_xmlrpc_DATA = xmlrpc/aria2mon \
 | 
			
		||||
	xmlrpc/aria2rpc
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,8 +34,8 @@ build_triplet = @build@
 | 
			
		|||
host_triplet = @host@
 | 
			
		||||
target_triplet = @target@
 | 
			
		||||
subdir = doc
 | 
			
		||||
DIST_COMMON = $(dist_doc_DATA) $(srcdir)/Makefile.am \
 | 
			
		||||
	$(srcdir)/Makefile.in
 | 
			
		||||
DIST_COMMON = $(dist_doc_DATA) $(dist_doc_xmlrpc_DATA) \
 | 
			
		||||
	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
 | 
			
		||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 | 
			
		||||
am__aclocal_m4_deps = $(top_srcdir)/m4/aria2_arg.m4 \
 | 
			
		||||
	$(top_srcdir)/m4/codeset.m4 $(top_srcdir)/m4/cppunit.m4 \
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +66,8 @@ CONFIG_CLEAN_FILES =
 | 
			
		|||
SOURCES =
 | 
			
		||||
DIST_SOURCES =
 | 
			
		||||
man1dir = $(mandir)/man1
 | 
			
		||||
am__installdirs = "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(docdir)"
 | 
			
		||||
am__installdirs = "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(docdir)" \
 | 
			
		||||
	"$(DESTDIR)$(doc_xmlrpcdir)"
 | 
			
		||||
NROFF = nroff
 | 
			
		||||
MANS = $(man_MANS)
 | 
			
		||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +77,8 @@ am__vpath_adj = case $$p in \
 | 
			
		|||
  esac;
 | 
			
		||||
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
 | 
			
		||||
dist_docDATA_INSTALL = $(INSTALL_DATA)
 | 
			
		||||
DATA = $(dist_doc_DATA)
 | 
			
		||||
dist_doc_xmlrpcDATA_INSTALL = $(INSTALL_DATA)
 | 
			
		||||
DATA = $(dist_doc_DATA) $(dist_doc_xmlrpc_DATA)
 | 
			
		||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 | 
			
		||||
ACLOCAL = @ACLOCAL@
 | 
			
		||||
ALLOCA = @ALLOCA@
 | 
			
		||||
| 
						 | 
				
			
			@ -257,6 +259,10 @@ top_srcdir = @top_srcdir@
 | 
			
		|||
man_MANS = aria2c.1
 | 
			
		||||
EXTRA_DIST = $(man_MANS)
 | 
			
		||||
dist_doc_DATA = aria2c.1.html
 | 
			
		||||
doc_xmlrpcdir = $(docdir)/xmlrpc
 | 
			
		||||
dist_doc_xmlrpc_DATA = xmlrpc/aria2mon \
 | 
			
		||||
	xmlrpc/aria2rpc
 | 
			
		||||
 | 
			
		||||
all: all-am
 | 
			
		||||
 | 
			
		||||
.SUFFIXES:
 | 
			
		||||
| 
						 | 
				
			
			@ -351,6 +357,23 @@ uninstall-dist_docDATA:
 | 
			
		|||
	  echo " rm -f '$(DESTDIR)$(docdir)/$$f'"; \
 | 
			
		||||
	  rm -f "$(DESTDIR)$(docdir)/$$f"; \
 | 
			
		||||
	done
 | 
			
		||||
install-dist_doc_xmlrpcDATA: $(dist_doc_xmlrpc_DATA)
 | 
			
		||||
	@$(NORMAL_INSTALL)
 | 
			
		||||
	test -z "$(doc_xmlrpcdir)" || $(MKDIR_P) "$(DESTDIR)$(doc_xmlrpcdir)"
 | 
			
		||||
	@list='$(dist_doc_xmlrpc_DATA)'; for p in $$list; do \
 | 
			
		||||
	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
 | 
			
		||||
	  f=$(am__strip_dir) \
 | 
			
		||||
	  echo " $(dist_doc_xmlrpcDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(doc_xmlrpcdir)/$$f'"; \
 | 
			
		||||
	  $(dist_doc_xmlrpcDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(doc_xmlrpcdir)/$$f"; \
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
uninstall-dist_doc_xmlrpcDATA:
 | 
			
		||||
	@$(NORMAL_UNINSTALL)
 | 
			
		||||
	@list='$(dist_doc_xmlrpc_DATA)'; for p in $$list; do \
 | 
			
		||||
	  f=$(am__strip_dir) \
 | 
			
		||||
	  echo " rm -f '$(DESTDIR)$(doc_xmlrpcdir)/$$f'"; \
 | 
			
		||||
	  rm -f "$(DESTDIR)$(doc_xmlrpcdir)/$$f"; \
 | 
			
		||||
	done
 | 
			
		||||
tags: TAGS
 | 
			
		||||
TAGS:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -388,7 +411,7 @@ check-am: all-am
 | 
			
		|||
check: check-am
 | 
			
		||||
all-am: Makefile $(MANS) $(DATA)
 | 
			
		||||
installdirs:
 | 
			
		||||
	for dir in "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(docdir)"; do \
 | 
			
		||||
	for dir in "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(docdir)" "$(DESTDIR)$(doc_xmlrpcdir)"; do \
 | 
			
		||||
	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
 | 
			
		||||
	done
 | 
			
		||||
install: install-am
 | 
			
		||||
| 
						 | 
				
			
			@ -433,7 +456,8 @@ info: info-am
 | 
			
		|||
 | 
			
		||||
info-am:
 | 
			
		||||
 | 
			
		||||
install-data-am: install-dist_docDATA install-man
 | 
			
		||||
install-data-am: install-dist_docDATA install-dist_doc_xmlrpcDATA \
 | 
			
		||||
	install-man
 | 
			
		||||
 | 
			
		||||
install-dvi: install-dvi-am
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -467,7 +491,8 @@ ps: ps-am
 | 
			
		|||
 | 
			
		||||
ps-am:
 | 
			
		||||
 | 
			
		||||
uninstall-am: uninstall-dist_docDATA uninstall-man
 | 
			
		||||
uninstall-am: uninstall-dist_docDATA uninstall-dist_doc_xmlrpcDATA \
 | 
			
		||||
	uninstall-man
 | 
			
		||||
 | 
			
		||||
uninstall-man: uninstall-man1
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -476,14 +501,15 @@ uninstall-man: uninstall-man1
 | 
			
		|||
.PHONY: all all-am check check-am clean clean-generic distclean \
 | 
			
		||||
	distclean-generic distdir dvi dvi-am html html-am info info-am \
 | 
			
		||||
	install install-am install-data install-data-am \
 | 
			
		||||
	install-dist_docDATA install-dvi install-dvi-am install-exec \
 | 
			
		||||
	install-exec-am install-html install-html-am install-info \
 | 
			
		||||
	install-info-am install-man install-man1 install-pdf \
 | 
			
		||||
	install-pdf-am install-ps install-ps-am install-strip \
 | 
			
		||||
	installcheck installcheck-am installdirs maintainer-clean \
 | 
			
		||||
	maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
 | 
			
		||||
	pdf-am ps ps-am uninstall uninstall-am uninstall-dist_docDATA \
 | 
			
		||||
	uninstall-man uninstall-man1
 | 
			
		||||
	install-dist_docDATA install-dist_doc_xmlrpcDATA install-dvi \
 | 
			
		||||
	install-dvi-am install-exec install-exec-am install-html \
 | 
			
		||||
	install-html-am install-info install-info-am install-man \
 | 
			
		||||
	install-man1 install-pdf install-pdf-am install-ps \
 | 
			
		||||
	install-ps-am install-strip installcheck installcheck-am \
 | 
			
		||||
	installdirs maintainer-clean maintainer-clean-generic \
 | 
			
		||||
	mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \
 | 
			
		||||
	uninstall-am uninstall-dist_docDATA \
 | 
			
		||||
	uninstall-dist_doc_xmlrpcDATA uninstall-man uninstall-man1
 | 
			
		||||
 | 
			
		||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
 | 
			
		||||
# Otherwise a system limit (for SysV at least) may be exceeded.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,141 @@
 | 
			
		|||
#!/usr/bin/env ruby
 | 
			
		||||
# The MIT License
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2009 Tatsuhiro Tsujikawa
 | 
			
		||||
#
 | 
			
		||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
# of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
# in the Software without restriction, including without limitation the rights
 | 
			
		||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
# copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
# furnished to do so, subject to the following conditions:
 | 
			
		||||
#
 | 
			
		||||
# The above copyright notice and this permission notice shall be included in
 | 
			
		||||
# all copies or substantial portions of the Software.
 | 
			
		||||
#
 | 
			
		||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
# THE SOFTWARE.
 | 
			
		||||
require 'xmlrpc/client'
 | 
			
		||||
require 'optparse'
 | 
			
		||||
 | 
			
		||||
program_name=File.basename($0)
 | 
			
		||||
options={}
 | 
			
		||||
args=nil
 | 
			
		||||
OptionParser.new do |opt|
 | 
			
		||||
  opt.on("--server SERVER", "hostname of XML-RPC server. Default: localhost"){|val| options["server"]=val }
 | 
			
		||||
  opt.on("--port PORT", "port of XML-RPC server. Default: 6800"){|val| options["port"]=val }
 | 
			
		||||
 | 
			
		||||
  opt.on("--user USERNAME", "XML-RPC username"){|val| options["user"]=val }
 | 
			
		||||
  opt.on("--passwd PASSWORD", "XML-RPC password"){|val| options["passwd"]=val }
 | 
			
		||||
 | 
			
		||||
  opt.banner=<<EOS
 | 
			
		||||
Usage: #{program_name} [options]
 | 
			
		||||
EOS
 | 
			
		||||
  
 | 
			
		||||
  args=opt.parse(ARGV)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def compute_eta speed,rem_length
 | 
			
		||||
  return "n/a" if speed == 0
 | 
			
		||||
  remsec=rem_length/speed
 | 
			
		||||
  hr=remsec/3600
 | 
			
		||||
  remsec=remsec%3600
 | 
			
		||||
  min=remsec/60
 | 
			
		||||
  remsec=remsec%60
 | 
			
		||||
  result=""
 | 
			
		||||
  result += "#{hr}h" if hr > 0
 | 
			
		||||
  result += "#{min}m" if min > 0
 | 
			
		||||
  result += "#{remsec}s"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
def abbrev value
 | 
			
		||||
  n=value/1024.0
 | 
			
		||||
  if n < 1 then
 | 
			
		||||
    return "#{value}"
 | 
			
		||||
  end
 | 
			
		||||
  value=n
 | 
			
		||||
  n=value/1024.0
 | 
			
		||||
  if n < 1 then
 | 
			
		||||
    return sprintf("%.1fKi", value)
 | 
			
		||||
  else
 | 
			
		||||
    return sprintf("%.1fMi", n)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
auth=""
 | 
			
		||||
if options.has_key?("user") then
 | 
			
		||||
  auth=options["user"]+":"+options["passwd"]+"@"
 | 
			
		||||
end
 | 
			
		||||
if not options.has_key?("server") then
 | 
			
		||||
  options["server"]="localhost"
 | 
			
		||||
end
 | 
			
		||||
if not options.has_key?("port") then
 | 
			
		||||
  options["port"]="6800"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
client=XMLRPC::Client.new3({:host => options["server"],
 | 
			
		||||
                             :port => options["port"],
 | 
			
		||||
                             :path => "/rpc",
 | 
			
		||||
                             :user => options["user"],
 | 
			
		||||
                             :password => options["passwd"]})
 | 
			
		||||
 | 
			
		||||
result=client.call("aria2.tellActive")
 | 
			
		||||
 | 
			
		||||
print "-- Download Progress --\n"
 | 
			
		||||
result.each { |entry|
 | 
			
		||||
  gid=entry['gid']
 | 
			
		||||
  total_length=entry['totalLength'].to_i
 | 
			
		||||
  completed_length=entry['completedLength'].to_i
 | 
			
		||||
  upload_length=entry['uploadLength'].to_i
 | 
			
		||||
  download_speed=entry['downloadSpeed'].to_i
 | 
			
		||||
  print "GID##{gid}"
 | 
			
		||||
  if total_length == completed_length then
 | 
			
		||||
    if entry.key? 'infoHash' then
 | 
			
		||||
      # for BitTorrent print seed status
 | 
			
		||||
      print " SEEDING"
 | 
			
		||||
      if completed_length > 0 then
 | 
			
		||||
        print "(#{upload_length*100/completed_length}%)"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  else
 | 
			
		||||
    print " SIZE:#{abbrev completed_length}B/#{abbrev total_length}B"
 | 
			
		||||
    if total_length > 0 then
 | 
			
		||||
      print "(#{completed_length*100/total_length}%)"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  print " CN:#{entry['connections']}"
 | 
			
		||||
  if entry.key? 'numSeeders' then
 | 
			
		||||
    print " SEED:#{entry['numSeeders']}"
 | 
			
		||||
  end
 | 
			
		||||
  print " SPD:#{abbrev download_speed}B/s"
 | 
			
		||||
  if entry.key? 'infoHash'
 | 
			
		||||
    printf " UP:#{abbrev entry['uploadSpeed'].to_i}B/s(#{abbrev upload_length}B)"
 | 
			
		||||
  end
 | 
			
		||||
  print " ETA:#{compute_eta(download_speed, total_length-completed_length)}"
 | 
			
		||||
  print "\n"
 | 
			
		||||
 | 
			
		||||
  if entry.key? 'infoHash'
 | 
			
		||||
    print " InfoHash:#{entry['infoHash']}"
 | 
			
		||||
  end
 | 
			
		||||
  print "\n"
 | 
			
		||||
 | 
			
		||||
  files=client.call("aria2.getFiles",entry['gid'])
 | 
			
		||||
  if files.length > 0 then
 | 
			
		||||
    first_file=files.find{|file| file["selected"]=="true"}
 | 
			
		||||
    if first_file != nil then
 | 
			
		||||
      print " File:#{first_file['path']}"
 | 
			
		||||
      count=0
 | 
			
		||||
      files.each {|file| count += 1 if file["selected"]=="true"}
 | 
			
		||||
      if count > 1 then
 | 
			
		||||
        print "(#{count-1}more)"
 | 
			
		||||
      end
 | 
			
		||||
      print "\n"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  print "--------------------------------------------------------------------------------"
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,256 @@
 | 
			
		|||
#!/usr/bin/env ruby
 | 
			
		||||
# The MIT License
 | 
			
		||||
#
 | 
			
		||||
# Copyright (c) 2009 Tatsuhiro Tsujikawa
 | 
			
		||||
#
 | 
			
		||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
# of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
# in the Software without restriction, including without limitation the rights
 | 
			
		||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
# copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
# furnished to do so, subject to the following conditions:
 | 
			
		||||
#
 | 
			
		||||
# The above copyright notice and this permission notice shall be included in
 | 
			
		||||
# all copies or substantial portions of the Software.
 | 
			
		||||
#
 | 
			
		||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
# THE SOFTWARE.
 | 
			
		||||
require 'xmlrpc/client'
 | 
			
		||||
require 'pp'
 | 
			
		||||
require 'optparse'
 | 
			
		||||
 | 
			
		||||
program_name=File.basename($0)
 | 
			
		||||
options={}
 | 
			
		||||
args=nil
 | 
			
		||||
OptionParser.new do |opt|
 | 
			
		||||
  opt.on("-d","--dir DIR"){|val| options["dir"]=val}
 | 
			
		||||
  opt.on("-V","--check-integrity [BOOL]", ["true","false"]){|val|
 | 
			
		||||
    options["check-integrity"]= val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("-c","--continue [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["continue"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--all-proxy PROXY"){|val| options["all-proxy"]=val}
 | 
			
		||||
  opt.on("--connect-timeout SEC"){|val| options["connect-timeout"]=val}
 | 
			
		||||
  opt.on("--dry-run [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["dry-run"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--lowest-speed-limit SPEED"){|val| options["lowest-speed-limit"]=val}
 | 
			
		||||
  opt.on("--max-file-not-found NUM"){|val| options["max-file-not-found"]=val}
 | 
			
		||||
  opt.on("-m","--max-tries N"){|val| options["max-tries"]=val}
 | 
			
		||||
  opt.on("--no-proxy DOMAINS"){|val| options["no-proxy"]=val}
 | 
			
		||||
  opt.on("-o","--out FILE"){|val| options["out"]=val}
 | 
			
		||||
  opt.on("--proxy-method METHOD"){|val| options["proxy-method"]=val}
 | 
			
		||||
  opt.on("-R","--remote-time [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["remote-time"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--retry-wait SEC"){|val| options["retry-wait"]=val}
 | 
			
		||||
  opt.on("-s","--split N"){|val| options["split"]=val}
 | 
			
		||||
  opt.on("-t","--timeout SEC"){|val| options["timeout"]=val}
 | 
			
		||||
  opt.on("--http-auth-challenge [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["http-auth-challenge"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--http-user USER"){|val| options["http-user"]=val}
 | 
			
		||||
  opt.on("--http-passwd PASSWD"){|val| options["http-passwd"]=val}
 | 
			
		||||
  opt.on("--http-proxy PROXY"){|val| options["http-proxy"]=val}
 | 
			
		||||
  opt.on("--https-proxy PROXY"){|val| options["https-proxy"]=val}
 | 
			
		||||
  opt.on("--referer REFERER"){|val| options["referer"]=val}
 | 
			
		||||
  opt.on("--enable-http-keep-alive [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["enable-http-keep-alive"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--enable-http-pipelining [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["enable-http-pipelining"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--header HEADER"){|val|
 | 
			
		||||
    options["header"] = [] if options["header"] == nil
 | 
			
		||||
    options["header"] << val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--use-head [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["use-head"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("-U","--user-agent USERAGENT"){|val| options["user-agent"]=val}
 | 
			
		||||
  opt.on("--ftp-user USER"){|val| options["ftp-user"]=val}
 | 
			
		||||
  opt.on("--ftp-passwd PASSWD"){|val| options["ftp-passwd"]=val}
 | 
			
		||||
  opt.on("-p","--ftp-pasv [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["ftp-pasv"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--ftp-proxy PROXY"){|val| options["ftp-proxy"]=val}
 | 
			
		||||
  opt.on("--ftp-type TYPE"){|val| options["ftp-type"]=val}
 | 
			
		||||
  opt.on("--ftp-reuse-connection [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["ftp-reuse-connection"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("-n","--no-netrc [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["no-netrc"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--select-file INDEXES"){|val| options["select-file"]=val}
 | 
			
		||||
  opt.on("--bt-external-ip IPADDRESS"){|val| options["bt-external-ip"]=val}
 | 
			
		||||
  opt.on("--bt-hash-check-seed [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["bt-hash-check-seed"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--bt-max-open-files NUM"){|val| options["bt-max-open-files"]=val}
 | 
			
		||||
  opt.on("--bt-max-peers NUM"){|val| options["bt-max-peers"]=val}
 | 
			
		||||
  opt.on("--bt-min-crypto-level LEVEL",["plain","arc4"]){|val|
 | 
			
		||||
    options["bt-min-crypto-level"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--bt-require-crypto BOOL",["true","false"]){|val|
 | 
			
		||||
    options["bt-require-crypto"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--bt-request-peer-speed-limit SPEED"){|val|
 | 
			
		||||
    options["bt-request-peer-speed-limit"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--bt-seed-unverified [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["bt-seed-unverified"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--bt-stop-timeout SEC"){|val| options["bt-stop-timeout"]=val}
 | 
			
		||||
  opt.on("--bt-tracker-interval SEC"){|val| options["bt-tracker-interval"]=val}
 | 
			
		||||
  opt.on("--enable-peer-exchange [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["enable-peer-exchange"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--follow-torrent VALUE", ["true","false","mem"]){|val|
 | 
			
		||||
    options["follow-torrent"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("-O","--index-out INDEXPATH"){|val|
 | 
			
		||||
    options["index-out"]=[] if options["index-out"] == nil
 | 
			
		||||
    options["index-out"] << val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("-u","--max-upload-limit SPEED"){|val| options["max-upload-limit"]=val}
 | 
			
		||||
  opt.on("--seed-ratio RATIO"){|val| options["seed-ratio"]=val}
 | 
			
		||||
  opt.on("--seed-time MINUTES"){|val| options["seed-time"]=val}
 | 
			
		||||
  opt.on("--follow-metalink VALUE", ["true","false","mem"]){|val|
 | 
			
		||||
    options["follow-metalink"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("-C","--metalink-servers NUM"){|val| options["metalink-servers"]=val}
 | 
			
		||||
  opt.on("--metalink-language LANG"){|val| options["metalink-language"]=val}
 | 
			
		||||
  opt.on("--metalink-location LOCS"){|val| options["metalink-location"]=val}
 | 
			
		||||
  opt.on("--metalink-os OS"){|val| options["metalink-os"]=val}
 | 
			
		||||
  opt.on("--metalink-version VERSION"){|val| options["metalink-version"]=val}
 | 
			
		||||
  opt.on("--metalink-preferred-protocol PROTO"){|val|
 | 
			
		||||
    options["metalink-preferred-protocol"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--metalink-enable-unique-protocol BOOL",["true","false"]){|val|
 | 
			
		||||
    options["metalink-enable-unique-protocol"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--allow-overwrite BOOL",["true","false"]){|val|
 | 
			
		||||
    options["allow-overwrite"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--allow-piece-length-change BOOL",["true","false"]){|val|
 | 
			
		||||
    options["allow-piece-length-change"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--async-dns [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["async-dns"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--auto-file-renaming [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["auto-file-renaming"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--file-allocation METHOD",["none","prealloc","falloc"]){|val|
 | 
			
		||||
    options["file-allocation"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--max-download-limit LIMIT"){|val| options["max-download-limit"]=val}
 | 
			
		||||
  opt.on("--no-file-allocation-limit SIZE"){|val|
 | 
			
		||||
    options["no-file-allocation-limit"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("-P","--parameterized-uri [BOOL]",["true","false"]){|val|
 | 
			
		||||
    options["parameterized-uri"]=val||"true"
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--realtime-chunk-checksum BOOL",["true","false"]){|val|
 | 
			
		||||
    options["realtime-chunk-checksum"]=val
 | 
			
		||||
  }
 | 
			
		||||
  opt.on("--max-overall-download-limit LIMIT"){|val| options["max-overall-download-limit"]=val}
 | 
			
		||||
  opt.on("--max-overall-upload-limit LIMIT"){|val| options["max-overall-upload-limit"]=val}
 | 
			
		||||
  opt.on("-j","--max-concurrent-downloads N"){|val| options["max-concurrent-downloads"]=val}
 | 
			
		||||
 | 
			
		||||
  opt.on("--server SERVER", "hostname of XML-RPC server. Default: localhost"){|val| options["server"]=val }
 | 
			
		||||
  opt.on("--port PORT", "port of XML-RPC server. Default: 6800"){|val| options["port"]=val }
 | 
			
		||||
 | 
			
		||||
  opt.on("--user USERNAME", "XML-RPC username"){|val| options["user"]=val }
 | 
			
		||||
  opt.on("--passwd PASSWORD", "XML-RPC password"){|val| options["passwd"]=val }
 | 
			
		||||
 | 
			
		||||
  opt.banner=<<EOS
 | 
			
		||||
Usage: #{program_name} addUri URI... [options]
 | 
			
		||||
       #{program_name} addTorrent /path/to/torrent_file URI... [options]
 | 
			
		||||
       #{program_name} addMetalink /path/to/metalink_file [options]
 | 
			
		||||
       #{program_name} tellStatus GID [options]
 | 
			
		||||
       #{program_name} tellActive [options]
 | 
			
		||||
       #{program_name} tellWaiting [options]
 | 
			
		||||
       #{program_name} getFiles   GID [options]
 | 
			
		||||
       #{program_name} getUris    GID [options]
 | 
			
		||||
       #{program_name} getPeers   GID [options]
 | 
			
		||||
       #{program_name} purgeDownloadResult [options]
 | 
			
		||||
       #{program_name} changeOption GID [options]
 | 
			
		||||
       #{program_name} changeGlobalOption [options]
 | 
			
		||||
       #{program_name} getVersion [options]
 | 
			
		||||
EOS
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  args=opt.parse(ARGV)
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if !args or args.size == 0 then
 | 
			
		||||
  puts "No command specified"
 | 
			
		||||
  exit 1
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
command=args[0]
 | 
			
		||||
resources=args[1..-1]
 | 
			
		||||
 | 
			
		||||
auth=""
 | 
			
		||||
if options.has_key?("user") then
 | 
			
		||||
  auth=options["user"]+":"+options["passwd"]+"@"
 | 
			
		||||
end
 | 
			
		||||
if not options.has_key?("server") then
 | 
			
		||||
  options["server"]="localhost"
 | 
			
		||||
end
 | 
			
		||||
if not options.has_key?("port") then
 | 
			
		||||
  options["port"]="6800"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
client=XMLRPC::Client.new3({:host => options["server"],
 | 
			
		||||
                             :port => options["port"],
 | 
			
		||||
                             :path => "/rpc",
 | 
			
		||||
                             :user => options["user"],
 | 
			
		||||
                             :password => options["passwd"]})
 | 
			
		||||
 
 | 
			
		||||
if command == "addUri" then
 | 
			
		||||
  result=client.call("aria2."+command, resources, options)
 | 
			
		||||
elsif command == "addTorrent" then
 | 
			
		||||
  torrentData=IO.read(resources[0])
 | 
			
		||||
  result=client.call("aria2."+command,
 | 
			
		||||
                     XMLRPC::Base64.new(torrentData), resources[1..-1], options)
 | 
			
		||||
elsif command == "addMetalink" then
 | 
			
		||||
  metalinkData=IO.read(resources[0])
 | 
			
		||||
  result=client.call("aria2."+command,
 | 
			
		||||
                     XMLRPC::Base64.new(metalinkData), options)
 | 
			
		||||
elsif command == "tellStatus" then
 | 
			
		||||
  result=client.call("aria2."+command, resources[0])
 | 
			
		||||
elsif command == "tellActive" then
 | 
			
		||||
  result=client.call("aria2."+command)
 | 
			
		||||
elsif command == "tellWaiting" then
 | 
			
		||||
  result=client.call("aria2."+command, resources[0].to_i(), resources[1].to_i())
 | 
			
		||||
elsif command == "remove" then
 | 
			
		||||
  result=client.call("aria2."+command, resources[0])
 | 
			
		||||
elsif command == "getFiles" then
 | 
			
		||||
  result=client.call("aria2."+command, resources[0])
 | 
			
		||||
elsif command == "getUris" then
 | 
			
		||||
  result=client.call("aria2."+command, resources[0])
 | 
			
		||||
elsif command == "getPeers" then
 | 
			
		||||
  result=client.call("aria2."+command, resources[0])
 | 
			
		||||
elsif command == "purgeDownloadResult" then
 | 
			
		||||
  result=client.call("aria2."+command)
 | 
			
		||||
elsif command == "changeOption" then
 | 
			
		||||
  result=client.call("aria2."+command, resources[0], options)
 | 
			
		||||
elsif command == "changeGlobalOption" then
 | 
			
		||||
  result=client.call("aria2."+command, options)
 | 
			
		||||
elsif command == "getVersion" then
 | 
			
		||||
  result=client.call("aria2."+command)
 | 
			
		||||
else
 | 
			
		||||
  puts "Command not recognized"
 | 
			
		||||
  exit 1
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
pp result
 | 
			
		||||
		Loading…
	
		Reference in New Issue