rtorrent_xmlrpc 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.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +25 -0
- data/Rakefile +24 -0
- data/bin/rtorrent_xmlrpc +70 -0
- data/lib/rtorrent_xmlrpc.rb +139 -0
- data/rtorrent_xmlrpc.conf.sample +9 -0
- data/rtorrent_xmlrpc.gemspec +17 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e970b5dddb523638d1ea5f441ae458ecae5922aa
|
4
|
+
data.tar.gz: 68b65a6be40657e357d2f12165b278a8a84a6750
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3126a3f7e45654edafa139b673867e4b6413f955994597defc9269f14509a29c701a31b52cd6d8e954a74132111ee7ae8c449640c984e233a1c0a9057eea510f
|
7
|
+
data.tar.gz: c0fd3a6a085cf20e679faf37232a2a53a594dfff3d11639a4101f9f3bd86a352fffd0c148b01e80ddb844a9e725a5abda904a78d0ca05277b9dc2a3bc33195cd
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rtorrent_xmlrpc (0.1)
|
5
|
+
colorize (~> 0.7, >= 0.7.7)
|
6
|
+
hashie (~> 3.4, >= 3.4.2)
|
7
|
+
thor (~> 0.19, >= 0.19.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
colorize (0.7.7)
|
13
|
+
hashie (3.4.2)
|
14
|
+
rake (10.4.2)
|
15
|
+
thor (0.19.1)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
rake (~> 10.4, >= 10.4.2)
|
22
|
+
rtorrent_xmlrpc!
|
23
|
+
|
24
|
+
BUNDLED WITH
|
25
|
+
1.10.5
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
task :default => [:build]
|
2
|
+
task :test => [:build, :install]
|
3
|
+
|
4
|
+
task :build do
|
5
|
+
system("gem build ./rtorrent_xmlrpc.gemspec")
|
6
|
+
end
|
7
|
+
|
8
|
+
task :install do
|
9
|
+
gem = Dir['*.gem'].last
|
10
|
+
system("sudo gem install #{gem}")
|
11
|
+
end
|
12
|
+
|
13
|
+
task :push do
|
14
|
+
gem = Dir['*.gem'].last
|
15
|
+
system("gem push #{gem}")
|
16
|
+
end
|
17
|
+
|
18
|
+
task :console do
|
19
|
+
exec "irb -I ./lib"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :run do
|
23
|
+
ruby "-Ilib", 'bin/rtorrent_xmlrpc'
|
24
|
+
end
|
data/bin/rtorrent_xmlrpc
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'hashie'
|
4
|
+
require 'rtorrent_xmlrpc'
|
5
|
+
require 'thor'
|
6
|
+
|
7
|
+
class RTorrent_XMLRPC < Thor
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
# Read in config file
|
12
|
+
config_file = nil
|
13
|
+
%W[rtorrent_xmlrpc.conf #{Dir.home}/.config/rtorrent_xmlrpc.conf #{Dir.home}/.rtorrent_xmlrpc.conf /etc/rtorrent_xmlrpc.conf].each do |f|
|
14
|
+
if File.exists?(f)
|
15
|
+
config_file = f
|
16
|
+
break
|
17
|
+
end
|
18
|
+
end
|
19
|
+
raise 'No config file found.' if config_file.nil?
|
20
|
+
config = Hashie::Mash.load(config_file)
|
21
|
+
# Connect to xmlrpc service
|
22
|
+
@xmlrpc = RTorrent::XMLRPC.new( host: config.host, port: config.port, path: config.path, user: config.user, password: config.password, use_ssl: config.use_ssl)
|
23
|
+
@xmlrpc.connect
|
24
|
+
@xmlrpc.fetch_torrents
|
25
|
+
end
|
26
|
+
|
27
|
+
no_tasks do
|
28
|
+
def print(torrents)
|
29
|
+
torrents.each { |torrent| torrent.pp }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "list", "Pretty print all the torrents on the server."
|
34
|
+
def list
|
35
|
+
self.print @xmlrpc.torrents
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "start HASH", "Start torrent with HASH"
|
39
|
+
def start(hash)
|
40
|
+
@xmlrpc.start hash
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "stop HASH", "Stop torrent with HASH"
|
44
|
+
def stop(hash)
|
45
|
+
@xmlrpc.stop hash
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "pause HASH", "Pause torrent with HASH"
|
49
|
+
def pause(hash)
|
50
|
+
@xmlrpc.pause hash
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "complete", "Print all torrents that are complete."
|
54
|
+
def complete
|
55
|
+
self.print @xmlrpc.completed
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "incomplete", "Print all incomplete torrents."
|
59
|
+
def incomplete
|
60
|
+
self.print @xmlrpc.incomplete
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "labeled LABEL", "Print all torrents with label"
|
64
|
+
def labeled(label)
|
65
|
+
self.print @xmlrpc.with_label label
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
RTorrent_XMLRPC.start(ARGV)
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'hashie'
|
3
|
+
require 'xmlrpc/client'
|
4
|
+
|
5
|
+
module RTorrent
|
6
|
+
|
7
|
+
class Torrent
|
8
|
+
attr_accessor :hash, :name, :completed, :base_filename, :base_path, :is_multi_file, :tied_to_file
|
9
|
+
attr_reader :labels
|
10
|
+
|
11
|
+
def has_label(label)
|
12
|
+
@labels.include? label.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def labels=(labels)
|
16
|
+
@labels = labels.split(',')
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
{
|
21
|
+
hash: @hash,
|
22
|
+
name: @name,
|
23
|
+
labels: @labels,
|
24
|
+
completed: @completed,
|
25
|
+
base_filename: @base_filename,
|
26
|
+
base_path: @base_path,
|
27
|
+
is_multi_file: @is_multi_file,
|
28
|
+
tied_to_file: @tied_to_file,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def pp
|
33
|
+
puts "-------------- ".red
|
34
|
+
puts " hash: ".blue + @hash.green
|
35
|
+
puts " name: ".blue + @name.green
|
36
|
+
puts " labels: ".blue + @labels.join(', ').green
|
37
|
+
puts " completed: ".blue + @completed.to_s.green
|
38
|
+
puts "base_filename: ".blue + @base_filename.green
|
39
|
+
puts " base_path: ".blue + @base_path.green
|
40
|
+
puts "is_multi_file: ".blue + @is_multi_file.to_s.green
|
41
|
+
puts " tied_to_file: ".blue + @tied_to_file.green
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class XMLRPC
|
46
|
+
attr_accessor :host, :user, :password, :path
|
47
|
+
attr_reader :port, :use_ssl, :torrents
|
48
|
+
|
49
|
+
def initialize(host:, port: 80, user:, password:, path: '/xmlrpc', use_ssl: false)
|
50
|
+
self.host = host
|
51
|
+
self.port = port
|
52
|
+
self.user = user
|
53
|
+
self.password = password
|
54
|
+
self.path = path
|
55
|
+
self.use_ssl = use_ssl
|
56
|
+
@torrents = []
|
57
|
+
@status = :initialized
|
58
|
+
end
|
59
|
+
|
60
|
+
def port=(port)
|
61
|
+
fail unless port.is_a? Integer
|
62
|
+
@port = port
|
63
|
+
end
|
64
|
+
|
65
|
+
def use_ssl=(use_ssl)
|
66
|
+
fail unless use_ssl.is_a?(TrueClass) || use_ssl.is_a?(FalseClass)
|
67
|
+
@use_ssl = use_ssl
|
68
|
+
end
|
69
|
+
|
70
|
+
# Connect to rtorrent xmlrpc service
|
71
|
+
def connect
|
72
|
+
connection_options = {
|
73
|
+
host: @host,
|
74
|
+
port: @port,
|
75
|
+
user: @user,
|
76
|
+
password: @password,
|
77
|
+
path: @path,
|
78
|
+
use_ssl: @use_ssl,
|
79
|
+
}
|
80
|
+
@server = ::XMLRPC::Client.new3(connection_options)
|
81
|
+
@status = :connected
|
82
|
+
end
|
83
|
+
|
84
|
+
# Grab list of torrents from server
|
85
|
+
def fetch_torrents
|
86
|
+
self.connect unless @status == :connected
|
87
|
+
@torrents = []
|
88
|
+
@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=').each do |stats|
|
89
|
+
torrent = RTorrent::Torrent.new
|
90
|
+
torrent.hash = stats[0]
|
91
|
+
torrent.name = stats[1]
|
92
|
+
torrent.labels = stats[2]
|
93
|
+
torrent.completed = stats[3] == 1 ? true : false
|
94
|
+
torrent.base_filename = stats[4]
|
95
|
+
torrent.base_path = stats[5]
|
96
|
+
torrent.is_multi_file = stats[6] == 1 ? true: false
|
97
|
+
torrent.tied_to_file = stats[7]
|
98
|
+
@torrents << torrent
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Start a torrent
|
103
|
+
def start(hash)
|
104
|
+
@server.call('d.start', hash)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Stop a torrent
|
108
|
+
def stop(hash)
|
109
|
+
@server.call('d.close', hash)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Pause a torrent
|
113
|
+
def pause(hash)
|
114
|
+
@server.call('d.stop', hash)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Get a list of completed torrents
|
118
|
+
def completed
|
119
|
+
result = []
|
120
|
+
@torrents.each { |torrent| result << torrent if torrent.completed }
|
121
|
+
return result
|
122
|
+
end
|
123
|
+
|
124
|
+
# Get a list of incomplete torrents
|
125
|
+
def incomplete
|
126
|
+
result = []
|
127
|
+
@torrents.each { |torrent| result << torrent unless torrent.completed }
|
128
|
+
return result
|
129
|
+
end
|
130
|
+
|
131
|
+
# Get a list of torrents with label
|
132
|
+
def with_label(label)
|
133
|
+
result = []
|
134
|
+
@torrents.each { |torrent| result << torrent if torrent.has_label(label) }
|
135
|
+
return result
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'rtorrent_xmlrpc'
|
3
|
+
s.version = '0.1'
|
4
|
+
s.date = '2015-07-02'
|
5
|
+
s.summary = 'A library and tool to query an rtorrent xmlrpc service.'
|
6
|
+
s.authors = ['Zan Loy']
|
7
|
+
s.email = 'zan.loy@gmail.com'
|
8
|
+
s.homepage = 'http://zanloy.com/ruby/rtorrent_xmlrpc/'
|
9
|
+
s.license = 'MIT'
|
10
|
+
s.files = `git ls-files`.split("\n") - %w[.gitignore]
|
11
|
+
s.executables = ['rtorrent_xmlrpc']
|
12
|
+
|
13
|
+
s.add_dependency 'colorize', '~> 0.7', '>= 0.7.7'
|
14
|
+
s.add_dependency 'hashie', '~> 3.4', '>= 3.4.2'
|
15
|
+
s.add_dependency 'thor', '~> 0.19', '>= 0.19.1'
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtorrent_xmlrpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zan Loy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.7.7
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.7'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.7.7
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hashie
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.4'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.4.2
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.4'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.4.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: thor
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.19'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.19.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.19'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.19.1
|
73
|
+
description:
|
74
|
+
email: zan.loy@gmail.com
|
75
|
+
executables:
|
76
|
+
- rtorrent_xmlrpc
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- Rakefile
|
83
|
+
- bin/rtorrent_xmlrpc
|
84
|
+
- lib/rtorrent_xmlrpc.rb
|
85
|
+
- rtorrent_xmlrpc.conf.sample
|
86
|
+
- rtorrent_xmlrpc.gemspec
|
87
|
+
homepage: http://zanloy.com/ruby/rtorrent_xmlrpc/
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.4.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A library and tool to query an rtorrent xmlrpc service.
|
111
|
+
test_files: []
|