Class: Aria2::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/aria2.rb

Class Method Summary collapse

Class Method Details

.checkObject



19
20
21
22
23
24
25
26
# File 'lib/aria2.rb', line 19

def self.check
	begin
		self.rpc_call('getGlobalStat', [])
		true
	rescue
		false
	end
end

.download(url, path) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/aria2.rb', line 28

def self.download(url, path)
	path = File.expand_path(path)
	self.rpc_call('addUri', [[url], {
		'dir' => File.dirname(path), 
		'out' => File.basename(path),
		'allow-overwrite' => 'true'
	}])
end

.new(host = 'localhost', port = 6800) ⇒ Object



13
14
15
16
17
# File 'lib/aria2.rb', line 13

def self.new(host = 'localhost', port = 6800)
	@host = host
	@port = port
	self
end

.query_status(gid) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aria2.rb', line 37

def self.query_status(gid)
	status = self.rpc_call('tellStatus', [gid, [
		'status', 
		'totalLength', 
		'completedLength', 
		'downloadSpeed', 
		'errorCode'
	]])

	status['totalLength'] = status['totalLength'].to_i
	status['completedLength'] = status['completedLength'].to_i
	status['downloadSpeed'] = status['downloadSpeed'].to_i
	status['errorCode'] = status['errorCode'].to_i

	status['progress'] = status['totalLength'] == 0 ? 
		0 :
		status['completedLength'].to_f / status['totalLength'].to_f

	status['remainingTime'] = status['downloadSpeed'] == 0 ?
		0 :
		(status['totalLength'] - status['completedLength']).to_f / status['downloadSpeed']

	status
end

.remove(gid) ⇒ Object



62
63
64
# File 'lib/aria2.rb', line 62

def self.remove(gid)
	self.rpc_call('remove', [gid]) == gid
end