rtorrent_xmlrpc 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/rtorrent_xmlrpc +5 -1
- data/lib/rtorrent_xmlrpc/torrent.rb +125 -0
- data/lib/rtorrent_xmlrpc/xmlrpc.rb +140 -0
- data/lib/rtorrent_xmlrpc.rb +1 -234
- data/methods.txt +1113 -0
- data/rtorrent_xmlrpc.gemspec +2 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c86aceddbf9e09b916268983bd63cf5a474cf77
|
4
|
+
data.tar.gz: df956f3f1c72817153881436aa1efe9bfb0218a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 703f7b8e98876f2f64597f2bbf5cecc122afb70ff94c6f59e7e6316c385cdc2b7dbb3fbd85c30adea9563dffdd49280870f5fcf2dc09b7996fa2d6f5f7a8a0bd
|
7
|
+
data.tar.gz: bb82d0251aebab977ecdd49458d143b18c7f23c2e4191282fea4064f94a9f7d2895b5d7c1228d6db395bfa9d0be0c0da5569efdb33d1166df1777e1e6cb557f9
|
data/Gemfile.lock
CHANGED
data/bin/rtorrent_xmlrpc
CHANGED
@@ -19,7 +19,7 @@ class RTorrent_XMLRPC < Thor
|
|
19
19
|
raise 'No config file found.' if config_file.nil?
|
20
20
|
config = Hashie::Mash.load(config_file)
|
21
21
|
# Connect to xmlrpc service
|
22
|
-
@xmlrpc = RTorrent::XMLRPC.
|
22
|
+
@xmlrpc = RTorrent::XMLRPC.new_from_hash(config.to_h)
|
23
23
|
@xmlrpc.connect
|
24
24
|
@xmlrpc.fetch_torrents
|
25
25
|
end
|
@@ -65,6 +65,10 @@ class RTorrent_XMLRPC < Thor
|
|
65
65
|
self.print @xmlrpc.with_label label
|
66
66
|
end
|
67
67
|
|
68
|
+
desc "files HASH", "Print the torrent information with files."
|
69
|
+
def files(hash)
|
70
|
+
# TODO:
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
74
|
RTorrent_XMLRPC.start(ARGV)
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'filesize'
|
3
|
+
require 'xmlrpc/client'
|
4
|
+
|
5
|
+
module RTorrent
|
6
|
+
|
7
|
+
class Torrent
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@labels = []
|
11
|
+
@files= []
|
12
|
+
end
|
13
|
+
|
14
|
+
# Attributes
|
15
|
+
attr_accessor :base_filename, :base_path, :completed, :files, :hash, :is_multi_file, :name, :tied_to_file
|
16
|
+
attr_reader :down_total, :labels, :priority, :ratio, :size, :up_total
|
17
|
+
|
18
|
+
def down_total=(down_total) # :nodoc:
|
19
|
+
@down_total = Filesize.new(down_total)
|
20
|
+
end
|
21
|
+
|
22
|
+
def labels=(labels) # :nodoc:
|
23
|
+
@labels = labels.split(',')
|
24
|
+
@labels.map! { |label| label.chomp }
|
25
|
+
end
|
26
|
+
|
27
|
+
def labels_str
|
28
|
+
@labels.join(', ')
|
29
|
+
end
|
30
|
+
|
31
|
+
def priority=(priority) # :nodoc:
|
32
|
+
begin
|
33
|
+
@priority = priority.to_i
|
34
|
+
rescue
|
35
|
+
@priority = 2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Return priority converted to a human readable string
|
40
|
+
def priority_str
|
41
|
+
case @priority
|
42
|
+
when 0
|
43
|
+
"Off"
|
44
|
+
when 1
|
45
|
+
"Low"
|
46
|
+
when 2
|
47
|
+
"Normal"
|
48
|
+
when 3
|
49
|
+
"High"
|
50
|
+
else
|
51
|
+
"Unknown"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def ratio=(ratio) # :nodoc:
|
56
|
+
begin
|
57
|
+
@ratio = ratio.to_f
|
58
|
+
rescue
|
59
|
+
@ratio = 0.0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def size=(size) # :nodoc:
|
64
|
+
@size = Filesize.new(size)
|
65
|
+
end
|
66
|
+
|
67
|
+
def up_total=(up_total) # :nodoc:
|
68
|
+
@up_total = Filesize.new(up_total)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Return hash of all values in Torrent
|
72
|
+
def to_h
|
73
|
+
{
|
74
|
+
base_filename: @base_filename,
|
75
|
+
base_path: @base_path,
|
76
|
+
completed: @completed,
|
77
|
+
hash: @hash,
|
78
|
+
is_multi_file: @is_multi_file,
|
79
|
+
labels: @labels,
|
80
|
+
name: @name,
|
81
|
+
priority: @priority,
|
82
|
+
ratio: @ratio,
|
83
|
+
size: @size,
|
84
|
+
tied_to_file: @tied_to_file,
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
# Single line header
|
89
|
+
def self.header
|
90
|
+
"hash : name : size : down : up : ratio : labels"
|
91
|
+
end
|
92
|
+
|
93
|
+
# All torrent data in a single string for output to screen
|
94
|
+
def to_s
|
95
|
+
"#{self.hash} : #{self.name} : #{self.size.pretty} : #{self.down_total.pretty} : #{self.up_total.pretty} : #{self.ratio} : #{self.labels_str}"
|
96
|
+
end
|
97
|
+
|
98
|
+
# All torrent data dumped to screen in color
|
99
|
+
def pp(with_files = false)
|
100
|
+
puts "-------------- ".red
|
101
|
+
puts " hash: ".blue + self.hash.green
|
102
|
+
puts " name: ".blue + self.name.green
|
103
|
+
puts " size: ".blue + self.size.pretty.green
|
104
|
+
puts " downloaded: ".blue + self.down_total.pretty.green
|
105
|
+
puts " uploaded: ".blue + self.up_total.pretty.green
|
106
|
+
puts " ratio: ".blue + self.ratio.to_s.green
|
107
|
+
puts " priority: ".blue + self.priority_str.green
|
108
|
+
puts " labels: ".blue + self.labels_str.green
|
109
|
+
puts " completed: ".blue + self.completed.to_s.green
|
110
|
+
if with_files
|
111
|
+
puts " files: ".blue
|
112
|
+
@files.each { |file| puts " " + file.green }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# FILTERS
|
117
|
+
|
118
|
+
# Test if torrent has a specific label
|
119
|
+
def has_label?(label)
|
120
|
+
@labels.include? label.to_s
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'rtorrent_xmlrpc/torrent'
|
3
|
+
require 'xmlrpc/client'
|
4
|
+
|
5
|
+
module RTorrent
|
6
|
+
|
7
|
+
class XMLRPC
|
8
|
+
attr_accessor :host, :user, :password, :path
|
9
|
+
attr_reader :port, :use_ssl, :server, :torrents
|
10
|
+
|
11
|
+
def initialize(host: 'localhost', port: nil, user: nil, password: nil, path: '/xmlrpc', use_ssl: false)
|
12
|
+
unless port
|
13
|
+
if use_ssl
|
14
|
+
port = 443
|
15
|
+
else
|
16
|
+
port = 80
|
17
|
+
end
|
18
|
+
end
|
19
|
+
self.host = host
|
20
|
+
self.port = port
|
21
|
+
self.user = user
|
22
|
+
self.password = password
|
23
|
+
self.path = path
|
24
|
+
self.use_ssl = use_ssl
|
25
|
+
@torrents = []
|
26
|
+
@status = :initialized
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.new_from_hash(hash = {})
|
30
|
+
h = {}
|
31
|
+
hash.each { |k,v| h[k.to_s.downcase.to_sym] = v }
|
32
|
+
self.new(host: h[:host], port: h[:port], user: h[:user], password: h[:password], path: h[:path], use_ssl: h[:use_ssl])
|
33
|
+
end
|
34
|
+
|
35
|
+
def port=(port)
|
36
|
+
fail unless port.is_a? Integer
|
37
|
+
@port = port
|
38
|
+
end
|
39
|
+
|
40
|
+
def use_ssl=(use_ssl)
|
41
|
+
fail unless use_ssl.is_a?(TrueClass) || use_ssl.is_a?(FalseClass)
|
42
|
+
@use_ssl = use_ssl
|
43
|
+
end
|
44
|
+
|
45
|
+
# Connect to rtorrent xmlrpc service
|
46
|
+
def connect
|
47
|
+
connection_options = {
|
48
|
+
host: @host,
|
49
|
+
port: @port,
|
50
|
+
user: @user,
|
51
|
+
password: @password,
|
52
|
+
path: @path,
|
53
|
+
use_ssl: @use_ssl,
|
54
|
+
}
|
55
|
+
@server = ::XMLRPC::Client.new3(connection_options)
|
56
|
+
@status = :connected
|
57
|
+
end
|
58
|
+
|
59
|
+
# Grab list of torrents from server
|
60
|
+
def fetch_torrents
|
61
|
+
self.connect unless @status == :connected
|
62
|
+
@torrents = []
|
63
|
+
#@server.call('d.multicall', 'main', 'd.hash=').each do |result|
|
64
|
+
# @torrents << RTorrent::Torrent.new(@server, result.first)
|
65
|
+
#end
|
66
|
+
args = [
|
67
|
+
'd.multicall',
|
68
|
+
'main',
|
69
|
+
'd.hash=',
|
70
|
+
'd.name=',
|
71
|
+
'd.custom1=',
|
72
|
+
'd.complete=',
|
73
|
+
'd.base_filename=',
|
74
|
+
'd.base_path=',
|
75
|
+
'd.is_multi_file=',
|
76
|
+
'd.tied_to_file=',
|
77
|
+
'd.get_size_bytes=',
|
78
|
+
'd.get_down_total=',
|
79
|
+
'd.get_up_total=',
|
80
|
+
'd.get_ratio=',
|
81
|
+
'd.get_priority=',
|
82
|
+
]
|
83
|
+
@server.call(*args).each do |stats|
|
84
|
+
torrent = RTorrent::Torrent.new
|
85
|
+
torrent.hash = stats[0]
|
86
|
+
torrent.name = stats[1]
|
87
|
+
torrent.labels = stats[2]
|
88
|
+
torrent.completed = stats[3] == 1 ? true : false
|
89
|
+
torrent.base_filename = stats[4]
|
90
|
+
torrent.base_path = stats[5]
|
91
|
+
torrent.is_multi_file = stats[6] == 1 ? true: false
|
92
|
+
torrent.tied_to_file = stats[7]
|
93
|
+
torrent.size = stats[8]
|
94
|
+
torrent.down_total = stats[9]
|
95
|
+
torrent.up_total = stats[10]
|
96
|
+
torrent.ratio = stats[11].to_f / 1000
|
97
|
+
torrent.priority = stats[12]
|
98
|
+
torrent.files = @server.call('f.multicall', torrent.hash, '', 'f.get_path=').flatten
|
99
|
+
@torrents << torrent
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Start a torrent
|
104
|
+
def start(hash)
|
105
|
+
@server.call('d.start', hash)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Stop a torrent
|
109
|
+
def stop(hash)
|
110
|
+
@server.call('d.close', hash)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Pause a torrent
|
114
|
+
def pause(hash)
|
115
|
+
@server.call('d.stop', hash)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Get a list of completed torrents
|
119
|
+
def completed
|
120
|
+
result = []
|
121
|
+
@torrents.each { |torrent| result << torrent if torrent.completed }
|
122
|
+
return result
|
123
|
+
end
|
124
|
+
|
125
|
+
# Get a list of incomplete torrents
|
126
|
+
def incomplete
|
127
|
+
result = []
|
128
|
+
@torrents.each { |torrent| result << torrent unless torrent.completed }
|
129
|
+
return result
|
130
|
+
end
|
131
|
+
|
132
|
+
# Get a list of torrents with label
|
133
|
+
def with_label(label)
|
134
|
+
result = []
|
135
|
+
@torrents.each { |torrent| result << torrent if torrent.has_label? label }
|
136
|
+
return result
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
data/lib/rtorrent_xmlrpc.rb
CHANGED
@@ -1,234 +1 @@
|
|
1
|
-
require '
|
2
|
-
require 'filesize'
|
3
|
-
require 'hashie'
|
4
|
-
require 'xmlrpc/client'
|
5
|
-
|
6
|
-
module RTorrent
|
7
|
-
|
8
|
-
class Torrent
|
9
|
-
|
10
|
-
# Attributes
|
11
|
-
attr_accessor :hash, :name, :completed, :base_filename, :base_path, :is_multi_file, :tied_to_file
|
12
|
-
attr_reader :down_total, :labels, :priority, :ratio, :size, :up_total
|
13
|
-
|
14
|
-
def down_total=(down_total) # :nodoc:
|
15
|
-
@down_total = Filesize.new(down_total)
|
16
|
-
end
|
17
|
-
|
18
|
-
def labels=(labels) # :nodoc:
|
19
|
-
@labels = labels.split(',')
|
20
|
-
@labels.map! { |label| label.chomp }
|
21
|
-
end
|
22
|
-
|
23
|
-
def labels_str
|
24
|
-
@labels.join(', ')
|
25
|
-
end
|
26
|
-
|
27
|
-
def priority=(priority) # :nodoc:
|
28
|
-
begin
|
29
|
-
@priority = priority.to_i
|
30
|
-
rescue
|
31
|
-
@priority = 2
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Return priority converted to a human readable string
|
36
|
-
def priority_str
|
37
|
-
case @priority
|
38
|
-
when 0
|
39
|
-
"Off"
|
40
|
-
when 1
|
41
|
-
"Low"
|
42
|
-
when 2
|
43
|
-
"Normal"
|
44
|
-
when 3
|
45
|
-
"High"
|
46
|
-
else
|
47
|
-
"Unknown"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def ratio=(ratio) # :nodoc:
|
52
|
-
begin
|
53
|
-
@ratio = ratio.to_f
|
54
|
-
rescue
|
55
|
-
@ratio = 0.0
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def size=(size) # :nodoc:
|
60
|
-
@size = Filesize.new(size)
|
61
|
-
end
|
62
|
-
|
63
|
-
def up_total=(up_total) # :nodoc:
|
64
|
-
@up_total = Filesize.new(up_total)
|
65
|
-
end
|
66
|
-
|
67
|
-
# Return hash of all values in Torrent
|
68
|
-
def to_h
|
69
|
-
{
|
70
|
-
base_filename: @base_filename,
|
71
|
-
base_path: @base_path,
|
72
|
-
completed: @completed,
|
73
|
-
hash: @hash,
|
74
|
-
is_multi_file: @is_multi_file,
|
75
|
-
labels: @labels,
|
76
|
-
name: @name,
|
77
|
-
priority: @priority,
|
78
|
-
ratio: @ratio,
|
79
|
-
size: @size,
|
80
|
-
tied_to_file: @tied_to_file,
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
# Single line header
|
85
|
-
def self.header
|
86
|
-
"hash : name : size : down : up : ratio : labels"
|
87
|
-
end
|
88
|
-
|
89
|
-
# All torrent data in a single string for output to screen
|
90
|
-
def to_s
|
91
|
-
"#{self.hash} : #{self.name} : #{self.size.pretty} : #{self.down_total.pretty} : #{self.up_total.pretty} : #{self.ratio} : #{self.labels_str}"
|
92
|
-
end
|
93
|
-
|
94
|
-
# All torrent data dumped to screen in color
|
95
|
-
def pp
|
96
|
-
puts "-------------- ".red
|
97
|
-
puts " hash: ".blue + self.hash.green
|
98
|
-
puts " name: ".blue + self.name.green
|
99
|
-
puts " size: ".blue + self.size.pretty.green
|
100
|
-
puts " downloaded: ".blue + self.down_total.pretty.green
|
101
|
-
puts " uploaded: ".blue + self.up_total.pretty.green
|
102
|
-
puts " ratio: ".blue + self.ratio.to_s.green
|
103
|
-
puts " priority: ".blue + self.priority_str.green
|
104
|
-
puts " labels: ".blue + self.labels_str.green
|
105
|
-
puts " completed: ".blue + self.completed.to_s.green
|
106
|
-
end
|
107
|
-
|
108
|
-
# FILTERS
|
109
|
-
|
110
|
-
# Test if torrent has a specific label
|
111
|
-
def has_label?(label)
|
112
|
-
@labels.include? label.to_s
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
class XMLRPC
|
118
|
-
attr_accessor :host, :user, :password, :path
|
119
|
-
attr_reader :port, :use_ssl, :torrents
|
120
|
-
|
121
|
-
def initialize(host:, port: 80, user:, password:, path: '/xmlrpc', use_ssl: false)
|
122
|
-
self.host = host
|
123
|
-
self.port = port
|
124
|
-
self.user = user
|
125
|
-
self.password = password
|
126
|
-
self.path = path
|
127
|
-
self.use_ssl = use_ssl
|
128
|
-
@torrents = []
|
129
|
-
@status = :initialized
|
130
|
-
end
|
131
|
-
|
132
|
-
def port=(port)
|
133
|
-
fail unless port.is_a? Integer
|
134
|
-
@port = port
|
135
|
-
end
|
136
|
-
|
137
|
-
def use_ssl=(use_ssl)
|
138
|
-
fail unless use_ssl.is_a?(TrueClass) || use_ssl.is_a?(FalseClass)
|
139
|
-
@use_ssl = use_ssl
|
140
|
-
end
|
141
|
-
|
142
|
-
# Connect to rtorrent xmlrpc service
|
143
|
-
def connect
|
144
|
-
connection_options = {
|
145
|
-
host: @host,
|
146
|
-
port: @port,
|
147
|
-
user: @user,
|
148
|
-
password: @password,
|
149
|
-
path: @path,
|
150
|
-
use_ssl: @use_ssl,
|
151
|
-
}
|
152
|
-
@server = ::XMLRPC::Client.new3(connection_options)
|
153
|
-
@status = :connected
|
154
|
-
end
|
155
|
-
|
156
|
-
# Grab list of torrents from server
|
157
|
-
def fetch_torrents
|
158
|
-
self.connect unless @status == :connected
|
159
|
-
@torrents = []
|
160
|
-
args = [
|
161
|
-
'd.multicall',
|
162
|
-
'main',
|
163
|
-
'd.hash=',
|
164
|
-
'd.name=',
|
165
|
-
'd.custom1=',
|
166
|
-
'd.complete=',
|
167
|
-
'd.base_filename=',
|
168
|
-
'd.base_path=',
|
169
|
-
'd.is_multi_file=',
|
170
|
-
'd.tied_to_file=',
|
171
|
-
'd.get_size_bytes=',
|
172
|
-
'd.get_down_total=',
|
173
|
-
'd.get_up_total=',
|
174
|
-
'd.get_ratio=',
|
175
|
-
'd.get_priority=',
|
176
|
-
]
|
177
|
-
#@server.call('d.multicall', 'main', 'd.hash=', 'd.name=', 'd.custom1=', 'd.complete=', 'd.base_filename=', 'd.base_path=', 'd.is_multi_file=', 'd.tied_to_file=', 'd.get_size').each do |stats|
|
178
|
-
@server.call(*args).each do |stats|
|
179
|
-
torrent = RTorrent::Torrent.new
|
180
|
-
torrent.hash = stats[0]
|
181
|
-
torrent.name = stats[1]
|
182
|
-
torrent.labels = stats[2]
|
183
|
-
torrent.completed = stats[3] == 1 ? true : false
|
184
|
-
torrent.base_filename = stats[4]
|
185
|
-
torrent.base_path = stats[5]
|
186
|
-
torrent.is_multi_file = stats[6] == 1 ? true: false
|
187
|
-
torrent.tied_to_file = stats[7]
|
188
|
-
torrent.size = stats[8]
|
189
|
-
torrent.down_total = stats[9]
|
190
|
-
torrent.up_total = stats[10]
|
191
|
-
torrent.ratio = stats[11].to_f / 1000
|
192
|
-
torrent.priority = stats[12]
|
193
|
-
@torrents << torrent
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
# Start a torrent
|
198
|
-
def start(hash)
|
199
|
-
@server.call('d.start', hash)
|
200
|
-
end
|
201
|
-
|
202
|
-
# Stop a torrent
|
203
|
-
def stop(hash)
|
204
|
-
@server.call('d.close', hash)
|
205
|
-
end
|
206
|
-
|
207
|
-
# Pause a torrent
|
208
|
-
def pause(hash)
|
209
|
-
@server.call('d.stop', hash)
|
210
|
-
end
|
211
|
-
|
212
|
-
# Get a list of completed torrents
|
213
|
-
def completed
|
214
|
-
result = []
|
215
|
-
@torrents.each { |torrent| result << torrent if torrent.completed }
|
216
|
-
return result
|
217
|
-
end
|
218
|
-
|
219
|
-
# Get a list of incomplete torrents
|
220
|
-
def incomplete
|
221
|
-
result = []
|
222
|
-
@torrents.each { |torrent| result << torrent unless torrent.completed }
|
223
|
-
return result
|
224
|
-
end
|
225
|
-
|
226
|
-
# Get a list of torrents with label
|
227
|
-
def with_label(label)
|
228
|
-
result = []
|
229
|
-
@torrents.each { |torrent| result << torrent if torrent.has_label? label }
|
230
|
-
return result
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
end
|
1
|
+
require 'rtorrent_xmlrpc/xmlrpc'
|