nzbget 0.6.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/Manifest +7 -0
- data/README.rdoc +50 -0
- data/Rakefile +14 -0
- data/lib/group.rb +98 -0
- data/lib/httparty/request.rb +14 -0
- data/lib/nzbget.rb +87 -0
- data/nzbget.gemspec +33 -0
- metadata +78 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
== Introduction
|
2
|
+
|
3
|
+
This Ruby gem provides a simple means of using NZBGet's RPC interface from within Ruby. It is very lightweight and has minimal dependencies.
|
4
|
+
|
5
|
+
NZBGet homepage: http://nzbget.sourceforge.net
|
6
|
+
NZBGet is a command-line based binary newsgrabber for nzb files, written in C++. It supports client/server mode, automatic par-check/-repair and web-interface (via additional package). NZBGet requires low system resources and runs great on routers and NAS-devices.
|
7
|
+
|
8
|
+
NZBGet RPC: http://nzbget.sourceforge.net/rpc.html
|
9
|
+
From the version 0.4.0 NZBGet has supported XML-RPC and JSON-RPC. It allows to control the server from other applications. Many programming languages have libraries, which make the usage of XML-RPC and JSON-RPC very simple. The implementations of both protocols in NZBGet are equal: all methods are identical. You may choose the protocol, which is better supported by your programming language.
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
To install directly from GitHub:
|
14
|
+
|
15
|
+
$ gem sources -a http://gems.github.com # you only need to run this once
|
16
|
+
$ gem install marcbowes-nzbget
|
17
|
+
|
18
|
+
== Getting started
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
require 'nzbget'
|
22
|
+
|
23
|
+
remote = Nzbget.new :uri => 'http://nzbget-server'
|
24
|
+
puts remote.status
|
25
|
+
|
26
|
+
== License
|
27
|
+
|
28
|
+
Copyright (c) 2009 Marc Bowes
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person
|
31
|
+
obtaining a copy of this software and associated documentation
|
32
|
+
files (the "Software"), to deal in the Software without
|
33
|
+
restriction, including without limitation the rights to use,
|
34
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
35
|
+
copies of the Software, and to permit persons to whom the
|
36
|
+
Software is furnished to do so, subject to the following
|
37
|
+
conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
44
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
45
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
46
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
47
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
48
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
49
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
50
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('nzbget', '0.6.0') do |p|
|
6
|
+
p.description = "Communicate with NZBGet via RPC."
|
7
|
+
p.url = "http://github.com/marcbowes/nzbget"
|
8
|
+
p.author = "Marc Bowes"
|
9
|
+
p.email = "marcbowes@gmail.com"
|
10
|
+
p.runtime_dependencies = ['httparty']
|
11
|
+
end
|
12
|
+
|
13
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
14
|
+
|
data/lib/group.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module NZBGet
|
2
|
+
class Group
|
3
|
+
attr_accessor :attributes
|
4
|
+
|
5
|
+
def initialize(nzbget, hash)
|
6
|
+
@nzbget = nzbget
|
7
|
+
@attributes = hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def category=(category = '')
|
11
|
+
@nzbget.editqueue('GroupSetCategory', 0, category, @attributes['LastID'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete
|
15
|
+
@nzbget.editqueue('GroupDelete', 0, '', @attributes['LastID'])
|
16
|
+
end
|
17
|
+
|
18
|
+
def downloaded(format = :bytes)
|
19
|
+
formatted_response [size - remaining, 0].max, format
|
20
|
+
end
|
21
|
+
|
22
|
+
def formatted_response(bytes, format)
|
23
|
+
case format
|
24
|
+
when :bytes, :b then bytes
|
25
|
+
when :kilobytes, :kb then bytes.to_f / 1024
|
26
|
+
when :megabytes, :mb then bytes.to_f / 1024 ** 2
|
27
|
+
when :gigabytes, :gb then bytes.to_f / 1024 ** 3
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<#{self.class} name=\"#{self.name}\">"
|
33
|
+
end
|
34
|
+
|
35
|
+
def name
|
36
|
+
@attributes['NZBNicename']
|
37
|
+
end
|
38
|
+
|
39
|
+
def move(offset_or_sym)
|
40
|
+
return move_to_offset(offset_or_sym) if offset_or_sym.is_a? Fixnum
|
41
|
+
return move_to_symbol(offset_or_sym) if offset_or_sym.is_a? Symbol
|
42
|
+
raise ArgumentError
|
43
|
+
end
|
44
|
+
|
45
|
+
def percentage
|
46
|
+
(downloaded + paused) * 100.0 / size
|
47
|
+
end
|
48
|
+
|
49
|
+
def pause(pars = nil)
|
50
|
+
command =
|
51
|
+
unless pars
|
52
|
+
'GroupPause'
|
53
|
+
else
|
54
|
+
if pars == :all
|
55
|
+
'GroupPauseAllPars'
|
56
|
+
elsif pars == :extra
|
57
|
+
'GroupPauseExtraPars'
|
58
|
+
else
|
59
|
+
raise ArgumentError
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
@nzbget.editqueue(command, 0, '', @attributes['LastID'])
|
64
|
+
end
|
65
|
+
|
66
|
+
def paused(format = :bytes)
|
67
|
+
formatted_response @attributes['PausedSizeLo'].to_i, format
|
68
|
+
end
|
69
|
+
|
70
|
+
def remaining(format = :bytes)
|
71
|
+
formatted_response @attributes['RemainingSizeLo'].to_i, format
|
72
|
+
end
|
73
|
+
|
74
|
+
def resume
|
75
|
+
@nzbget.editqueue('GroupResume', 0, '', @attributes['LastID'])
|
76
|
+
end
|
77
|
+
|
78
|
+
def size(format = :bytes)
|
79
|
+
formatted_response @attributes['FileSizeLo'].to_i, format
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def move_to_offset(offset)
|
85
|
+
@nzbget.editqueue('GroupMoveOffset', offset, '', @attributes['LastID'])
|
86
|
+
end
|
87
|
+
|
88
|
+
def move_to_symbol(sym)
|
89
|
+
command = case sym
|
90
|
+
when :top then 'GroupMoveTop'
|
91
|
+
when :bottom then 'GroupMoveBottom'
|
92
|
+
else raise ArgumentError
|
93
|
+
end
|
94
|
+
|
95
|
+
@nzbget.editqueue(command, 0, '', @attributes['LastID'])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HTTParty
|
2
|
+
class Request
|
3
|
+
def uri
|
4
|
+
new_uri = path.relative? ? URI.parse("#{options[:base_uri]}#{path}") : path
|
5
|
+
|
6
|
+
# avoid double query string on redirects [#12]
|
7
|
+
unless @redirect
|
8
|
+
new_uri.query = query_string(new_uri)
|
9
|
+
end
|
10
|
+
new_uri.query = nil if new_uri.query.blank?
|
11
|
+
new_uri
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/nzbget.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require File.join(File.dirname(__FILE__), 'httparty/request')
|
4
|
+
require 'group'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module NZBGet
|
8
|
+
class RemoteConnection
|
9
|
+
include HTTParty
|
10
|
+
|
11
|
+
DEFAULT_OPTIONS = {
|
12
|
+
:method => :json,
|
13
|
+
:password => 'tegbzn6789',
|
14
|
+
:port => 6789,
|
15
|
+
:uri => 'http://localhost',
|
16
|
+
:username => 'nzbget'
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(options = {})
|
20
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
21
|
+
|
22
|
+
uri = URI.parse(@options[:uri])
|
23
|
+
uri.port = @options[:port]
|
24
|
+
|
25
|
+
self.class.base_uri uri.to_s
|
26
|
+
self.class.basic_auth @options[:username], @options[:password]
|
27
|
+
|
28
|
+
case @options[:method]
|
29
|
+
when :json
|
30
|
+
require 'json'
|
31
|
+
when :xml
|
32
|
+
raise ArgumentError
|
33
|
+
else
|
34
|
+
raise ArgumentError
|
35
|
+
end
|
36
|
+
self.class.format @options[:method]
|
37
|
+
end
|
38
|
+
|
39
|
+
def enqueue(path, options = {})
|
40
|
+
extname = File.extname(path)
|
41
|
+
raise ArgumentError unless extname.downcase == '.nzb'
|
42
|
+
|
43
|
+
filename = options[:filename] || File.basename(path).sub(/#{extname}$/, '')
|
44
|
+
category = options[:category] || ''
|
45
|
+
add_to_top = options[:to_top] || false
|
46
|
+
|
47
|
+
content = open(path).read
|
48
|
+
send :append, filename, category, add_to_top, Base64.encode64(content).strip
|
49
|
+
end
|
50
|
+
|
51
|
+
def paused?
|
52
|
+
send(:status)['result']['ServerPaused']
|
53
|
+
end
|
54
|
+
|
55
|
+
def groups
|
56
|
+
send(:listgroups)['result'].collect { |g| NZBGet::Group.new(self, g) }
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def encode(hash)
|
62
|
+
hash.send("to_#{@options[:method].to_s}".to_sym)
|
63
|
+
end
|
64
|
+
|
65
|
+
def method_missing(name, *args)
|
66
|
+
invoke name, args
|
67
|
+
end
|
68
|
+
|
69
|
+
def invoke(method, params)
|
70
|
+
#
|
71
|
+
# According to http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#RequestHeaders:
|
72
|
+
#
|
73
|
+
# Regardless of whether a remote procedure call is made using HTTP GET or POST, the HTTP request message MUST specify the following headers:
|
74
|
+
# * The User-Agent MUST be specified.
|
75
|
+
# * For HTTP POST only, the Content-Type MUST be specified and SHOULD read application/json.
|
76
|
+
# * The Content-Length MUST be specified and correct according to the guidelines and rules laid out in Section 4.4, “Message Length”, of the HTTP specification.
|
77
|
+
# * The Accept MUST be specified and SHOULD read application/json.
|
78
|
+
#
|
79
|
+
# However, NZBGet does not check these headers, so they are not included.
|
80
|
+
#
|
81
|
+
|
82
|
+
response = self.class.post("/#{@options[:method].to_s}rpc",
|
83
|
+
:body => encode({ :method => method.to_s, :params => params, :version => '1.1' }))
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
data/nzbget.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{nzbget}
|
5
|
+
s.version = "0.6.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Marc Bowes"]
|
9
|
+
s.date = %q{2009-10-21}
|
10
|
+
s.description = %q{Communicate with NZBGet via RPC.}
|
11
|
+
s.email = %q{marcbowes@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/group.rb", "lib/httparty/request.rb", "lib/nzbget.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/group.rb", "lib/httparty/request.rb", "lib/nzbget.rb", "nzbget.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/marcbowes/nzbget}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nzbget", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{nzbget}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Communicate with NZBGet via RPC.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nzbget
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marc Bowes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-21 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Communicate with NZBGet via RPC.
|
26
|
+
email: marcbowes@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- lib/group.rb
|
34
|
+
- lib/httparty/request.rb
|
35
|
+
- lib/nzbget.rb
|
36
|
+
files:
|
37
|
+
- Manifest
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- lib/group.rb
|
41
|
+
- lib/httparty/request.rb
|
42
|
+
- lib/nzbget.rb
|
43
|
+
- nzbget.gemspec
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/marcbowes/nzbget
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --line-numbers
|
51
|
+
- --inline-source
|
52
|
+
- --title
|
53
|
+
- Nzbget
|
54
|
+
- --main
|
55
|
+
- README.rdoc
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "1.2"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project: nzbget
|
73
|
+
rubygems_version: 1.3.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Communicate with NZBGet via RPC.
|
77
|
+
test_files: []
|
78
|
+
|