uwa_download 0.1
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/lib/uwa_download/config.rb +29 -0
- data/lib/uwa_download/widget.rb +64 -0
- data/resources/script.js +36 -0
- data/resources/style.css +21 -0
- metadata +57 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'uwa'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module UWA
|
6
|
+
module Widget
|
7
|
+
class Download < UWA::Handler
|
8
|
+
NAME = 'uwa_download'
|
9
|
+
VERSION = '0.1'
|
10
|
+
COPYRIGHT = 'Copyright (C) 2007 Florent Solt'
|
11
|
+
DESC = 'UWA Download widget'
|
12
|
+
AUTHOR = 'Florent Solt'
|
13
|
+
EMAIL = 'florent@solt.biz'
|
14
|
+
HOMEPAGE = 'http://gnetvibes.rubyforge.org'
|
15
|
+
LICENSE = 'BSD'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Network buffer increase from 1024 to 4096
|
21
|
+
module Net
|
22
|
+
class BufferedIO
|
23
|
+
private
|
24
|
+
|
25
|
+
def rbuf_fill
|
26
|
+
timeout(@read_timeout) { @rbuf << @io.sysread(0x1000) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'uwa_download/config'
|
2
|
+
|
3
|
+
module UWA
|
4
|
+
module Widget
|
5
|
+
class Download
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@author = AUTHOR
|
10
|
+
@title = 'Download'
|
11
|
+
@threads = []
|
12
|
+
@destination = "/tmp/download"
|
13
|
+
@icon = "http://www.netvibes.com/img/icons/world.gif"
|
14
|
+
@bin = '/usr/bin/aria2c'
|
15
|
+
@args = '--allow-overwrite=true --log=/dev/null --listen-port=42066 --max-upload-limit=20K'
|
16
|
+
end
|
17
|
+
|
18
|
+
def download
|
19
|
+
start(@query['uri'].strip)
|
20
|
+
monitor
|
21
|
+
end
|
22
|
+
|
23
|
+
def monitor
|
24
|
+
@threads.delete_if { |t| !t.status }
|
25
|
+
self << JSON.unparse(@threads.collect do |t|
|
26
|
+
[
|
27
|
+
t[:download][:name],
|
28
|
+
t[:download][:percent] || 0,
|
29
|
+
t[:download][:speed] || 0
|
30
|
+
]
|
31
|
+
end)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def start(uri)
|
37
|
+
FileUtils.mkdir_p @destination
|
38
|
+
@threads << Thread.start do
|
39
|
+
begin
|
40
|
+
Thread.current[:download] = {}
|
41
|
+
Thread.current[:download][:name] = File.basename(uri)
|
42
|
+
fd = IO.popen("#{@bin} #{@args} --dir='#{@destination}' '#{uri}'")
|
43
|
+
loop do
|
44
|
+
select([fd], nil, nil)
|
45
|
+
buf = fd.sysread(0x1000).strip
|
46
|
+
percent = buf[/\d+%/]
|
47
|
+
Thread.current[:download][:percent] = percent.to_i unless percent.nil?
|
48
|
+
speed = buf[/\d+\.\d+ KB\/s/]
|
49
|
+
speed = buf[/D:\d+\.\d+ U:\d+\.\d+/] if speed.nil?
|
50
|
+
Thread.current[:download][:speed] = speed unless speed.nil?
|
51
|
+
end
|
52
|
+
rescue EOFError
|
53
|
+
fd.close
|
54
|
+
Thread.current[:download][:percent] = 100
|
55
|
+
UWA::Server.log(:download, "Finished #{uri.inspect}")
|
56
|
+
rescue Exception
|
57
|
+
UWA::Server.log(:download, "Error with #{uri.inspect} (#{$!.message})")
|
58
|
+
UWA::Server.log(:error, $!.backtrace)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/resources/script.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
widget.input = widget.createElement('input');
|
2
|
+
widget.input.type = 'text';
|
3
|
+
widget.input.className = 'uwa_input';
|
4
|
+
widget.input.onkeyup = function(ev) {
|
5
|
+
if (ev.keyCode == 13) {
|
6
|
+
widget.remoteJson('download?uri=' + encodeURIComponent(widget.input.value), widget.onMonitor);
|
7
|
+
widget.input.value = '';
|
8
|
+
}
|
9
|
+
}
|
10
|
+
widget.monitor = widget.createElement('ul');
|
11
|
+
widget.monitor.className = 'uwa_monitor';
|
12
|
+
|
13
|
+
widget.onLoad = function() {
|
14
|
+
widget.body.empty();
|
15
|
+
widget.body.appendChild(widget.input);
|
16
|
+
widget.body.appendChild(widget.monitor);
|
17
|
+
widget.remoteJson('monitor', widget.onMonitor);
|
18
|
+
}
|
19
|
+
|
20
|
+
widget.onRefresh = function() {
|
21
|
+
widget.remoteJson('monitor', widget.onMonitor);
|
22
|
+
}
|
23
|
+
|
24
|
+
widget.onMonitor = function(values) {
|
25
|
+
widget.monitor.empty();
|
26
|
+
if (values.length > 0) {
|
27
|
+
widget.setAutoRefresh(1);
|
28
|
+
} else {
|
29
|
+
widget.clearPeriodical('autoRefresh');
|
30
|
+
}
|
31
|
+
for (var i=0; i<values.length; i++) {
|
32
|
+
var li = widget.createElement('li');
|
33
|
+
li.appendText(values[i][0] + ' - ' + values[i][1] + '% - ' + values[i][2]);
|
34
|
+
widget.monitor.appendChild(li);
|
35
|
+
}
|
36
|
+
}
|
data/resources/style.css
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
.uwa_input {
|
2
|
+
background-image: url(http://www.netvibes.com/img/icons/attach.gif);
|
3
|
+
background-position: left center;
|
4
|
+
background-repeat: no-repeat;
|
5
|
+
width: 80%;
|
6
|
+
padding-left: 20px;
|
7
|
+
margin: auto;
|
8
|
+
display: block;
|
9
|
+
border: 1px solid #999;
|
10
|
+
padding-top: 2px;
|
11
|
+
padding-bottom: 2px;
|
12
|
+
margin-bottom: 4px;
|
13
|
+
}
|
14
|
+
|
15
|
+
.uwa_monitor LI {
|
16
|
+
background-image: url(http://www.netvibes.com/img/icons/page_white.gif);
|
17
|
+
background-position: left center;
|
18
|
+
background-repeat: no-repeat;
|
19
|
+
padding-left: 20px;
|
20
|
+
line-height: 18px;
|
21
|
+
}
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: uwa_download
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2007-04-06 00:00:00 +02:00
|
8
|
+
summary: UWA Download widget
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: florent@solt.biz
|
12
|
+
homepage: http://gnetvibes.rubyforge.org
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Florent Solt
|
31
|
+
files:
|
32
|
+
- lib/uwa_download/config.rb
|
33
|
+
- lib/uwa_download/widget.rb
|
34
|
+
- resources/script.js
|
35
|
+
- resources/style.css
|
36
|
+
test_files: []
|
37
|
+
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
executables: []
|
43
|
+
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
dependencies:
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: uwa
|
51
|
+
version_requirement:
|
52
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.0.0
|
57
|
+
version:
|