kieranj-nzb 0.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.
- data/Readme.rdoc +21 -0
- data/history.txt +3 -0
- data/lib/nzb.rb +44 -0
- data/lib/nzb/file.rb +28 -0
- data/lib/nzb/parser.rb +50 -0
- data/lib/nzb/segment.rb +14 -0
- data/license.txt +20 -0
- data/spec/file_spec.rb +9 -0
- data/spec/fixtures/sample.nzb +14 -0
- data/spec/nzb_spec.rb +5 -0
- data/spec/parser_spec.rb +18 -0
- data/spec/segment_spec.rb +26 -0
- metadata +73 -0
data/Readme.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= Read Me
|
2
|
+
|
3
|
+
Nzb - Ruby library for parsing nzb files
|
4
|
+
|
5
|
+
by Kieran Johnson
|
6
|
+
http://github.com/kieranj/nzb
|
7
|
+
|
8
|
+
== Installation:
|
9
|
+
|
10
|
+
$ gem sources -a http://gems.github.com/ (you only need to do this once)
|
11
|
+
$ gem install kieranj-nzb
|
12
|
+
|
13
|
+
== Usage:
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'kieranj-nzb'
|
17
|
+
|
18
|
+
# Parse your file
|
19
|
+
fileset = Nzb.parser(file)
|
20
|
+
|
21
|
+
# This returns an array of file objects. Each file in turn contains an array of segments. Each segment has the msg_id, number and bytes.
|
data/history.txt
ADDED
data/lib/nzb.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
%w(rubygems libxml).each { |lib| require lib }
|
2
|
+
|
3
|
+
# = Overview:
|
4
|
+
# A library for parsing nzb files using libxml for speed
|
5
|
+
# ---
|
6
|
+
# = License:
|
7
|
+
# Author:: Kieran Johnson
|
8
|
+
# Copyright:: November, 2008
|
9
|
+
# License:: Ruby License
|
10
|
+
# ---
|
11
|
+
# = Usage:
|
12
|
+
# require 'rubygems'
|
13
|
+
# require 'kieranj-nzb'
|
14
|
+
#
|
15
|
+
# n = Nzb.parse(file) # fileset
|
16
|
+
|
17
|
+
class Nzb
|
18
|
+
|
19
|
+
module VERSION
|
20
|
+
MAJOR = 0
|
21
|
+
MINOR = 0
|
22
|
+
TINY = 1
|
23
|
+
|
24
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
25
|
+
|
26
|
+
def self.to_s
|
27
|
+
STRING
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
%w(file segment parser).each do |lib|
|
33
|
+
require ::File.join(::File.dirname(__FILE__), 'nzb', lib)
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
|
38
|
+
def parse(file)
|
39
|
+
Parser.new(file).parse
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/nzb/file.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Nzb
|
2
|
+
|
3
|
+
class File
|
4
|
+
|
5
|
+
attr_accessor :segments, :groups, :subject
|
6
|
+
|
7
|
+
def initialize(attrs)
|
8
|
+
@segments = []
|
9
|
+
@groups = []
|
10
|
+
@subject = attrs["subject"]
|
11
|
+
@filename = ""
|
12
|
+
@poster = attrs["poster"]
|
13
|
+
@date = attrs["date"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_segment(attrs)
|
17
|
+
@segment = Segment.new(attrs)
|
18
|
+
@segments << @segment
|
19
|
+
@segment
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_group(name)
|
23
|
+
@groups << name
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/nzb/parser.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
class Nzb
|
2
|
+
|
3
|
+
class Parser
|
4
|
+
|
5
|
+
def initialize(file)
|
6
|
+
@parser = LibXML::XML::SaxParser.new
|
7
|
+
@parser.file = file
|
8
|
+
@parser.callbacks = Callbacks.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
@parser.parse
|
13
|
+
@parser.callbacks.files
|
14
|
+
end
|
15
|
+
|
16
|
+
class Callbacks
|
17
|
+
include LibXML::XML::SaxParser::Callbacks
|
18
|
+
|
19
|
+
attr_reader :files
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@files = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_start_element(name, attrs)
|
26
|
+
case name
|
27
|
+
when "file"
|
28
|
+
@files << File.new(attrs)
|
29
|
+
when "segment"
|
30
|
+
@segment = @files.last.add_segment(attrs)
|
31
|
+
when "group"
|
32
|
+
@group = true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_characters(text)
|
37
|
+
if @segment
|
38
|
+
@segment.msgid = text.strip
|
39
|
+
@segment = nil
|
40
|
+
elsif @group
|
41
|
+
@files.last.add_group(text.strip)
|
42
|
+
@group = nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/nzb/segment.rb
ADDED
data/license.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Kieran Johnson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/spec/file_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1" ?>
|
2
|
+
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd">
|
3
|
+
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
|
4
|
+
<file poster="Joe Bloggs >bloggs@nowhere.example<" date="1071674882" subject="Here's your file! abc-mr2a.r01 (1/2)">
|
5
|
+
<groups>
|
6
|
+
<group>alt.binaries.newzbin</group>
|
7
|
+
<group>alt.binaries.mojo</group>
|
8
|
+
</groups>
|
9
|
+
<segments>
|
10
|
+
<segment bytes="102394" number="1">123456789abcdef@news.newzbin.com</segment>
|
11
|
+
<segment bytes="4501" number="2">987654321fedbca@news.newzbin.com</segment>
|
12
|
+
</segments>
|
13
|
+
</file>
|
14
|
+
</nzb>
|
data/spec/nzb_spec.rb
ADDED
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class Nzb
|
4
|
+
|
5
|
+
describe Parser do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@parser = Parser.new(File.dirname(__FILE__) + "/fixtures/sample.nzb")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return a fileset instance" do
|
12
|
+
fileset = @parser.parse
|
13
|
+
fileset.should be_instance_of(Fileset)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class Nzb
|
4
|
+
|
5
|
+
describe Segment do
|
6
|
+
|
7
|
+
before do
|
8
|
+
attrs = {"msgid" => "123456789abcdef@news.newzbin.com", "bytes" => "102394", "number" => "1"}
|
9
|
+
@segment = Segment.new(attrs)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have the msg_id" do
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have the segment number" do
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have the message size" do
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kieranj-nzb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kieran Johnson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-22 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: libxml-ruby
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.7
|
23
|
+
version:
|
24
|
+
description: Library for parsing NZB files.
|
25
|
+
email: kieran[AT]invisiblelines.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- Readme.rdoc
|
32
|
+
files:
|
33
|
+
- history.txt
|
34
|
+
- license.txt
|
35
|
+
- lib/nzb.rb
|
36
|
+
- lib/nzb/file.rb
|
37
|
+
- lib/nzb/segment.rb
|
38
|
+
- lib/nzb/parser.rb
|
39
|
+
- README.rdoc
|
40
|
+
- Readme.rdoc
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/kieranj/nzb
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --main
|
46
|
+
- Readme.rdoc
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project: nzb
|
64
|
+
rubygems_version: 1.2.0
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: A library for parsing nzb files using libxml for speed
|
68
|
+
test_files:
|
69
|
+
- spec/fixtures/sample.nzb
|
70
|
+
- spec/file_spec.rb
|
71
|
+
- spec/segment_spec.rb
|
72
|
+
- spec/parser_spec.rb
|
73
|
+
- spec/nzb_spec.rb
|