rootor 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57aee2a2fc75e6e60f56c0b230be423638bfd7ac
4
- data.tar.gz: 8fd467e368e92eb606ab32eeef49db41c56968ca
3
+ metadata.gz: 15dbfbc038a84afc383b11e112467a3f5d3f5072
4
+ data.tar.gz: 89932a88882db6259bfd2e2444bd420d55947272
5
5
  SHA512:
6
- metadata.gz: 5593f543852bbd6bf7f21df24d881de7f582a40f391ecd208f32e50daa9165d0ddbed59ca1baf300476d468679e9d1952f8914070ee84610534f9aff99ac4f1d
7
- data.tar.gz: 667a992e97d9756a8ddf7026f27e0d9f1f299fe5961ef81985aa2076d9df8009a6185a24bf1476d1993ba0847d74579bf07f86c8c267bcef77dad45957bc3eba
6
+ metadata.gz: a14bcc0d475658c04e37417f4c74a8eea1500c02169f5ca8c99ffbfabba936a402e92dd0e317e0a47c1213bb9dcd52396d1a8ceab5e9144ee4e5829a2373615f
7
+ data.tar.gz: '099c11134037670eed044c029fecf31b89d6cb201f3054e32a8740d44e7ca989e1584891dcc963e3ad43dcfa888f01e54c58f8a64ab234f4e7a57b3b618f1edb'
data/README.md CHANGED
@@ -1,13 +1,29 @@
1
- Rootor is an `xmlrpc` ruby frontend.
2
-
1
+ Rootor is an `xmlrpc` rtorrent ruby frontend.
2
+ ```bash
3
+ gem install rootor
3
4
  ```
5
+
6
+
7
+ ```ruby
4
8
  require 'rootor'
5
9
 
6
10
  r = Rootor.new('https://<user>:<password>@<server>:<port>/<xmlrpc>')
7
11
 
8
- r.torrents
12
+ puts r.torrents.length
13
+
14
+ r.load_from_file('<file.torrent>')
9
15
  ```
10
16
 
11
- links
17
+ Reference
12
18
  ---
13
19
  https://github.com/mdevaev/emonoda/wiki/rTorrent-XMLRPC-Reference
20
+
21
+ http://elektito.com/2016/02/10/rtorrent-xmlrpc/
22
+
23
+ https://github.com/rakshasa/rtorrent/wiki/rTorrent-0.9-Comprehensive-Command-list-(WIP)
24
+
25
+ https://github.com/rakshasa/rtorrent/wiki
26
+
27
+ https://github.com/Novik/ruTorrent/blob/master/js/rtorrent.js
28
+
29
+ https://github.com/rafipiccolo/node-rtorrent/blob/master/index.js
data/lib/client.rb CHANGED
@@ -1,7 +1,16 @@
1
1
  class Client < XMLRPC::Client
2
- def fetch(queries)
3
- call_async('d.multicall', 'main', *render_queries(queries)).map do |t|
4
- Torrent.new(t, queries)
2
+ def fetch
3
+ d_objects = call_async('d.multicall', 'main', *render_downloads_queries).map do |t|
4
+ Hash[QUERIES[:downloads].keys.zip(t)]
5
+ end
6
+
7
+ t_commands = render_trackers_commands(d_objects.map { |d| d[:hash] })
8
+ t_objects = multicall_async(*t_commands).map do |r|
9
+ Hash[QUERIES[:trackers].keys.zip(r.first)]
10
+ end
11
+
12
+ d_objects.zip(t_objects).map do |d, t|
13
+ Torrent.new(d.merge(t))
5
14
  end
6
15
  end
7
16
 
@@ -11,7 +20,15 @@ class Client < XMLRPC::Client
11
20
 
12
21
  private
13
22
 
14
- def render_queries(queries)
15
- queries.map { |k, v| "d.#{v[:call]}=" }
23
+ def render_downloads_queries
24
+ QUERIES[:downloads].map { |_, v| "d.#{v[:call]}=" }
25
+ end
26
+
27
+ def render_trackers_commands(hashes)
28
+ calls = QUERIES[:trackers].map { |_, v| "t.#{v[:call]}=" }
29
+
30
+ hashes.map do |h|
31
+ ['t.multicall', h, '', *calls]
32
+ end
16
33
  end
