rtorrent_xmlrpc 0.2.0 → 0.2.1

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: 7c86aceddbf9e09b916268983bd63cf5a474cf77
4
- data.tar.gz: df956f3f1c72817153881436aa1efe9bfb0218a2
3
+ metadata.gz: 4ae000db9daac6192dce5cf98cc2c8d974d42b7c
4
+ data.tar.gz: 584a8a6dead03963572ef365a663a74443e84955
5
5
  SHA512:
6
- metadata.gz: 703f7b8e98876f2f64597f2bbf5cecc122afb70ff94c6f59e7e6316c385cdc2b7dbb3fbd85c30adea9563dffdd49280870f5fcf2dc09b7996fa2d6f5f7a8a0bd
7
- data.tar.gz: bb82d0251aebab977ecdd49458d143b18c7f23c2e4191282fea4064f94a9f7d2895b5d7c1228d6db395bfa9d0be0c0da5569efdb33d1166df1777e1e6cb557f9
6
+ metadata.gz: 38942789a53713954eada8eec5e817a834b3b980aac312c21ecebd0d6b476e089089e9a202e85a9567d89447c48b005d9d7471c8f2bc98014ac56178485cac14
7
+ data.tar.gz: 13e72a2aaee74129a9f2f661965159dd581b5b2910487018460f4e43ada857a58e9ddc85a828b500475e17e7bf81ade9a533d2214a97378ce1614b5db06853c1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rtorrent_xmlrpc (0.1.1)
4
+ rtorrent_xmlrpc (0.2.0)
5
5
  colorize (~> 0.7, >= 0.7.7)
6
6
  filesize (~> 0.1, >= 0.1.0)
7
7
  hashie (~> 3.4, >= 3.4.2)
data/bin/rtorrent_xmlrpc CHANGED
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'hashie'
4
+ require 'json'
4
5
  require 'rtorrent_xmlrpc'
5
6
  require 'thor'
6
7
 
7
8
  class RTorrent_XMLRPC < Thor
8
9
 
10
+ class_option '--json', type: :boolean
11
+
9
12
  def initialize(*args)
10
13
  super
11
14
  # Read in config file
@@ -26,7 +29,11 @@ class RTorrent_XMLRPC < Thor
26
29
 
27
30
  no_tasks do
28
31
  def print(torrents)
29
- torrents.each { |torrent| torrent.pp }
32
+ if options[:json]
33
+ puts torrents.to_json
34
+ else
35
+ torrents.each { |torrent| torrent.pp }
36
+ end
30
37
  end
31
38
  end
32
39
 
@@ -52,7 +59,7 @@ class RTorrent_XMLRPC < Thor
52
59
 
53
60
  desc "complete", "Print all torrents that are complete."
54
61
  def complete
55
- self.print @xmlrpc.completed
62
+ self.print @xmlrpc.torrents.completed
56
63
  end
57
64
 
58
65
  desc "incomplete", "Print all incomplete torrents."
@@ -62,7 +69,7 @@ class RTorrent_XMLRPC < Thor
62
69
 
63
70
  desc "labeled LABEL", "Print all torrents with label"
64
71
  def labeled(label)
65
- self.print @xmlrpc.with_label label
72
+ self.print @xmlrpc.torrents.with_label label
66
73
  end
67
74
 
68
75
  desc "files HASH", "Print the torrent information with files."
@@ -1,5 +1,6 @@
1
1
  require 'colorize'
2
2
  require 'filesize'
3
+ require 'json'
3
4
  require 'xmlrpc/client'
4
5
 
5
6
  module RTorrent
@@ -15,6 +16,10 @@ module RTorrent
15
16
  attr_accessor :base_filename, :base_path, :completed, :files, :hash, :is_multi_file, :name, :tied_to_file
16
17
  attr_reader :down_total, :labels, :priority, :ratio, :size, :up_total
17
18
 
19
+ def completed?
20
+ self.completed
21
+ end
22
+
18
23
  def down_total=(down_total) # :nodoc:
19
24
  @down_total = Filesize.new(down_total)
20
25
  end
@@ -74,6 +79,7 @@ module RTorrent
74
79
  base_filename: @base_filename,
75
80
  base_path: @base_path,
76
81
  completed: @completed,
82
+ files: @files,
77
83
  hash: @hash,
78
84
  is_multi_file: @is_multi_file,
79
85
  labels: @labels,
@@ -85,14 +91,9 @@ module RTorrent
85
91
  }
86
92
  end
87
93
 
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
+ # Convert object to string as json
94
95
  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
+ self.to_h.to_json
96
97
  end
97
98
 
98
99
  # All torrent data dumped to screen in color
@@ -0,0 +1,20 @@
1
+ module RTorrent
2
+
3
+ class Torrents < Array
4
+ def completed
5
+ result = Torrents.new
6
+ self.each do |torrent|
7
+ result << torrent if torrent.completed?
8
+ end
9
+ return result
10
+ end
11
+ def with_label(label)
12
+ result = Torrents.new
13
+ self.each do |torrent|
14
+ result << torrent if torrent.has_label? label
15
+ end
16
+ return result
17
+ end
18
+ end
19
+
20
+ end
@@ -1,5 +1,6 @@
1
1
  require 'hashie'
2
2
  require 'rtorrent_xmlrpc/torrent'
3
+ require 'rtorrent_xmlrpc/torrents'
3
4
  require 'xmlrpc/client'
4
5
 
5
6
  module RTorrent
@@ -22,7 +23,7 @@ module RTorrent
22
23
  self.password = password
23
24
  self.path = path
24
25
  self.use_ssl = use_ssl
25
- @torrents = []
26
+ @torrents = Torrents.new
26
27
  @status = :initialized
27
28
  end
28
29
 
@@ -59,10 +60,7 @@ module RTorrent
59
60
  # Grab list of torrents from server
60
61
  def fetch_torrents
61
62
  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
63
+ @torrents = Torrents.new
66
64
  args = [
67
65
  'd.multicall',
68
66
  'main',
@@ -115,26 +113,6 @@ module RTorrent
115
113
  @server.call('d.stop', hash)
116
114
  end
117
115
 
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
116
  end
139
117
 
140
118
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rtorrent_xmlrpc'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.1'
4
4
  s.date = '2015-07-03'
5
5
  s.summary = 'A library and tool to query an rtorrent xmlrpc service.'
6
6
  s.description = 'This is a library to get torrent information from a remote rtorrent server.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtorrent_xmlrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zan Loy
@@ -103,6 +103,7 @@ files:
103
103
  - bin/rtorrent_xmlrpc
104
104
  - lib/rtorrent_xmlrpc.rb
105
105
  - lib/rtorrent_xmlrpc/torrent.rb
106
+ - lib/rtorrent_xmlrpc/torrents.rb
106
107
  - lib/rtorrent_xmlrpc/xmlrpc.rb
107
108
  - methods.txt
108
109
  - rtorrent_xmlrpc.conf.sample