leecher 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/leecher +80 -6
- data/lib/leecher/client.rb +2 -2
- data/lib/leecher/version.rb +1 -1
- metadata +4 -4
data/bin/leecher
CHANGED
@@ -42,6 +42,24 @@ module Leecher
|
|
42
42
|
@foreground = v
|
43
43
|
end
|
44
44
|
|
45
|
+
o.on("-q", "--print-queue",
|
46
|
+
"Print the active queue") do |v|
|
47
|
+
do_print_queue()
|
48
|
+
Kernel.exit!(RC_OK)
|
49
|
+
end
|
50
|
+
|
51
|
+
o.on("-p", "--pause",
|
52
|
+
"Pause downloads") do |v|
|
53
|
+
do_pause()
|
54
|
+
Kernel.exit!(RC_OK)
|
55
|
+
end
|
56
|
+
|
57
|
+
o.on("-r", "--unpause",
|
58
|
+
"Unpause downloads") do |v|
|
59
|
+
do_unpause()
|
60
|
+
Kernel.exit!(RC_OK)
|
61
|
+
end
|
62
|
+
|
45
63
|
o.separator("")
|
46
64
|
o.on("-h", "--help", "You're reading it :-)") do
|
47
65
|
puts o
|
@@ -91,6 +109,58 @@ module Leecher
|
|
91
109
|
log.info("Looking good, now take us for a real spin!")
|
92
110
|
end
|
93
111
|
|
112
|
+
# Somewhat lifted from
|
113
|
+
# http://sourceforge.net/apps/trac/aria2/browser/trunk/doc/xmlrpc/aria2mon
|
114
|
+
def do_print_queue()
|
115
|
+
config = load_config(@config_dirname)
|
116
|
+
client = make_client(config, @log)
|
117
|
+
log.info("Asking aria2 about it's active downloads ..")
|
118
|
+
active = client.call_rpc("aria2.tellActive")
|
119
|
+
active.each do |entry|
|
120
|
+
gid = entry["gid"]
|
121
|
+
complete, total, speed = [
|
122
|
+
"completedLength",
|
123
|
+
"totalLength",
|
124
|
+
"downloadSpeed",
|
125
|
+
].map do |field|
|
126
|
+
entry[field].to_i
|
127
|
+
end
|
128
|
+
remaining = total - complete
|
129
|
+
eta_str = if speed == 0
|
130
|
+
"N/A"
|
131
|
+
else
|
132
|
+
remsec = remaining/speed
|
133
|
+
hr = remsec/3600
|
134
|
+
remsec = remsec%3600
|
135
|
+
min = remsec/60
|
136
|
+
remsec = remsec%60
|
137
|
+
result = ""
|
138
|
+
result += "#{hr}h" if hr > 0
|
139
|
+
result += "#{min}m" if min > 0
|
140
|
+
result += "#{remsec}s"
|
141
|
+
end
|
142
|
+
no_files = entry["files"].size
|
143
|
+
first_file = entry["files"].first["uris"].first["uri"]
|
144
|
+
log.info("##{gid}: #{no_files} file(s) (currently: #{File.basename(first_file)}). "\
|
145
|
+
"#{complete}/#{total} (#{"%.2f" % (complete.to_f * 100 / total)}%). "\
|
146
|
+
"ETA: #{eta_str}")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def do_pause()
|
151
|
+
config = load_config(@config_dirname)
|
152
|
+
client = make_client(config, @log)
|
153
|
+
log.info("Asking aria2 to pause ..")
|
154
|
+
log.debug(client.call_rpc("aria2.pauseAll"))
|
155
|
+
end
|
156
|
+
|
157
|
+
def do_unpause()
|
158
|
+
config = load_config(@config_dirname)
|
159
|
+
client = make_client(config, @log)
|
160
|
+
log.info("Asking aria2 to pause ..")
|
161
|
+
log.debug(client.call_rpc("aria2.unpauseAll"))
|
162
|
+
end
|
163
|
+
|
94
164
|
def get_user_input(question, default)
|
95
165
|
default_text = case default
|
96
166
|
when :required, :password; nil
|
@@ -136,12 +206,7 @@ module Leecher
|
|
136
206
|
log.info("Fading into the ether ..")
|
137
207
|
make_daemon(config[:daemon])
|
138
208
|
end
|
139
|
-
client =
|
140
|
-
config[:password],
|
141
|
-
config[:metalink_queue_name],
|
142
|
-
config[:bunny_opts],
|
143
|
-
config[:aria2_opts],
|
144
|
-
@log)
|
209
|
+
client = make_client(config, @log)
|
145
210
|
client.run()
|
146
211
|
Kernel.exit(RC_OK)
|
147
212
|
end
|
@@ -188,6 +253,15 @@ module Leecher
|
|
188
253
|
end
|
189
254
|
end
|
190
255
|
end
|
256
|
+
|
257
|
+
def make_client(config, log)
|
258
|
+
Leecher::Client.new(config[:username],
|
259
|
+
config[:password],
|
260
|
+
config[:metalink_queue_name],
|
261
|
+
config[:bunny_opts],
|
262
|
+
config[:aria2_opts],
|
263
|
+
log)
|
264
|
+
end
|
191
265
|
end
|
192
266
|
end
|
193
267
|
|
data/lib/leecher/client.rb
CHANGED
@@ -118,7 +118,7 @@ module Leecher
|
|
118
118
|
# FIXME: is it possible something can go wrong but not throw an exception?
|
119
119
|
begin
|
120
120
|
uris, options = Yajl::Parser.parse(msg)
|
121
|
-
|
121
|
+
enqueue_with_aria(uris, options)
|
122
122
|
true
|
123
123
|
rescue Exception => e
|
124
124
|
log.error("Failed to add uri to aria2c: #{e.message}")
|
@@ -129,7 +129,7 @@ module Leecher
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
def
|
132
|
+
def enqueue_with_aria(uris, options)
|
133
133
|
rewrite_aria_dir_opt(options)
|
134
134
|
log.info("Will call aria2.addUri(#{uris.inspect()}, #{options.inspect()})")
|
135
135
|
status = call_rpc("aria2.addUri", uris, options)
|
data/lib/leecher/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leecher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marc Bowes
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-22 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|