17
34
  end
data/lib/queries.rb ADDED
@@ -0,0 +1,30 @@
1
+ QUERIES = {
2
+ downloads: {
3
+ hash: { call: 'hash', kind: :str },
4
+ name: { call: 'name', kind: :str },
5
+ path: { call: 'base_path', kind: :str },
6
+ file_name: { call: 'base_filename', kind: :str },
7
+ created_at: { call: 'creation_date', kind: :time },
8
+ finished_at: { call: 'timestamp.finished', kind: :time },
9
+ message: { call: 'message', kind: :str },
10
+ status: { call: 'connection_current', kind: :str },
11
+ is_active: { call: 'is_active', kind: :bool },
12
+ is_open: { call: 'is_open', kind: :bool },
13
+ size: { call: 'size_bytes', kind: :file },
14
+ uploaded: { call: 'up.total', kind: :file },
15
+ downloaded: { call: 'down.total', kind: :file },
16
+ ratio: { call: 'ratio', kind: :ratio },
17
+ up_rate: { call: 'up.rate', kind: :rate },
18
+ down_rate: { call: 'down.rate', kind: :rate },
19
+ is_private: { call: 'is_private', kind: :bool },
20
+ },
21
+ trackers: {
22
+ tracker_url: { call: 'url', type: :str },
23
+ tracker_type: { call: 'type', type: :str },
24
+ tracker_group: { call: 'group', type: :str },
25
+ tracker_success_count: { call: 'success_counter', type: :int },
26
+ tracker_failed_count: { call: 'failed_counter', type: :int },
27
+ }
28
+ }.freeze
29
+
30
+ FLAT_QUERIES = QUERIES[:downloads].merge(QUERIES[:trackers]).freeze
data/lib/rootor.rb CHANGED
@@ -2,49 +2,32 @@ require 'xmlrpc/client'
2
2
  require 'filesize'
3
3
  require_relative 'client'
4
4
  require_relative 'torrent'
5
+ require_relative 'queries'
5
6
 
6
7
  class Rootor
7
8
  attr_accessor :client, :torrents
8
9
 
9
- QUERIES = {
10
- id: { call: 'hash', kind: :str },
11
- name: { call: 'name', kind: :str },
12
- path: { call: 'get_base_path', kind: :str },
13
- creation_date: { call: 'creation_date', kind: :date },
14
- message: { call: 'message', kind: :str },
15
- connection_current: { call: 'connection_current', kind: :str },
16
- is_active: { call: 'is_active', kind: :bool },
17
- is_open: { call: 'is_open', kind: :bool },
18
- size: { call: 'size_bytes', kind: :file },
19
- uploaded: { call: 'get_up_total', kind: :file },
20
- downloaded: { call: 'bytes_done', kind: :file },
21
- ratio: { call: 'get_ratio', kind: :ratio },
22
- up_rate: { call: 'get_up_rate', kind: :rate },
23
- down_rate: { call: 'get_down_rate', kind: :rate },
24
- }
25
-
26
- def initialize(xmlrpc_url, queries = QUERIES)
27
- @queries = queries
28
- @client = Client.new2(xmlrpc_url)
29
- @torrents = @client.fetch(@queries)
10
+ def initialize(xmlrpc_url)
11
+ @client = Client.new2(xmlrpc_url)
12
+ @torrents = refresh!
30
13
  end
31
14
 
32
- def refresh
33
- @torrents = @client.fetch(@queries)
15
+ def refresh!
16
+ @torrents = @client.fetch
34
17
  end
35
18
 
36
19
  def serialized_torrents
37
- serialize(@torrents)
20
+ @torrents.map(&:serialize)
21
+ end
22
+
23
+ def pretty_serialized_torrents
24
+ @torrents.map(&:pretty_serialize)
38
25
  end
39
26
 
