remotransmission 0.0.2 → 1.0.0
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.
- data/bin/remotransmission +24 -27
- data/lib/remotransmission/client.rb +4 -79
- data/lib/remotransmission/remote.rb +73 -0
- data/lib/remotransmission/version.rb +2 -2
- data/lib/remotransmission.rb +34 -3
- metadata +11 -19
data/bin/remotransmission
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# RemoTransmission command line interface to control
|
3
3
|
# a remote transmission client.
|
4
|
-
#
|
5
|
-
# Examples:
|
6
|
-
# $ remotransmission -p PaSsWord --add 'magnet://...'
|
7
|
-
# success
|
8
|
-
# $ remotransmission -p PaSsWord --server 214.512.12.20 --port 9092 --list
|
9
|
-
# 100% - ubuntu-10.10-desktop-i386.iso
|
10
|
-
# 100% - ubuntu-10.10-server-i386.iso
|
11
|
-
|
12
4
|
|
5
|
+
require 'choice'
|
13
6
|
require 'remotransmission'
|
14
7
|
|
8
|
+
defaults = RemoTransmission::default_options("~/.config/remotransmission/settings.json")
|
9
|
+
|
15
10
|
Choice.options do
|
16
11
|
header ""
|
17
12
|
header 'Commands:'
|
@@ -28,7 +23,6 @@ Choice.options do
|
|
28
23
|
end
|
29
24
|
|
30
25
|
option :help do
|
31
|
-
#short '-h'
|
32
26
|
long '--help'
|
33
27
|
desc 'Show this message'
|
34
28
|
end
|
@@ -45,55 +39,58 @@ Choice.options do
|
|
45
39
|
separator ""
|
46
40
|
separator 'Common options:'
|
47
41
|
option :host do
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
default '192.168.0.254'
|
42
|
+
long '--host=IP'
|
43
|
+
desc "The hostname or ip of the server to connect to (default #{defaults[:host].inspect})"
|
44
|
+
default defaults[:host]
|
52
45
|
end
|
53
46
|
|
54
47
|
option :port do
|
55
48
|
long '--port=PORT'
|
56
|
-
desc
|
49
|
+
desc "The port to bind to (default #{defaults[:port].inspect})"
|
57
50
|
cast Integer
|
58
|
-
default
|
51
|
+
default defaults[:port]
|
59
52
|
end
|
60
53
|
|
61
54
|
option :user do
|
62
55
|
short '-u'
|
63
56
|
long '--user=USER'
|
64
|
-
desc
|
57
|
+
desc "User to authenticate (default #{defaults[:user].inspect})"
|
65
58
|
default 'freebox'
|
59
|
+
default defaults[:user]
|
66
60
|
end
|
67
61
|
|
68
62
|
option :password do
|
69
63
|
short '-p'
|
70
64
|
long '--password=PASSWORD'
|
71
|
-
desc
|
65
|
+
desc "Password to authenticate"
|
66
|
+
default defaults[:password]
|
72
67
|
end
|
73
68
|
|
74
69
|
option :debug do
|
75
70
|
short '-d'
|
76
71
|
long '--debug'
|
77
|
-
desc
|
72
|
+
desc "Enable debug mode (default #{defaults[:debug].inspect})"
|
73
|
+
default defaults[:debug]
|
78
74
|
end
|
79
75
|
|
80
76
|
separator ""
|
81
77
|
separator "Examples:"
|
82
|
-
separator " $ #{File.basename($0)}
|
78
|
+
separator " $ #{File.basename($0)} --add 'magnet://...'"
|
83
79
|
separator " success"
|
84
|
-
separator " $ #{File.basename($0)} -p PaSsWord --
|
80
|
+
separator " $ #{File.basename($0)} -p PaSsWord --host 192.168.0.254 --list"
|
85
81
|
separator " 100% - ubuntu-10.10-desktop-i386.iso"
|
86
82
|
separator " 100% - ubuntu-10.10-server-i386.iso"
|
87
83
|
end
|
88
84
|
|
85
|
+
options = {
|
86
|
+
host: Choice[:host],
|
87
|
+
port: Choice[:port],
|
88
|
+
user: Choice[:user],
|
89
|
+
password: Choice[:password],
|
90
|
+
debug: Choice[:debug]
|
91
|
+
}
|
89
92
|
|
90
|
-
client = RemoTransmission::Client.new(
|
91
|
-
Choice[:host],
|
92
|
-
Choice[:port],
|
93
|
-
Choice[:user],
|
94
|
-
Choice[:password],
|
95
|
-
Choice[:debug]
|
96
|
-
)
|
93
|
+
client = RemoTransmission::Client.new(options)
|
97
94
|
|
98
95
|
if Choice[:add]
|
99
96
|
client.add(Choice[:add])
|
@@ -1,21 +1,5 @@
|
|
1
1
|
# The main Remote Transmission driver
|
2
|
-
class RemoTransmission::Client
|
3
|
-
# Initialize a remote transmission
|
4
|
-
#
|
5
|
-
# Arguments:
|
6
|
-
# host: host to connect to (String)
|
7
|
-
# port: port to connect to (Integer)
|
8
|
-
# user: username to authenticate to (String)
|
9
|
-
# password: password to authenticate to (String)
|
10
|
-
# debug: flag to turn on debugging (Integer)
|
11
|
-
def initialize(host = "localhost", port = 9091, user = "", password = "", debug = false)
|
12
|
-
@host = host
|
13
|
-
@port = port
|
14
|
-
@user = user
|
15
|
-
@password = password
|
16
|
-
@debug = debug
|
17
|
-
end
|
18
|
-
|
2
|
+
class RemoTransmission::Client < RemoTransmission::Remote
|
19
3
|
# Add a torrent to the transmission client
|
20
4
|
# and prints output.
|
21
5
|
#
|
@@ -26,15 +10,8 @@ class RemoTransmission::Client
|
|
26
10
|
# >> transmission.add("magnet://..."")
|
27
11
|
# success
|
28
12
|
def add(url)
|
29
|
-
add =
|
30
|
-
|
31
|
-
tag: 8,
|
32
|
-
arguments: {
|
33
|
-
filename: url,
|
34
|
-
}
|
35
|
-
)
|
36
|
-
result = add["result"]
|
37
|
-
puts result
|
13
|
+
add = super
|
14
|
+
puts add["result"]
|
38
15
|
end
|
39
16
|
|
40
17
|
# Prints all active torrents
|
@@ -44,15 +21,7 @@ class RemoTransmission::Client
|
|
44
21
|
# 100% - ubuntu-10.10-desktop-i386.iso
|
45
22
|
# 100% - ubuntu-10.10-server-i386.iso
|
46
23
|
def list
|
47
|
-
list =
|
48
|
-
method: "torrent-get",
|
49
|
-
tag: 4,
|
50
|
-
arguments: {
|
51
|
-
#fields: ["error","errorString","eta","id","isFinished","leftUntilDone","name","peersGettingFromUs","peersSendingToUs","rateDownload","rateUpload","sizeWhenDone","status","uploadRatio"],
|
52
|
-
fields: ["isFinished","leftUntilDone","sizeWhenDone", "name"],
|
53
|
-
}
|
54
|
-
)
|
55
|
-
|
24
|
+
list = super
|
56
25
|
args = list["arguments"]
|
57
26
|
torrents = args["torrents"]
|
58
27
|
torrents.each do |torrent|
|
@@ -62,49 +31,5 @@ class RemoTransmission::Client
|
|
62
31
|
puts "#{pourcent}% - #{torrent["name"]}"
|
63
32
|
end
|
64
33
|
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def command(*cmd)
|
69
|
-
debug *cmd
|
70
|
-
exit_status = nil
|
71
|
-
err = nil
|
72
|
-
out = nil
|
73
|
-
|
74
|
-
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread|
|
75
|
-
err = stderr.gets(nil)
|
76
|
-
out = stdout.gets(nil)
|
77
|
-
[stdin, stdout, stderr].each { |stream|
|
78
|
-
stream.send('close')
|
79
|
-
}
|
80
|
-
exit_status = wait_thread.value
|
81
|
-
end
|
82
|
-
|
83
|
-
if exit_status.to_i > 0
|
84
|
-
err = err.chomp if err
|
85
|
-
raise RemoTransmission::ShellError, err
|
86
|
-
elsif out
|
87
|
-
out.chomp
|
88
|
-
else
|
89
|
-
true
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def rpc(options = {})
|
94
|
-
default_options = { arguments: { fields: ["error","errorString","eta","id","isFinished","leftUntilDone","name","peersGettingFromUs","peersSendingToUs","rateDownload","rateUpload","sizeWhenDone","status","uploadRatio"] }, tag: 4 }
|
95
|
-
options = default_options.merge(options).to_json
|
96
|
-
|
97
|
-
curl = command("curl -fsS -u #{@user}:#{@password} -d '#{options}' http://#{@host}:#{@port}/transmission/rpc")
|
98
|
-
json = JSON.parse(curl)
|
99
|
-
debug(json)
|
100
|
-
json
|
101
|
-
rescue RemoTransmission::ShellError => e
|
102
|
-
puts e.message
|
103
|
-
exit 1
|
104
|
-
end
|
105
|
-
|
106
|
-
def debug(*obj)
|
107
|
-
puts *obj if @debug
|
108
|
-
end
|
109
34
|
end
|
110
35
|
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Driver for all API calls
|
2
|
+
class RemoTransmission::Remote
|
3
|
+
# Initialize a remote transmission
|
4
|
+
#
|
5
|
+
# Arguments:
|
6
|
+
# options: hash
|
7
|
+
#
|
8
|
+
# Options:
|
9
|
+
# :host: host to connect to (String)
|
10
|
+
# :port: port to connect to (Integer)
|
11
|
+
# :user: username to authenticate to (String)
|
12
|
+
# :password: password to authenticate to (String)
|
13
|
+
# :debug: flag to turn on debugging (Integer)
|
14
|
+
def initialize(options = {})
|
15
|
+
defaults = RemoTransmission::DEFAULT_OPTIONS
|
16
|
+
options = defaults.merge(options)
|
17
|
+
@host = options[:host]
|
18
|
+
@port = options[:port]
|
19
|
+
@user = options[:user]
|
20
|
+
@password = options[:password]
|
21
|
+
@debug = options[:debug]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Add a torrent to the transmission client
|
25
|
+
# and returns output.
|
26
|
+
#
|
27
|
+
# Arguments:
|
28
|
+
# url: magnet URL or URL of torrent file
|
29
|
+
#
|
30
|
+
# Example:
|
31
|
+
# >> transmission.add("magnet://..."")
|
32
|
+
# { "result" => "success" }
|
33
|
+
def add(url)
|
34
|
+
rpc(
|
35
|
+
method: "torrent-add",
|
36
|
+
tag: 8,
|
37
|
+
arguments: { filename: url }
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Prints all active torrents
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
# >> transmission.list
|
45
|
+
# { "arguments" => { "torrents" => { "leftUntilDone" => ... } }
|
46
|
+
def list
|
47
|
+
rpc(
|
48
|
+
method: "torrent-get",
|
49
|
+
tag: 4,
|
50
|
+
arguments: {
|
51
|
+
#fields: ["error","errorString","eta","id","isFinished","leftUntilDone","name","peersGettingFromUs","peersSendingToUs","rateDownload","rateUpload","sizeWhenDone","status","uploadRatio"],
|
52
|
+
fields: ["isFinished","leftUntilDone","sizeWhenDone", "name"],
|
53
|
+
}
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def rpc(options = {})
|
60
|
+
uri = URI("http://#{@host}:#{@port}/transmission/rpc")
|
61
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
62
|
+
request = Net::HTTP::Post.new(uri.path)
|
63
|
+
request.body = options.to_json
|
64
|
+
request.basic_auth(@user, @password)
|
65
|
+
http.request(request)
|
66
|
+
end
|
67
|
+
|
68
|
+
json = JSON.parse(response.body)
|
69
|
+
$stderr.puts json if @debug
|
70
|
+
json
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/lib/remotransmission.rb
CHANGED
@@ -1,11 +1,42 @@
|
|
1
|
-
require 'choice'
|
2
1
|
require 'json'
|
3
|
-
require '
|
2
|
+
require 'net/http'
|
4
3
|
|
5
4
|
module RemoTransmission
|
5
|
+
DEFAULT_OPTIONS = {
|
6
|
+
host: "localhost",
|
7
|
+
port: 9091,
|
8
|
+
user: "freebox",
|
9
|
+
password: "",
|
10
|
+
debug: false
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
# Returns the default options hash, optionnaly pulled from the given
|
14
|
+
# configuration file.
|
15
|
+
#
|
16
|
+
# Arguments:
|
17
|
+
# file: path to JSON configuration file
|
18
|
+
def self.default_options(file = nil)
|
19
|
+
defaults = DEFAULT_OPTIONS
|
20
|
+
|
21
|
+
if file and file = File.expand_path(file) and File.exists?(file)
|
22
|
+
config = JSON.parse(File.read(file))
|
23
|
+
|
24
|
+
# symbolize keys
|
25
|
+
config = config.inject({}) do |options, (key, value)|
|
26
|
+
options[key.to_sym] = value
|
27
|
+
options
|
28
|
+
end
|
29
|
+
|
30
|
+
defaults = defaults.merge(config)
|
31
|
+
end
|
32
|
+
|
33
|
+
defaults
|
34
|
+
end
|
35
|
+
|
6
36
|
# :nodoc:
|
7
37
|
class ShellError < StandardError; end
|
8
38
|
end
|
9
39
|
|
10
|
-
require 'remotransmission/client'
|
11
40
|
require 'remotransmission/version'
|
41
|
+
require 'remotransmission/remote'
|
42
|
+
require 'remotransmission/client'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotransmission
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-24 00:00:00.000000000
|
12
|
+
date: 2012-08-24 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: choice
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirement: &82533290 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
@@ -21,15 +22,10 @@ dependencies:
|
|
21
22
|
version: '0.1'
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.1'
|
25
|
+
version_requirements: *82533290
|
30
26
|
- !ruby/object:Gem::Dependency
|
31
27
|
name: json
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
28
|
+
requirement: &82533040 !ruby/object:Gem::Requirement
|
33
29
|
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
@@ -37,12 +33,7 @@ dependencies:
|
|
37
33
|
version: '1.7'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '1.7'
|
36
|
+
version_requirements: *82533040
|
46
37
|
description: A gem that can talk to remote Transmission demons
|
47
38
|
email: sunny@sunfox.org
|
48
39
|
executables:
|
@@ -52,8 +43,10 @@ extra_rdoc_files: []
|
|
52
43
|
files:
|
53
44
|
- lib/remotransmission.rb
|
54
45
|
- lib/remotransmission/client.rb
|
46
|
+
- lib/remotransmission/remote.rb
|
55
47
|
- lib/remotransmission/version.rb
|
56
48
|
- bin/remotransmission
|
49
|
+
has_rdoc: true
|
57
50
|
homepage: http://github.com/sunny/remotransmission
|
58
51
|
licenses:
|
59
52
|
- MIT
|
@@ -73,10 +66,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
66
|
- - ! '>='
|
74
67
|
- !ruby/object:Gem::Version
|
75
68
|
version: '0'
|
76
|
-
requirements:
|
77
|
-
- Curl command line
|
69
|
+
requirements: []
|
78
70
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.6.2
|
80
72
|
signing_key:
|
81
73
|
specification_version: 3
|
82
74
|
summary: Remote Transmission
|