pirate-autonzb 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +6 -3
- data/Rakefile +2 -2
- data/autonzb.gemspec +6 -6
- data/bin/autonzb +15 -7
- data/lib/imdb.rb +1 -0
- data/lib/inspector.rb +41 -10
- data/lib/movie.rb +12 -5
- data/lib/sites/newzleech/nfo.rb +35 -0
- data/lib/sites/newzleech/nzb.rb +118 -0
- data/lib/sites/nzbs/mechanize_hack.rb +41 -0
- data/lib/sites/nzbs/nfo.rb +36 -0
- data/lib/sites/nzbs/nzb.rb +137 -0
- metadata +14 -8
- data/lib/nfo.rb +0 -33
- data/lib/nzb.rb +0 -132
data/Manifest
CHANGED
@@ -4,8 +4,11 @@ bin/autonzb
|
|
4
4
|
lib/imdb.rb
|
5
5
|
lib/inspector.rb
|
6
6
|
lib/movie.rb
|
7
|
-
lib/nfo.rb
|
8
|
-
lib/nzb.rb
|
7
|
+
lib/sites/newzleech/nfo.rb
|
8
|
+
lib/sites/newzleech/nzb.rb
|
9
|
+
lib/sites/nzbs/mechanize_hack.rb
|
10
|
+
lib/sites/nzbs/nfo.rb
|
11
|
+
lib/sites/nzbs/nzb.rb
|
9
12
|
Manifest
|
10
13
|
Rakefile
|
11
|
-
README.markdown
|
14
|
+
README.markdown
|
data/Rakefile
CHANGED
@@ -3,8 +3,8 @@ require 'rubygems'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('autonzb', '0.
|
7
|
-
p.description = "Ruby tool to automatically download x264 HD nzb movies files from newzleech.com"
|
6
|
+
Echoe.new('autonzb', '0.5.0') do |p|
|
7
|
+
p.description = "Ruby tool to automatically download x264 HD nzb movies files from newzleech.com & nzbs.org"
|
8
8
|
p.url = "http://github.com/pirate/autonzb"
|
9
9
|
p.author = "Pirate"
|
10
10
|
p.email = "pirate.2061@gmail.com"
|
data/autonzb.gemspec
CHANGED
@@ -2,24 +2,24 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{autonzb}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.5.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Pirate"]
|
9
|
-
s.date = %q{2009-03-
|
9
|
+
s.date = %q{2009-03-22}
|
10
10
|
s.default_executable = %q{autonzb}
|
11
|
-
s.description = %q{Ruby tool to automatically download x264 HD nzb movies files from newzleech.com}
|
11
|
+
s.description = %q{Ruby tool to automatically download x264 HD nzb movies files from newzleech.com & nzbs.org}
|
12
12
|
s.email = %q{pirate.2061@gmail.com}
|
13
13
|
s.executables = ["autonzb"]
|
14
|
-
s.extra_rdoc_files = ["bin/autonzb", "lib/imdb.rb", "lib/inspector.rb", "lib/movie.rb", "lib/nfo.rb", "lib/nzb.rb", "README.markdown"]
|
15
|
-
s.files = ["asset/failure.png", "autonzb.gemspec", "bin/autonzb", "lib/imdb.rb", "lib/inspector.rb", "lib/movie.rb", "lib/nfo.rb", "lib/nzb.rb", "Manifest", "Rakefile", "README.markdown"]
|
14
|
+
s.extra_rdoc_files = ["bin/autonzb", "lib/imdb.rb", "lib/inspector.rb", "lib/movie.rb", "lib/sites/newzleech/nfo.rb", "lib/sites/newzleech/nzb.rb", "lib/sites/nzbs/mechanize_hack.rb", "lib/sites/nzbs/nfo.rb", "lib/sites/nzbs/nzb.rb", "README.markdown"]
|
15
|
+
s.files = ["asset/failure.png", "autonzb.gemspec", "bin/autonzb", "lib/imdb.rb", "lib/inspector.rb", "lib/movie.rb", "lib/sites/newzleech/nfo.rb", "lib/sites/newzleech/nzb.rb", "lib/sites/nzbs/mechanize_hack.rb", "lib/sites/nzbs/nfo.rb", "lib/sites/nzbs/nzb.rb", "Manifest", "Rakefile", "README.markdown"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/pirate/autonzb}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Autonzb", "--main", "README.markdown"]
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.rubyforge_project = %q{autonzb}
|
21
21
|
s.rubygems_version = %q{1.3.1}
|
22
|
-
s.summary = %q{Ruby tool to automatically download x264 HD nzb movies files from newzleech.com}
|
22
|
+
s.summary = %q{Ruby tool to automatically download x264 HD nzb movies files from newzleech.com & nzbs.org}
|
23
23
|
|
24
24
|
if s.respond_to? :specification_version then
|
25
25
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/bin/autonzb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'optiflag'
|
4
4
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'inspector')
|
5
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'nzb')
|
6
5
|
|
7
6
|
module AutoNZB extend OptiFlagSet
|
8
7
|
flag "d" do
|
@@ -35,17 +34,26 @@ module AutoNZB extend OptiFlagSet
|
|
35
34
|
optional_flag "backup" do
|
36
35
|
description "Backup folder path (to save a copy of all downloaded nzb files and prevent an already downloaded nzb to be re-downloaded)"
|
37
36
|
end
|
37
|
+
optional_flag "login" do
|
38
|
+
description "Username for www.nzbs.org"
|
39
|
+
end
|
40
|
+
optional_flag "pass" do
|
41
|
+
description "Password for www.nzbs.org"
|
42
|
+
end
|
38
43
|
|
39
44
|
and_process!
|
40
45
|
end
|
41
46
|
|
42
47
|
begin
|
43
|
-
inspector = Inspector.new(ARGV.flags.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
inspector = Inspector.new(ARGV.flags.d, :year => ARGV.flags.year,
|
49
|
+
:imdb_score => ARGV.flags.imdb,
|
50
|
+
:srt => ARGV.flags.srt,
|
51
|
+
:age => ARGV.flags.age,
|
52
|
+
:pages => ARGV.flags.pages,
|
53
|
+
:backup_path => ARGV.flags.backup,
|
54
|
+
:movie_paths => ARGV.flags.movies,
|
55
|
+
:login => ARGV.flags.login,
|
56
|
+
:pass => ARGV.flags.pass)
|
49
57
|
rescue => e
|
50
58
|
p e.to_s
|
51
59
|
Inspector.growl("AutoNZB Error!", 'look into the console log')
|
data/lib/imdb.rb
CHANGED
data/lib/inspector.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'movie')
|
2
|
+
require File.join(File.dirname(__FILE__), 'sites', 'newzleech', 'nzb')
|
3
|
+
require File.join(File.dirname(__FILE__), 'sites', 'nzbs', 'nzb')
|
2
4
|
|
3
5
|
class Inspector
|
4
6
|
|
5
7
|
attr_accessor :backup_path, :movies, :nzbs
|
6
8
|
|
7
|
-
def initialize(
|
8
|
-
@paths =
|
9
|
+
def initialize(download_path, options = {})
|
10
|
+
@paths = options[:movie_paths] ? options[:movie_paths].split(',').map { |p| p.gsub(/\/$/,'') } : []
|
9
11
|
@options = options
|
10
12
|
@options[:srt] = @options[:srt] ? (@options[:srt].split(',') - ["unknown"] + ['unknown']).uniq : nil
|
11
13
|
@options[:imdb_score] = @options[:imdb_score] ? @options[:imdb_score].to_f : 7.0
|
@@ -14,14 +16,22 @@ class Inspector
|
|
14
16
|
@movies = []
|
15
17
|
initialize_movies
|
16
18
|
|
17
|
-
if @options[:
|
18
|
-
@backup_path = @options[:
|
19
|
+
if @options[:backup_path]
|
20
|
+
@backup_path = @options[:backup_path].gsub(/\/$/,'')
|
19
21
|
@nzbs = []
|
20
22
|
initialize_nzbs
|
21
23
|
@movies = @nzbs + @movies
|
22
24
|
end
|
23
25
|
|
24
|
-
$stdout.print "Movie criteria: imdb score >= #{@options[:imdb_score]}, year >= #{@options[:year]} and srt [#{@options[:srt].join(',')}]\n"
|
26
|
+
$stdout.print "Movie criteria: imdb score >= #{@options[:imdb_score]}, year >= #{@options[:year]}#{" and srt [#{@options[:srt].join(',')}]" if @options[:srt]}\n"
|
27
|
+
|
28
|
+
if @options[:login] && @options[:pass]
|
29
|
+
Nzbs::NZB.new(self, download_path, @options)
|
30
|
+
else
|
31
|
+
Newzleech::NZB.new(self, download_path, @options)
|
32
|
+
end
|
33
|
+
|
34
|
+
keep_only_best_nzb if @backup_path
|
25
35
|
end
|
26
36
|
|
27
37
|
def need?(movie, not_validate = false, movies = @movies, log = true)
|
@@ -95,6 +105,8 @@ private
|
|
95
105
|
@nzbs << Movie.new(nzb, :path => nzb_path) if File.extname(nzb_path) == '.nzb'
|
96
106
|
end
|
97
107
|
$stdout.print "Found #{@nzbs.size} backuped nzb(s) in #{@backup_path}\n"
|
108
|
+
rescue => e
|
109
|
+
$stdout.print "Problem with backup nzb: #{e}\n"
|
98
110
|
end
|
99
111
|
|
100
112
|
def clean_dir(dir)
|
@@ -108,11 +120,15 @@ private
|
|
108
120
|
end
|
109
121
|
|
110
122
|
def srt_score(movie)
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
123
|
+
if @options[:srt]
|
124
|
+
srts = @options[:srt].reverse
|
125
|
+
movie.srt.inject(-1) do |score, srt|
|
126
|
+
s = (i = srts.index(srt)) ? i : -1
|
127
|
+
score = s if s > score
|
128
|
+
score
|
129
|
+
end
|
130
|
+
else
|
131
|
+
0
|
116
132
|
end
|
117
133
|
end
|
118
134
|
|
@@ -137,5 +153,20 @@ private
|
|
137
153
|
def sound_score(movie)
|
138
154
|
movie.format == 'DTS' ? 1 : 0
|
139
155
|
end
|
156
|
+
|
157
|
+
def keep_only_best_nzb
|
158
|
+
size = 0
|
159
|
+
@nzbs.each do |nzb|
|
160
|
+
nzbs = @nzbs.select { |item| item.path != nzb.path }
|
161
|
+
unless need?(nzb, true, nzbs, false)
|
162
|
+
File.delete(nzb.path)
|
163
|
+
size += 1
|
164
|
+
end
|
165
|
+
end
|
166
|
+
if size > 0
|
167
|
+
$stdout.print "#########################################################################\n"
|
168
|
+
$stdout.print "Deleted #{size} useless backuped nzb(s) (keep only the best nzb by movie)\n"
|
169
|
+
end
|
170
|
+
end
|
140
171
|
|
141
172
|
end
|
data/lib/movie.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'imdb')
|
2
|
-
require File.join(File.dirname(__FILE__), 'nfo')
|
3
2
|
|
4
3
|
class Movie
|
5
4
|
include Comparable
|
@@ -12,6 +11,11 @@ class Movie
|
|
12
11
|
attributes.each { |k,v| self.send("#{k}=", v) }
|
13
12
|
@srt, @tags = [], []
|
14
13
|
|
14
|
+
# for info set with nzbs title
|
15
|
+
if name && year && score
|
16
|
+
@info_get_from_title = true
|
17
|
+
end
|
18
|
+
|
15
19
|
set_name
|
16
20
|
set_year
|
17
21
|
set_format
|
@@ -21,8 +25,9 @@ class Movie
|
|
21
25
|
set_lang
|
22
26
|
set_encoding
|
23
27
|
set_tags
|
28
|
+
|
24
29
|
set_imdb_id
|
25
|
-
set_data_from_imdb unless path
|
30
|
+
set_data_from_imdb unless path || @info_get_from_title
|
26
31
|
end
|
27
32
|
|
28
33
|
def score
|
@@ -65,7 +70,7 @@ private
|
|
65
70
|
end
|
66
71
|
|
67
72
|
def set_name
|
68
|
-
if
|
73
|
+
if name.nil?
|
69
74
|
raw_name = @raw_name.gsub(/\(|\)|\[|\]|\{|\}|\//, ' ')
|
70
75
|
if matched = raw_name.match(/(.*)(19[0-9]{2}|20[0-9]{2})[^p]/)
|
71
76
|
@name = matched[1]
|
@@ -82,8 +87,10 @@ private
|
|
82
87
|
end
|
83
88
|
|
84
89
|
def set_year
|
85
|
-
if
|
86
|
-
|
90
|
+
if year.nil?
|
91
|
+
if matched = @raw_name.match(/19[0-9]{2}|20[0-9]{2}/)
|
92
|
+
@year = matched[0].to_i
|
93
|
+
end
|
87
94
|
end
|
88
95
|
end
|
89
96
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Newzleech
|
4
|
+
class Nfo
|
5
|
+
|
6
|
+
attr_accessor :srt, :imdb_link
|
7
|
+
|
8
|
+
def initialize(url)
|
9
|
+
@nfo = open(url.gsub(/\/$/,'')).read
|
10
|
+
@srt = []
|
11
|
+
|
12
|
+
parse_nfo
|
13
|
+
@srt.uniq!
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# searching for subtitles languages info & imdb link
|
19
|
+
def parse_nfo
|
20
|
+
@nfo.split(/\n/).each do |line|
|
21
|
+
case line
|
22
|
+
when /subtitle|sub/i
|
23
|
+
@srt << 'fr' if line =~ /fr|fre|french/i
|
24
|
+
@srt << 'en' if line =~ /en|eng|english/i
|
25
|
+
# TODO add more language parsing here
|
26
|
+
@srt << 'none' if line =~ /none/i
|
27
|
+
when /imdb\.com\/title\//
|
28
|
+
@imdb_link = (matched = line.match(/imdb.com\/title\/(tt[0-9]+)/)) && "http://imdb.com/title/#{matched[1]}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@srt << 'unknown' if @srt.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'hpricot'
|
3
|
+
require 'zip/zip'
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), 'nfo')
|
6
|
+
|
7
|
+
module Newzleech
|
8
|
+
class NZB
|
9
|
+
|
10
|
+
URL = 'http://www.newzleech.com'
|
11
|
+
|
12
|
+
attr_accessor :movies, :agent
|
13
|
+
|
14
|
+
def initialize(inspector, download_path, options = {})
|
15
|
+
@inspector, @download_path = inspector, download_path.gsub(/\/$/,'')
|
16
|
+
@options = options
|
17
|
+
@options[:age] ||= 160
|
18
|
+
@options[:pages] ||= 2
|
19
|
+
|
20
|
+
@nzb_urls = []
|
21
|
+
@movies = []
|
22
|
+
|
23
|
+
(1..(@options[:pages].to_i)).each do |page|
|
24
|
+
@nzb_urls << "#{URL}?group=143&minage=&age=160&min=4000&max=max&q=&m=search&adv=1&offset=#{(page.to_i - 1) * 60}"
|
25
|
+
end
|
26
|
+
|
27
|
+
parse_newzleech
|
28
|
+
parse_movies
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def parse_newzleech
|
34
|
+
$stdout.print "Parsing #{URL} for new x264 HD nzb movies, with age <= #{@options[:age]}, in last #{@options[:pages]} page(s)\n"
|
35
|
+
@nzb_urls.each do |url|
|
36
|
+
doc = Hpricot(open(url))
|
37
|
+
doc.search("table.contentt").each do |table|
|
38
|
+
raw_name = raw_name(table)
|
39
|
+
if nfo_link = nfo_link(table)
|
40
|
+
nfo = Nfo.new(nfo_link)
|
41
|
+
imdb_link = nfo.imdb_link
|
42
|
+
else
|
43
|
+
imdb_link = imdb_link(table)
|
44
|
+
end
|
45
|
+
if raw_name && (imdb_link || (raw_name = find_clean_nzb_name(raw_name))) && raw_name.include?('x264')
|
46
|
+
age = parse_age(table.search("td.age").first.inner_html) # get age of the nzb
|
47
|
+
if age <= @options[:age].to_f
|
48
|
+
raw_name = clean_raw_name(raw_name)
|
49
|
+
movie = Movie.new(raw_name, :nfo => nfo, :imdb_link => imdb_link, :nzb_link => nzb_link(table), :age => age)
|
50
|
+
@movies << movie
|
51
|
+
|
52
|
+
$stdout.print '.'
|
53
|
+
$stdout.flush
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
$stdout.print "\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
def clean_raw_name(raw_name)
|
62
|
+
(find_clean_nzb_name(raw_name) || raw_name).strip
|
63
|
+
end
|
64
|
+
|
65
|
+
def find_clean_nzb_name(raw_name)
|
66
|
+
if matched = raw_name.match(/^\[[0-9]*\]-\[.*\]-\[(.*)\]-/)
|
67
|
+
matched[1]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def raw_name(table)
|
72
|
+
(a = table.search("td.subject a[@href^='?p=']").first) && a.inner_html
|
73
|
+
end
|
74
|
+
|
75
|
+
def nfo_link(table)
|
76
|
+
(nfo = table.search("td.subject a[@href^='nfo.php?id=']").first) && "#{URL}/#{nfo[:href]}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def imdb_link(table)
|
80
|
+
(imdb = table.search("td.subject a[@href^='http://anonym.to/?http://www.imdb.com']").first) && imdb[:href].match(/\?(.*)/)[1]
|
81
|
+
end
|
82
|
+
|
83
|
+
def nzb_link(table)
|
84
|
+
(nzb = table.search("td.get a[@href^='?m=gen&dl=1']").first) && "#{URL}/#{nzb[:href]}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def parse_movies
|
88
|
+
movies.each do |movie|
|
89
|
+
$stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age.to_i} day(s)\n"
|
90
|
+
if @inspector.need?(movie)
|
91
|
+
$stdout.print " => DOWNLOAD: #{movie.name} (#{movie.year})\n"
|
92
|
+
download_nzb(movie, @inspector.backup_path)
|
93
|
+
@inspector.movies << movie
|
94
|
+
end
|
95
|
+
end
|
96
|
+
$stdout.print "No nzb found, maybe change -age or -page setting\n" if @movies.empty?
|
97
|
+
end
|
98
|
+
|
99
|
+
def download_nzb(movie, backup_path = nil)
|
100
|
+
Tempfile.open("movie.nzb") do |tempfile|
|
101
|
+
tempfile.write(open(movie.nzb_link).read) # download the nzb
|
102
|
+
tempfile.close
|
103
|
+
File.copy(tempfile.path, "#{backup_path}/#{movie.dirname}.nzb") if backup_path
|
104
|
+
File.move(tempfile.path, "#{@download_path}/#{movie.dirname}.nzb")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse_age(string)
|
109
|
+
case string
|
110
|
+
when /h/i
|
111
|
+
string.to_f / 24
|
112
|
+
when /d/i
|
113
|
+
string.to_f
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module WWW
|
2
|
+
class Mechanize
|
3
|
+
class Chain
|
4
|
+
class ResponseReader
|
5
|
+
include WWW::Handler
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@response = response
|
9
|
+
end
|
10
|
+
|
11
|
+
def handle(ctx, params)
|
12
|
+
params[:response] = @response
|
13
|
+
body = StringIO.new
|
14
|
+
total = 0
|
15
|
+
@response.read_body { |part|
|
16
|
+
total += part.length
|
17
|
+
body.write(part)
|
18
|
+
Mechanize.log.debug("Read #{total} bytes") if Mechanize.log
|
19
|
+
}
|
20
|
+
body.rewind
|
21
|
+
|
22
|
+
res_klass = Net::HTTPResponse::CODE_TO_OBJ[@response.code.to_s]
|
23
|
+
raise ResponseCodeError.new(@response) unless res_klass
|
24
|
+
|
25
|
+
# Net::HTTP ignores EOFError if Content-length is given, so we emulate it here.
|
26
|
+
# unless res_klass <= Net::HTTPRedirection
|
27
|
+
# raise EOFError if (!params[:request].is_a?(Net::HTTP::Head)) && @response.content_length() && @response.content_length() != total
|
28
|
+
# end
|
29
|
+
|
30
|
+
@response.each_header { |k,v|
|
31
|
+
Mechanize.log.debug("response-header: #{ k } => #{ v }")
|
32
|
+
} if Mechanize.log
|
33
|
+
|
34
|
+
params[:response_body] = body
|
35
|
+
params[:res_klass] = res_klass
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Nzbs
|
4
|
+
class Nfo
|
5
|
+
|
6
|
+
attr_accessor :srt, :imdb_link
|
7
|
+
|
8
|
+
def initialize(agent, url)
|
9
|
+
@page = agent.get(url.gsub(/\/$/,''))
|
10
|
+
@srt = []
|
11
|
+
|
12
|
+
parse_nfo
|
13
|
+
@srt.uniq!
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# searching for subtitles languages info & imdb link
|
19
|
+
def parse_nfo
|
20
|
+
pre = @page.search('pre.nfo')
|
21
|
+
pre.to_s.split(/\n/).each do |line|
|
22
|
+
case line
|
23
|
+
when /subtitle|sub/i
|
24
|
+
@srt << 'fr' if line =~ /fr|fre|french/i
|
25
|
+
@srt << 'en' if line =~ /en|eng|english/i
|
26
|
+
# TODO add more language parsing here
|
27
|
+
@srt << 'none' if line =~ /none/i
|
28
|
+
when /imdb\.com\/title\//
|
29
|
+
@imdb_link = (matched = line.match(/imdb.com\/title\/(tt[0-9]+)/)) && "http://imdb.com/title/#{matched[1]}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
@srt << 'unknown' if @srt.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'hpricot'
|
3
|
+
require 'zip/zip'
|
4
|
+
require 'mechanize'
|
5
|
+
|
6
|
+
require File.join(File.dirname(__FILE__), 'nfo')
|
7
|
+
require File.join(File.dirname(__FILE__), 'mechanize_hack')
|
8
|
+
|
9
|
+
|
10
|
+
module Nzbs
|
11
|
+
class NZB
|
12
|
+
|
13
|
+
URL = 'http://www.nzbs.org'
|
14
|
+
|
15
|
+
attr_accessor :movies, :agent
|
16
|
+
|
17
|
+
def initialize(inspector, download_path, options = {})
|
18
|
+
@inspector, @download_path = inspector, download_path.gsub(/\/$/,'')
|
19
|
+
@options = options
|
20
|
+
@options[:age] ||= 160
|
21
|
+
@options[:pages] ||= 2
|
22
|
+
|
23
|
+
@nzb_urls = []
|
24
|
+
@movies = []
|
25
|
+
|
26
|
+
(1..(@options[:pages].to_i)).each do |page|
|
27
|
+
@nzb_urls << "#{URL}/index.php?action=browse&catid=4&page=#{(page)}"
|
28
|
+
end
|
29
|
+
|
30
|
+
login
|
31
|
+
parse_nzbs
|
32
|
+
parse_movies
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def login
|
38
|
+
@agent = WWW::Mechanize.new
|
39
|
+
page = @agent.get "#{URL}/index.php?action=browse&catid=4"
|
40
|
+
|
41
|
+
form = page.forms[1]
|
42
|
+
form.username = @options[:login]
|
43
|
+
form.password = @options[:pass]
|
44
|
+
|
45
|
+
@agent.submit form
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_nzbs
|
49
|
+
$stdout.print "Parsing #{URL} for new x264 HD nzb movies, with age <= #{@options[:age]}, in last #{@options[:pages]} page(s)\n"
|
50
|
+
@nzb_urls.each do |url|
|
51
|
+
page = @agent.get url
|
52
|
+
page.search("#nzbtable tr").each do |tr|
|
53
|
+
if raw_name = raw_name(tr)
|
54
|
+
if (age = age(tr)) <= @options[:age].to_f
|
55
|
+
if nfo_link = nfo_link(tr)
|
56
|
+
@nfo = Nfo.new(@agent, nfo_link(tr))
|
57
|
+
end
|
58
|
+
|
59
|
+
name, year, score = get_info_from_imdb_title(tr)
|
60
|
+
movie = Movie.new(raw_name, :name => name,
|
61
|
+
:year => year,
|
62
|
+
:score => score,
|
63
|
+
:imdb_link => imdb_link(tr),
|
64
|
+
:nzb_link => nzb_link(tr, page),
|
65
|
+
:age => age,
|
66
|
+
:nfo => @nfo)
|
67
|
+
@movies << movie
|
68
|
+
|
69
|
+
$stdout.print '.'
|
70
|
+
$stdout.flush
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
$stdout.print "\n"
|
76
|
+
end
|
77
|
+
|
78
|
+
def raw_name(tr)
|
79
|
+
(a = tr.search("a.nzb").first) && a.inner_html
|
80
|
+
end
|
81
|
+
|
82
|
+
def age(tr)
|
83
|
+
age_text = (td = tr.search("td[@align='right']").first) && td.inner_html
|
84
|
+
if age_text.include?("days ago")
|
85
|
+
age_text.to_f
|
86
|
+
else
|
87
|
+
$stdout.print "AGE NOT FOUND\n"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def nfo_link(tr)
|
92
|
+
(a = tr.search("small a[@href$='#nfo']").first) && a[:href]
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_info_from_imdb_title(tr)
|
96
|
+
title = (a = tr.search("small a.viewimdb").first) && a[:title]
|
97
|
+
if title
|
98
|
+
if matched = title.match(/^(.*)\s\(([0-9]{4}).*\s\((.*)\/10\)/)
|
99
|
+
name = matched[1]
|
100
|
+
year = matched[2]
|
101
|
+
score = matched[3]
|
102
|
+
return name, year.to_i, score.to_f
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def imdb_link(tr)
|
108
|
+
(a = tr.search("small a.viewimdb").first) && a[:href].match(/^http:\/\/anonym.to\/\?(.*)/)[1]
|
109
|
+
end
|
110
|
+
|
111
|
+
def nzb_link(tr, page)
|
112
|
+
(a = tr.search("a.dlnzb").first) && "#{URL}/#{a[:href]}"
|
113
|
+
end
|
114
|
+
|
115
|
+
def parse_movies
|
116
|
+
movies.each do |movie|
|
117
|
+
$stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age} day(s)\n"
|
118
|
+
if @inspector.need?(movie)
|
119
|
+
$stdout.print " => DOWNLOAD: #{movie.name} (#{movie.year})\n"
|
120
|
+
download_nzb(movie, @inspector.backup_path)
|
121
|
+
@inspector.movies << movie
|
122
|
+
end
|
123
|
+
end
|
124
|
+
$stdout.print "No nzb found, maybe change -age or -page setting\n" if @movies.empty?
|
125
|
+
end
|
126
|
+
|
127
|
+
def download_nzb(movie, backup_path = nil)
|
128
|
+
Tempfile.open("movie.nzb") do |tempfile|
|
129
|
+
tempfile.write(@agent.get_file(movie.nzb_link)) # download the nzb
|
130
|
+
tempfile.close
|
131
|
+
File.copy(tempfile.path, "#{backup_path}/#{movie.dirname}.nzb") if backup_path
|
132
|
+
File.move(tempfile.path, "#{@download_path}/#{movie.dirname}.nzb")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pirate-autonzb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pirate
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-22 00:00:00 -07:00
|
13
13
|
default_executable: autonzb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: "0"
|
54
54
|
version:
|
55
|
-
description: Ruby tool to automatically download x264 HD nzb movies files from newzleech.com
|
55
|
+
description: Ruby tool to automatically download x264 HD nzb movies files from newzleech.com & nzbs.org
|
56
56
|
email: pirate.2061@gmail.com
|
57
57
|
executables:
|
58
58
|
- autonzb
|
@@ -63,8 +63,11 @@ extra_rdoc_files:
|
|
63
63
|
- lib/imdb.rb
|
64
64
|
- lib/inspector.rb
|
65
65
|
- lib/movie.rb
|
66
|
-
- lib/nfo.rb
|
67
|
-
- lib/nzb.rb
|
66
|
+
- lib/sites/newzleech/nfo.rb
|
67
|
+
- lib/sites/newzleech/nzb.rb
|
68
|
+
- lib/sites/nzbs/mechanize_hack.rb
|
69
|
+
- lib/sites/nzbs/nfo.rb
|
70
|
+
- lib/sites/nzbs/nzb.rb
|
68
71
|
- README.markdown
|
69
72
|
files:
|
70
73
|
- asset/failure.png
|
@@ -73,8 +76,11 @@ files:
|
|
73
76
|
- lib/imdb.rb
|
74
77
|
- lib/inspector.rb
|
75
78
|
- lib/movie.rb
|
76
|
-
- lib/nfo.rb
|
77
|
-
- lib/nzb.rb
|
79
|
+
- lib/sites/newzleech/nfo.rb
|
80
|
+
- lib/sites/newzleech/nzb.rb
|
81
|
+
- lib/sites/nzbs/mechanize_hack.rb
|
82
|
+
- lib/sites/nzbs/nfo.rb
|
83
|
+
- lib/sites/nzbs/nzb.rb
|
78
84
|
- Manifest
|
79
85
|
- Rakefile
|
80
86
|
- README.markdown
|
@@ -108,6 +114,6 @@ rubyforge_project: autonzb
|
|
108
114
|
rubygems_version: 1.2.0
|
109
115
|
signing_key:
|
110
116
|
specification_version: 2
|
111
|
-
summary: Ruby tool to automatically download x264 HD nzb movies files from newzleech.com
|
117
|
+
summary: Ruby tool to automatically download x264 HD nzb movies files from newzleech.com & nzbs.org
|
112
118
|
test_files: []
|
113
119
|
|
data/lib/nfo.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
|
3
|
-
class NFO
|
4
|
-
|
5
|
-
attr_accessor :srt, :imdb_link
|
6
|
-
|
7
|
-
def initialize(url)
|
8
|
-
@nfo = open(url.gsub(/\/$/,'')).read
|
9
|
-
@srt = []
|
10
|
-
|
11
|
-
parse_nfo
|
12
|
-
@srt.uniq!
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
# searching for subtitles languages info & imdb link
|
18
|
-
def parse_nfo
|
19
|
-
@nfo.split(/\n/).each do |line|
|
20
|
-
case line
|
21
|
-
when /subtitle|sub/i
|
22
|
-
@srt << 'fr' if line =~ /fr|fre|french/i
|
23
|
-
@srt << 'en' if line =~ /en|eng|english/i
|
24
|
-
# TODO add more language parsing here
|
25
|
-
@srt << 'none' if line =~ /none/i
|
26
|
-
when /imdb\.com\/title\//
|
27
|
-
@imdb_link = (matched = line.match(/imdb.com\/title\/(tt[0-9]+)/)) && "http://imdb.com/title/#{matched[1]}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
@srt << 'unknown' if @srt.empty?
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
data/lib/nzb.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
require 'hpricot'
|
3
|
-
require 'zip/zip'
|
4
|
-
|
5
|
-
require File.join(File.dirname(__FILE__), 'movie')
|
6
|
-
|
7
|
-
class NZB
|
8
|
-
|
9
|
-
URL = 'http://www.newzleech.com'
|
10
|
-
|
11
|
-
attr_accessor :movies, :agent
|
12
|
-
|
13
|
-
def initialize(inspector, download_path, options = {})
|
14
|
-
@inspector, @download_path = inspector, download_path.gsub(/\/$/,'')
|
15
|
-
@options = options
|
16
|
-
@options[:age] ||= 160
|
17
|
-
@options[:pages] ||= 2
|
18
|
-
|
19
|
-
@nzb_urls = []
|
20
|
-
@movies = []
|
21
|
-
|
22
|
-
(1..(@options[:pages].to_i)).each do |page|
|
23
|
-
@nzb_urls << "#{URL}?group=143&minage=&age=160&min=4000&max=max&q=&m=search&adv=1&offset=#{(page.to_i - 1) * 60}"
|
24
|
-
end
|
25
|
-
|
26
|
-
parse_newzleech
|
27
|
-
parse_movies
|
28
|
-
keep_only_best_nzb if @inspector.backup_path
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def parse_newzleech
|
34
|
-
$stdout.print "Parsing #{URL} for new x264 HD nzb movies, with age <= #{@options[:age]}, in last #{@options[:pages]} page(s)\n"
|
35
|
-
@nzb_urls.each do |url|
|
36
|
-
doc = Hpricot(open(url))
|
37
|
-
doc.search("table.contentt").each do |table|
|
38
|
-
raw_name = raw_name(table)
|
39
|
-
if nfo_link = nfo_link(table)
|
40
|
-
nfo = NFO.new(nfo_link)
|
41
|
-
imdb_link = nfo.imdb_link
|
42
|
-
else
|
43
|
-
imdb_link = imdb_link(table)
|
44
|
-
end
|
45
|
-
if raw_name && (imdb_link || (raw_name = find_clean_nzb_name(raw_name))) && raw_name.include?('x264')
|
46
|
-
age = parse_age(table.search("td.age").first.inner_html) # get age of the nzb
|
47
|
-
if age <= @options[:age].to_f
|
48
|
-
raw_name = clean_raw_name(raw_name)
|
49
|
-
movie = Movie.new(raw_name, :nfo => nfo, :imdb_link => imdb_link, :nzb_link => nzb_link(table), :age => age)
|
50
|
-
@movies << movie
|
51
|
-
|
52
|
-
$stdout.print '.'
|
53
|
-
$stdout.flush
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
$stdout.print "\n"
|
59
|
-
end
|
60
|
-
|
61
|
-
def clean_raw_name(raw_name)
|
62
|
-
(find_clean_nzb_name(raw_name) || raw_name).strip
|
63
|
-
end
|
64
|
-
|
65
|
-
def find_clean_nzb_name(raw_name)
|
66
|
-
if matched = raw_name.match(/^\[[0-9]*\]-\[.*\]-\[(.*)\]-/)
|
67
|
-
matched[1]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def raw_name(table)
|
72
|
-
(a = table.search("td.subject a[@href^='?p=']").first) && a.inner_html
|
73
|
-
end
|
74
|
-
|
75
|
-
def nfo_link(table)
|
76
|
-
(nfo = table.search("td.subject a[@href^='nfo.php?id=']").first) && "#{URL}/#{nfo[:href]}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def imdb_link(table)
|
80
|
-
(imdb = table.search("td.subject a[@href^='http://anonym.to/?http://www.imdb.com']").first) && imdb[:href].match(/\?(.*)/)[1]
|
81
|
-
end
|
82
|
-
|
83
|
-
def nzb_link(table)
|
84
|
-
(nzb = table.search("td.get a[@href^='?m=gen&dl=1']").first) && "#{URL}/#{nzb[:href]}"
|
85
|
-
end
|
86
|
-
|
87
|
-
def parse_movies
|
88
|
-
movies.each do |movie|
|
89
|
-
$stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age.to_i} day(s)\n"
|
90
|
-
if @inspector.need?(movie)
|
91
|
-
$stdout.print " => DOWNLOAD: #{movie.name} (#{movie.year})\n"
|
92
|
-
download_nzb(movie, @inspector.backup_path)
|
93
|
-
@inspector.movies << movie
|
94
|
-
end
|
95
|
-
end
|
96
|
-
$stdout.print "No nzb found, maybe change -age or -page setting\n" if @movies.empty?
|
97
|
-
end
|
98
|
-
|
99
|
-
def download_nzb(movie, backup_path = nil)
|
100
|
-
Tempfile.open("movie.nzb") do |tempfile|
|
101
|
-
tempfile.write(open(movie.nzb_link).read) # download the nzb
|
102
|
-
tempfile.close
|
103
|
-
File.copy(tempfile.path, "#{backup_path}/#{movie.dirname}.nzb") if backup_path
|
104
|
-
File.move(tempfile.path, "#{@download_path}/#{movie.dirname}.nzb")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def parse_age(string)
|
109
|
-
case string
|
110
|
-
when /h/i
|
111
|
-
string.to_f / 24
|
112
|
-
when /d/i
|
113
|
-
string.to_f
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def keep_only_best_nzb
|
118
|
-
size = 0
|
119
|
-
@inspector.nzbs.each do |nzb|
|
120
|
-
nzbs = @inspector.nzbs.select { |item| item.path != nzb.path }
|
121
|
-
unless @inspector.need?(nzb, true, nzbs, false)
|
122
|
-
File.delete(nzb.path)
|
123
|
-
size += 1
|
124
|
-
end
|
125
|
-
end
|
126
|
-
if size > 0
|
127
|
-
$stdout.print "#########################################################################\n"
|
128
|
-
$stdout.print "Deleted #{size} useless backuped nzb(s) (keep only the best nzb by movie)\n"
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|