40
27
  def find(str)
41
- return [] if (str.empty? || !str.instance_of?(String))
28
+ return [] if str.empty? || !str.instance_of?(String)
42
29
  @torrents.map do |t|
43
- begin
44
- t if t.serialize.values.any? { |tt| tt.downcase.include? str.downcase }
45
- rescue
46
- nil
47
- end
30
+ t if t.serialize.values.any? { |tt| tt.downcase.include? str.downcase } rescue nil
48
31
  end.compact
49
32
  end
50
33
 
@@ -55,10 +38,4 @@ class Rootor
55
38
  def load_from_file(path)
56
39
  load_from_raw(File.read(path))
57
40
  end
58
-
59
- private
60
-
61
- def serialize(torrents)
62
- torrents.map(&:serialize)
63
- end
64
41
  end
data/lib/torrent.rb CHANGED
@@ -1,38 +1,54 @@
1
1
  class Torrent
2
- def initialize(data, queries)
3
- @data = data
4
- @queries = queries
2
+ def initialize(raw_hash)
3
+ @raw_hash = raw_hash
5
4
  serialize.each do |k, v|
6
- self.instance_variable_set "@#{k.to_s}", v
7
- self.class.__send__(:attr_accessor, k)
5
+ instance_variable_set "@#{k}", v
6
+ self.class.__send__(:attr_reader, k)
8
7
  end
9
8
  end
10
9
 
11
- def serialize
12
- Hash[
13
- @data.each_with_index.map do |value, index|
10
+ def serialize(pretty: false)
11
+ serialized_queries = Hash[
12
+ @raw_hash.map do |k, v|
14
13
  [
15
- @queries.keys[index],
16
- mutate(@queries[@queries.keys[index]][:kind], value)
14
+ k,
15
+ mutate(FLAT_QUERIES[k][:kind], v, pretty: pretty)
17
16
  ]
18
17
  end
19
18
  ]
19
+
20
+ serialized_queries.merge(
21
+ {
22
+ tracker: URI(serialized_queries[:tracker_url]).host
23
+ }
24
+ )
25
+ end
26
+
27
+ def pretty_serialize
28
+ serialize(pretty: true)
20
29
  end
21
30
 
22
31
  private
23
32
 
24
- def mutate(kase, data)
33
+ def mutate(kase, data, pretty:)
25
34
  case kase
26
- when :file, :rate
27
- Filesize.from("#{data} B")
28
- when :date
29
- Time.at(data)
30
- when :ratio
31
- data.to_f/1000
32
- when :bool
33
- !!data
34
- else
35
- data
35
+ when :file
36
+ filesize = Filesize.from("#{data} B")
37
+ pretty ? filesize.pretty : filesize
38
+ when :rate
39
+ filesize = Filesize.from("#{data} B")
40
+ pretty ? "#{filesize.pretty}/s" : filesize
41
+ when :time
42
+ time = Time.at(data)
43
+ pretty ? time.to_s : time
44
+ when :ratio
45
+ data.to_f / 1000
46
+ when :int
47
+ data.to_i
48
+ when :bool
49
+ !!data
50
+ else
51
+ data
36
52
  end
37
53
  end
38
54
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rootor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - lightbright
7
+ - graham otte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: ''
27
+ description:
28
28
  email: graham.otte@gmail.com
29
29
  executables: []
30
30
  extensions: []
@@ -32,9 +32,10 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - README.md
34
34
  - lib/client.rb
35
+ - lib/queries.rb
35
36
  - lib/rootor.rb
36
37
  - lib/torrent.rb
37
- homepage: http://what.com
38
+ homepage:
38
39
  licenses:
39
40
  - MIT
40
41
  metadata: {}
@@ -54,8 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  version: '0'
55
56
  requirements: []
56
57
  rubyforge_project:
57
- rubygems_version: 2.5.2
58
+ rubygems_version: 2.6.8
58
59
  signing_key:
59
60
  specification_version: 4
60
- summary: XMLRPC interface
61
+ summary: XMLRPC ruby interface
61
62
  test_files: []