Class: Inspector
- Inherits:
-
Object
- Object
- Inspector
- Defined in:
- lib/inspector.rb
Instance Attribute Summary collapse
-
#backup_path ⇒ Object
Returns the value of attribute backup_path.
-
#download_path ⇒ Object
Returns the value of attribute download_path.
-
#movies ⇒ Object
Returns the value of attribute movies.
-
#nzbs ⇒ Object
Returns the value of attribute nzbs.
Class Method Summary collapse
Instance Method Summary collapse
- #download(site, movie) ⇒ Object
-
#initialize(download_path, options = {}) ⇒ Inspector
constructor
A new instance of Inspector.
- #need?(movie, movies = @movies, not_validate = false, log = true) ⇒ Boolean
- #parse_nzbs(site) ⇒ Object
- #search_and_download ⇒ Object
Constructor Details
#initialize(download_path, options = {}) ⇒ Inspector
Returns a new instance of Inspector.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/inspector.rb', line 9 def initialize(download_path, = {}) @download_path = download_path.gsub(/\/$/,'') @paths = [:movie_paths] ? [:movie_paths].split(',').map { |p| p.gsub(/\/$/,'') } : [] @options = @options[:srt] = @options[:srt] ? (@options[:srt].split(',') - ["unknown"] + ['unknown']).uniq : nil @options[:imdb_score] = @options[:imdb_score] ? @options[:imdb_score].to_f : 7.0 @options[:year] = @options[:year] ? @options[:year].to_i : 1950 @movies = [] initialize_movies if @options[:backup_path] @backup_path = @options[:backup_path].gsub(/\/$/,'') @nzbs = [] initialize_nzbs @movies = @nzbs + @movies load_age_from_yaml end $stdout.print "Movie criteria: imdb score >= #{@options[:imdb_score]}, year >= #{@options[:year]}#{" and srt [#{@options[:srt].join(',')}]" if @options[:srt]}\n" end |
Instance Attribute Details
#backup_path ⇒ Object
Returns the value of attribute backup_path.
7 8 9 |
# File 'lib/inspector.rb', line 7 def backup_path @backup_path end |
#download_path ⇒ Object
Returns the value of attribute download_path.
7 8 9 |
# File 'lib/inspector.rb', line 7 def download_path @download_path end |
#movies ⇒ Object
Returns the value of attribute movies.
7 8 9 |
# File 'lib/inspector.rb', line 7 def movies @movies end |
#nzbs ⇒ Object
Returns the value of attribute nzbs.
7 8 9 |
# File 'lib/inspector.rb', line 7 def nzbs @nzbs end |
Class Method Details
.growl(title, msg, pri = 0) ⇒ Object
112 113 114 |
# File 'lib/inspector.rb', line 112 def self.growl(title, msg, pri = 0) system("/usr/local/bin/growlnotify -w -n autonzb --image #{File.dirname(__FILE__) + "/../asset/failure.png"} -p #{pri} -m #{msg.inspect} #{title} &") end |
Instance Method Details
#download(site, movie) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/inspector.rb', line 56 def download(site, movie) Tempfile.open("movie.nzb") do |tempfile| tempfile.write(site.download(movie)) # download nzb tempfile.close File.copy(tempfile.path, "#{backup_path}/#{movie.dirname}.nzb") if backup_path File.move(tempfile.path, "#{download_path}/#{movie.dirname}.nzb") end @movies << movie end |
#need?(movie, movies = @movies, not_validate = false, log = true) ⇒ Boolean
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/inspector.rb', line 66 def need?(movie, movies = @movies, not_validate = false, log = true) if not_validate || valid?(movie) $stdout.print " => movie has required criteria " if log if m = movies.detect { |m| m == movie } $stdout.print "but is already owned " if log if srt_score(movie) > srt_score(m) $stdout.print "but new movie has better subtitle: [#{movie.srt.join(',')}]\n" if log true elsif srt_score(movie) == srt_score(m) if format_score(movie) > format_score(m) $stdout.print "but new movie has better format: #{movie.format}\n" if log true elsif format_score(movie) == format_score(m) if source_score(movie) > source_score(m) $stdout.print "but new movie has better source: #{movie.source}\n" if log true elsif source_score(movie) == source_score(m) if sound_score(movie) > sound_score(m) $stdout.print "but new movie has better sound: #{movie.sound}\n" if log true else $stdout.print "with same srt, format, source and sound\n" if log false end else $stdout.print "with same srt, format and better source: #{m.source}\n" if log false end else $stdout.print "with same srt and better format: #{m.format}\n" if log false end else $stdout.print "with better subtitle: [#{m.srt.join(',')}]\n" if log false end else $stdout.print "and is not already owned\n" if log true end else $stdout.print " => movie doesn't have required criteria\n" if log false end end |
#parse_nzbs(site) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/inspector.rb', line 45 def parse_nzbs(site) site.nzbs.each do |movie| $stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age} day(s)\n" if need?(movie) $stdout.print " => DOWNLOAD: #{movie.name} (#{movie.year})\n" download(site, movie) end end $stdout.print "No nzb found, maybe change -age or -page setting\n" if site.nzbs.empty? end |
#search_and_download ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inspector.rb', line 31 def search_and_download if @options[:login] && @options[:pass] site = Nzbs::NZB.new(@options) parse_nzbs(site) end site = Newzleech::NZB.new(@options) parse_nzbs(site) if backup_path keep_only_best_nzbs set_age_on_yaml end end |