pirate-autonzb 0.3 → 0.3.2

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  asset/failure.png
2
+ autonzb.gemspec
2
3
  bin/autonzb
3
4
  lib/imdb.rb
4
5
  lib/inspector.rb
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('autonzb', '0.3') do |p|
6
+ Echoe.new('autonzb', '0.3.2') do |p|
7
7
  p.description = "Ruby tool to automatically download x264 HD nzb movies files from newzleech.com"
8
8
  p.url = "http://github.com/pirate/autonzb"
9
9
  p.author = "Pirate"
data/autonzb.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{autonzb}
5
- s.version = "0.3"
5
+ s.version = "0.3.2"
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{2008-12-25}
9
+ s.date = %q{2008-12-26}
10
10
  s.default_executable = %q{autonzb}
11
11
  s.description = %q{Ruby tool to automatically download x264 HD nzb movies files from newzleech.com}
12
12
  s.email = %q{pirate.2061@gmail.com}
13
13
  s.executables = ["autonzb"]
14
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", "bin/autonzb", "lib/imdb.rb", "lib/inspector.rb", "lib/movie.rb", "lib/nfo.rb", "lib/nzb.rb", "Manifest", "Rakefile", "README.markdown", "autonzb.gemspec"]
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"]
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"]
data/bin/autonzb CHANGED
@@ -46,5 +46,6 @@ begin
46
46
 
47
47
  nzbmatrix = NZB.new(inspector, ARGV.flags.d, :age => ARGV.flags.age, :pages => ARGV.flags.pages)
48
48
  rescue => e
49
- Inspector.growl("AutoNZB Error!", e)
49
+ p e.to_s
50
+ Inspector.growl("AutoNZB Error!", 'look into the console log')
50
51
  end
data/lib/inspector.rb CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'movie')
2
2
 
3
3
  class Inspector
4
4
 
5
- attr_accessor :backup
5
+ attr_accessor :backup_path, :movies, :nzbs
6
6
 
7
7
  def initialize(paths, options = {})
8
8
  @paths = paths.split(',').map { |p| p.gsub(/\/$/,'') }
@@ -11,59 +11,61 @@ class Inspector
11
11
  @options[:imdb_score] = @options[:imdb_score] ? @options[:imdb_score].to_f : 7.0
12
12
  @options[:year] = @options[:year] ? @options[:year].to_i : 1950
13
13
 
14
- if @options[:backup]
15
- @backup = @options[:backup].gsub(/\/$/,'')
16
- @paths << @backup
17
- end
18
-
19
14
  @movies = []
20
15
  initialize_movies
21
16
 
17
+ if @options[:backup]
18
+ @backup_path = @options[:backup].gsub(/\/$/,'')
19
+ @nzbs = []
20
+ initialize_nzbs
21
+ @movies = @nzbs + @movies
22
+ end
23
+
22
24
  $stdout.print "Movie criteria: imdb score >= #{@options[:imdb_score]}, year >= #{@options[:year]} and srt [#{@options[:srt].join(',')}]\n"
23
25
  end
24
26
 
25
- def need?(movie)
26
- if valid?(movie)
27
- $stdout.print " => movie has required criteria "
28
- if m = @movies.detect { |m| m == movie }
29
- $stdout.print "but is already owned "
27
+ def need?(movie, not_validate = false, movies = @movies, log = true)
28
+ if not_validate || valid?(movie)
29
+ $stdout.print " => movie has required criteria " if log
30
+ if m = movies.detect { |m| m == movie }
31
+ $stdout.print "but is already owned " if log
30
32
  if srt_score(movie) > srt_score(m)
31
- $stdout.print "but new movie has better subtitle: [#{movie.srt.join(',')}]\n"
33
+ $stdout.print "but new movie has better subtitle: [#{movie.srt.join(',')}]\n" if log
32
34
  true
33
35
  elsif srt_score(movie) == srt_score(m)
