nzb 0.2.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.
- checksums.yaml +7 -0
- data/lib/nzb.rb +110 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a68ce356dc13bbd8a10bd669cf8465fc6c51bc84
|
4
|
+
data.tar.gz: ca4ae96226b754ac2fd64e6b6132a7fb20d3d1c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25b1be16c9ce25eda792e5cbe5279818771e6d3143317a720e2b10ea93ac5f95bbeaea14771a6deee3d1a7e29aae5c7bedbabcfe57c754876912574d828a937a
|
7
|
+
data.tar.gz: 5f2a3bbd4352d437e1fa34ff10eec70f0799dffd4524749131de9aeb5daa17b4dce073800c8f34b9ead9d7abd4ce019d7a2c3972cd6eda9271b80a67d5fcfe02
|
data/lib/nzb.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
########################################################################
|
2
|
+
# nzb - class used to generated nzb files according to nzb specs
|
3
|
+
# Copyright (c) 2013, Tadeus Dobrovolskij
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation; either version 2 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License along
|
15
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
16
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
17
|
+
########################################################################
|
18
|
+
# = Methods
|
19
|
+
# * write_header - invoked only once to generate xml header
|
20
|
+
# * write_file_header - you need to invoke it once for every file with following parameters:
|
21
|
+
# - poster - as in from field
|
22
|
+
# - subject - as in subject field
|
23
|
+
# - groups - separated by comma if more than one
|
24
|
+
# - date - optional; unix timestamp required
|
25
|
+
# * write_file_footer - invoked only once for every file; closes file section
|
26
|
+
# * write_segment - needs to be run for every segment(partial file)
|
27
|
+
# - size - size in bytes
|
28
|
+
# - number - number of the part
|
29
|
+
# - msgid - message ID as told by the NNTP server
|
30
|
+
# * write_footer - closes nzb. Normally you shouldn't write to a file after this method was invoked.
|
31
|
+
########################################################################
|
32
|
+
require 'cgi'
|
33
|
+
|
34
|
+
class Nzb
|
35
|
+
# we accept basename and prefix, combine them and add suffix ".nzb"
|
36
|
+
def initialize(filename,prefix='')
|
37
|
+
@nzb_filename = prefix + filename + ".nzb"
|
38
|
+
end
|
39
|
+
|
40
|
+
# nzb header
|
41
|
+
def write_header(name=nil)
|
42
|
+
begin
|
43
|
+
f = File.open(@nzb_filename,"w+:ISO-8859-1")
|
44
|
+
rescue
|
45
|
+
raise "Unable to open #{@nzb_filename} for writing."
|
46
|
+
end
|
47
|
+
f.puts '<?xml version="1.0" encoding="iso-8859-1" ?>'
|
48
|
+
f.puts '<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.nzbindex.com/nzb-1.0.dtd">'
|
49
|
+
f.puts '<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">'
|
50
|
+
if !name.nil?
|
51
|
+
f.puts ' <head>'
|
52
|
+
f.puts ' <meta type="title">' + name + '</meta>'
|
53
|
+
f.puts ' </head>'
|
54
|
+
end
|
55
|
+
f.close
|
56
|
+
end
|
57
|
+
|
58
|
+
# date must be in unix timestamp or nil(it isn't checked anyway, so whatever)
|
59
|
+
def write_file_header(poster,subject,groups,date=nil)
|
60
|
+
begin
|
61
|
+
f = File.open(@nzb_filename,"a:ISO-8859-1")
|
62
|
+
rescue
|
63
|
+
raise "Unable to open #{@nzb_filename} for writing."
|
64
|
+
end
|
65
|
+
from = CGI.escapeHTML(poster)
|
66
|
+
subj = CGI.escapeHTML(subject)
|
67
|
+
date = Time.now.to_i if date.nil?
|
68
|
+
f.puts "<file poster=\"#{from}\" date=\"#{date}\" subject=\"#{subj}\">"
|
69
|
+
f.puts '<groups>'
|
70
|
+
groups.split(',').each do |group|
|
71
|
+
f.puts '<group>' + group.strip + '</group>'
|
72
|
+
end
|
73
|
+
f.puts '</groups>'
|
74
|
+
f.puts '<segments>'
|
75
|
+
f.close
|
76
|
+
end
|
77
|
+
|
78
|
+
# method closes file section
|
79
|
+
def write_file_footer
|
80
|
+
begin
|
81
|
+
f = File.open(@nzb_filename,"a:ISO-8859-1")
|
82
|
+
rescue
|
83
|
+
raise "Unable to open #{@nzb_filename} for writing."
|
84
|
+
end
|
85
|
+
f.puts '</segments>'
|
86
|
+
f.puts '</file>'
|
87
|
+
f.close
|
88
|
+
end
|
89
|
+
|
90
|
+
def write_segment(size,number,msgid)
|
91
|
+
begin
|
92
|
+
f = File.open(@nzb_filename,"a:ISO-8859-1")
|
93
|
+
rescue
|
94
|
+
raise "Unable to open #{@nzb_filename} for writing."
|
95
|
+
end
|
96
|
+
f.puts "<segment bytes=\"#{size}\" number=\"#{number}\">#{msgid}</segment>"
|
97
|
+
f.close
|
98
|
+
end
|
99
|
+
|
100
|
+
# close nzb
|
101
|
+
def write_footer
|
102
|
+
begin
|
103
|
+
f = File.open(@nzb_filename,"a:ISO-8859-1")
|
104
|
+
rescue
|
105
|
+
raise "Unable to open #{@nzb_filename} for writing."
|
106
|
+
end
|
107
|
+
f.puts '</nzb>'
|
108
|
+
f.close
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nzb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tadeus Dobrovolskij
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Library for nzb file generation
|
14
|
+
email: root@tad-do.net
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/nzb.rb
|
20
|
+
homepage: https://github.com/tdobrovolskij/nzb
|
21
|
+
licenses:
|
22
|
+
- GPLv2
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: nzb
|
44
|
+
test_files: []
|