34
36
  if format_score(movie) > format_score(m)
35
- $stdout.print "but new movie has better format: #{movie.format}\n"
37
+ $stdout.print "but new movie has better format: #{movie.format}\n" if log
36
38
  true
37
39
  elsif format_score(movie) == format_score(m)
38
40
  if source_score(movie) > source_score(m)
39
- $stdout.print "but new movie has better source: #{movie.source}\n"
41
+ $stdout.print "but new movie has better source: #{movie.source}\n" if log
40
42
  true
41
43
  elsif source_score(movie) == source_score(m)
42
44
  if sound_score(movie) > sound_score(m)
43
- $stdout.print "but new movie has better sound: #{movie.sound}\n"
45
+ $stdout.print "but new movie has better sound: #{movie.sound}\n" if log
44
46
  true
45
47
  else
46
- $stdout.print "with same srt, format, source and sound\n"
48
+ $stdout.print "with same srt, format, source and sound\n" if log
47
49
  false
48
50
  end
49
51
  else
50
- $stdout.print "with same srt, format and better source: #{m.source}\n"
52
+ $stdout.print "with same srt, format and better source: #{m.source}\n" if log
51
53
  false
52
54
  end
53
55
  else
54
- $stdout.print "with same srt and better format: #{m.format}\n"
56
+ $stdout.print "with same srt and better format: #{m.format}\n" if log
55
57
  false
56
58
  end
57
59
  else
58
- $stdout.print "with better subtitle: [#{m.srt.join(',')}]\n"
60
+ $stdout.print "with better subtitle: [#{m.srt.join(',')}]\n" if log
59
61
  false
60
62
  end
61
63
  else
62
- $stdout.print "and is not already owned\n"
64
+ $stdout.print "and is not already owned\n" if log
63
65
  true
64
66
  end
65
67
  else
66
- $stdout.print " => movie doesn't have required criteria\n"
68
+ $stdout.print " => movie doesn't have required criteria\n" if log
67
69
  false
68
70
  end
69
71
  end
@@ -80,14 +82,19 @@ private
80
82
  base_dir = clean_dir(Dir.new(path))
81
83
  base_dir.each do |movie|
82
84
  movie_path = "#{path}/#{movie}"
83
- @movies << Movie.new(movie) if File.directory?(movie_path) || File.extname(movie_path) == '.nzb'
84
- end
85
- if path == @backup
86
- $stdout.print "Found #{@movies.size - old_movies_size} backuped nzb(s) in #{path}\n"
87
- else
88
- $stdout.print "Found #{@movies.size - old_movies_size} movie(s) in #{path}\n"
85
+ @movies << Movie.new(movie, :path => movie_path) if File.directory?(movie_path)
89
86
  end
87
+ $stdout.print "Found #{@movies.size - old_movies_size} movie(s) in #{path}\n"
88
+ end
89
+ end
90
+
91
+ def initialize_nzbs
92
+ base_dir = clean_dir(Dir.new(@backup_path))
93
+ base_dir.each do |nzb|
94
+ nzb_path = "#{@backup_path}/#{nzb}"
95
+ @nzbs << Movie.new(nzb, :path => nzb_path) if File.extname(nzb_path) == '.nzb'
90
96
  end
97
+ $stdout.print "Found #{@nzbs.size} backuped nzb(s) in #{@backup_path}\n"
91
98
  end
92
99
 
93
100
  def clean_dir(dir)
data/lib/nzb.rb CHANGED
@@ -11,6 +11,7 @@ class NZB
11
11
  attr_accessor :movies, :agent
12
12
 
13
13
  def initialize(inspector, download_path, options = {})
14
+ @inspector, @download_path = inspector, download_path.gsub(/\/$/,'')
14
15
  @options = options
15
16
  @options[:age] ||= 160
16
17
  @options[:pages] ||= 2
@@ -23,24 +24,8 @@ class NZB
23
24
  end
24
25
 
25
26
  parse_newzleech
26
- movies.each do |movie|
27
- $stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age.to_i} day(s)\n"
28
- if inspector.need?(movie)
29
- $stdout.print " => DOWNLOAD: #{movie.name} (#{movie.year})\n"
30
- download_nzb(download_path, movie, inspector.backup)
31
- end
32
- end
33
- $stdout.print "No nzb found, maybe change -age or -page setting\n" if @movies.empty?
34
- end
35
-
36
- def download_nzb(download_path, movie, backup_path = nil)
37
- path = download_path.gsub(/\/$/,'') # removed / at the end
38
- Tempfile.open("movie.nzb") do |tempfile|
39
- tempfile.write(open(movie.nzb_link).read) # download the nzb
40
- tempfile.close
41
- File.move(tempfile.path, "#{path}/#{movie.dirname}.nzb")
42
- File.copy("#{path}/#{movie.dirname}.nzb", "#{backup_path}/#{movie.dirname}.nzb") if backup_path
43
- end
27
+ parse_movies
28
+ keep_only_best_nzb if @inspector.backup_path
44
29
  end
45
30
 
46
31
  private
@@ -70,6 +55,27 @@ private
70
55
  $stdout.print "\n"
71
56
  end
72
57
 
58
+ def parse_movies
59
+ movies.each do |movie|
60
+ $stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age.to_i} day(s)\n"
61
+ if @inspector.need?(movie)
62
+ $stdout.print " => DOWNLOAD: #{movie.name} (#{movie.year})\n"
63
+ download_nzb(movie, @inspector.backup_path)
64
+ @inspector.movies << movie
65
+ end
66
+ end
67
+ $stdout.print "No nzb found, maybe change -age or -page setting\n" if @movies.empty?
68
+ end
69
+
70
+ def download_nzb(movie, backup_path = nil)
71
+ Tempfile.open("movie.nzb") do |tempfile|
72
+ tempfile.write(open(movie.nzb_link).read) # download the nzb
73
+ tempfile.close
74
+ File.move(tempfile.path, "#{@download_path}/#{movie.dirname}.nzb")
75
+ File.copy("#{@download_path}/#{movie.dirname}.nzb", "#{backup_path}/#{movie.dirname}.nzb") if backup_path
76
+ end
77
+ end
78
+
73
79
  def parse_age(string)
74
80
  case string
75
81
  when /h/i
@@ -78,5 +84,20 @@ private
78
84
  string.to_f
79
85
  end
80
86
  end
87
+
88
+ def keep_only_best_nzb
89
+ size = 0
90
+ @inspector.nzbs.each do |nzb|
91
+ nzbs = @inspector.nzbs.select { |item| item.path != nzb.path }
92
+ unless @inspector.need?(nzb, true, nzbs, false)
93
+ File.delete(nzb.path)
94
+ size += 1
95
+ end
96
+ end
97
+ if size > 0
98
+ $stdout.print "#########################################################################\n"
99
+ $stdout.print "Deleted #{size} useless backuped nzb(s) (keep only the best nzb by movie)\n"
100
+ end
101
+ end
81
102
 
82
103
  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.3"
4
+ version: 0.3.2
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: 2008-12-25 00:00:00 -08:00
12
+ date: 2008-12-26 00:00:00 -08:00
13
13
  default_executable: autonzb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -73,6 +73,7 @@ extra_rdoc_files:
73
73
  - README.markdown
74
74
  files:
75
75
  - asset/failure.png
76
+ - autonzb.gemspec
76
77
  - bin/autonzb
77
78
  - lib/imdb.rb
78
79
  - lib/inspector.rb
@@ -82,7 +83,6 @@ files:
82
83
  - Manifest
83
84
  - Rakefile
84
85
  - README.markdown
85
- - autonzb.gemspec
86
86
  has_rdoc: true
87
87
  homepage: http://github.com/pirate/autonzb
88
88
  post_install_message: