pirate-autonzb 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('autonzb', '0.2.2') do |p|
6
+ Echoe.new('autonzb', '0.2.3') 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,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{autonzb}
5
- s.version = "0.2.2"
5
+ s.version = "0.2.3"
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"]
data/bin/autonzb CHANGED
@@ -12,10 +12,9 @@ module AutoNZB extend OptiFlagSet
12
12
  description "Directories paths (separated by ,) with all your Movie's folders"
13
13
  end
14
14
  optional_flag 'srt' do
15
- description "Subtitle's language wanted (separated by ,), ie 'fr,en'.
16
- Use 'none' if you want download movies without subtitle too.
15
+ description "Subtitle languages desired (separated by ,), ie 'fr,en'.
16
+ Add 'none' at the end if you want to download movies without subtitles too.
17
17
  (Order is important to define if a nzb is needed), default: none"
18
- value_in_set ['fr', 'en', 'none']
19
18
  end
20
19
  optional_flag 'imdb' do
21
20
  description "IMDB score limit, default: 7.0"
@@ -28,9 +27,12 @@ module AutoNZB extend OptiFlagSet
28
27
  description "Age limit, in day, of nbz file on newzleech, default: 160"
29
28
  value_matches ["age must be a number", /[0-9]+/]
30
29
  end
31
- optional_flag "page" do
32
- description "number of the page on newzleech, default: 1. Think to augment -a when change page number"
33
- value_matches ["page must be a number", /[0-9]+/]
30
+ optional_flag "pages" do
31
+ description "number page(s) parsed on newzleech, default: 2. Think to augment -a when change number of pages"
32
+ value_matches ["pages must be a number", /[0-9]+/]
33
+ end
34
+ optional_flag "backup" do
35
+ description "Backup folder path (to save a copy of all downloaded nzb files and prevent an already downloaded nzb to be re-downloaded)"
34
36
  end
35
37
 
36
38
  and_process!
@@ -38,6 +40,7 @@ end
38
40
 
39
41
  inspector = Inspector.new(ARGV.flags.movies || '', :year => ARGV.flags.year,
40
42
  :imdb_score => ARGV.flags.imdb,
41
- :srt => ARGV.flags.srt)
43
+ :srt => ARGV.flags.srt,
44
+ :backup => ARGV.flags.backup)
42
45
 
43
- nzbmatrix = NZB.new(inspector, ARGV.flags.d, :age => ARGV.flags.age, :page => ARGV.flags.page)
46
+ nzbmatrix = NZB.new(inspector, ARGV.flags.d, :age => ARGV.flags.age, :pages => ARGV.flags.pages)
data/lib/imdb.rb CHANGED
@@ -34,7 +34,7 @@ private
34
34
 
35
35
  def set_doc
36
36
  if link
37
- @doc = Hpricot(open(link))
37
+ @doc = Hpricot(open(link.gsub(/\/$/,'')))
38
38
  else
39
39
  query = "#{@name} (#{@year})"
40
40
  search_url = "http://www.imdb.com/find?q=#{CGI::escape(query)}"
data/lib/inspector.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), 'movie')
2
2
 
3
3
  class Inspector
4
-
4
+
5
+ attr_accessor :backup
6
+
5
7
  def initialize(paths, options = {})
6
8
  @paths = paths.split(',').map { |p| p.gsub!(/\/$/,'') }
7
9
  @options = options
@@ -9,10 +11,15 @@ class Inspector
9
11
  @options[:imdb_score] = @options[:imdb_score] ? @options[:imdb_score].to_f : 7.0
10
12
  @options[:year] = @options[:year] ? @options[:year].to_i : 1950
11
13
 
14
+ if @options[:backup]
15
+ @backup = @options[:backup].gsub(/\/$/,'')
16
+ @paths << @backup
17
+ end
18
+
12
19
  @movies = []
13
20
  initialize_movies
14
21
 
15
- $stdout.print "Movie criteria: imdb_score >= #{@options[:imdb_score]}, year >= #{@options[:year]} and srt [#{@options[:srt].join(',')}]\n"
22
+ $stdout.print "Movie criteria: imdb score >= #{@options[:imdb_score]}, year >= #{@options[:year]} and srt [#{@options[:srt].join(',')}]\n"
16
23
  end
17
24
 
18
25
  def need?(movie)
@@ -28,11 +35,19 @@ class Inspector
28
35
  $stdout.print "but new movie has better format: #{movie.format}\n"
29
36
  true
30
37
  elsif format_score(movie) == format_score(m)
31
- if sound_score(movie) > sound_score(m)
32
- $stdout.print "but new movie has better sound: #{movie.sound}\n"
38
+ if source_score(movie) > source_score(m)
39
+ $stdout.print "but new movie has better source: #{movie.source}\n"
33
40
  true
41
+ elsif source_score(movie) == source_score(m)
42
+ if sound_score(movie) > sound_score(m)
43
+ $stdout.print "but new movie has better sound: #{movie.sound}\n"
44
+ true
45
+ else
46
+ $stdout.print "with same srt, format, source and sound\n"
47
+ false
48
+ end
34
49
  else
35
- $stdout.print "with same srt, format and sound\n"
50
+ $stdout.print "with same srt, format and better source: #{m.source}\n"
36
51
  false
37
52
  end
38
53
  else
@@ -62,9 +77,13 @@ private
62
77
  base_dir = clean_dir(Dir.new(path))
63
78
  base_dir.each do |movie|
64
79
  movie_path = "#{path}/#{movie}"
65
- @movies << Movie.new(movie) if File.directory?(movie_path)
80
+ @movies << Movie.new(movie) if File.directory?(movie_path) || File.extname(movie_path) == '.nzb'
81
+ end
82
+ if path == @backup
83
+ $stdout.print "Found #{@movies.size - old_movies_size} backuped nzb(s) in #{path}\n"
84
+ else
85
+ $stdout.print "Found #{@movies.size - old_movies_size} movie(s) in #{path}\n"
66
86
  end
67
- $stdout.print "Inspected #{@movies.size - old_movies_size} movie(s) in #{path}\n"
68
87
  end
69
88
  end
70
89
 
@@ -95,6 +114,16 @@ private
95
114
  end
96
115
  end
97
116
 
117
+ def source_score(movie)
118
+ case movie.format
119
+ when 'BluRay'; 4
120
+ when 'HDDVD'; 3
121
+ when 'HDTV'; 2
122
+ when 'DVD'; 1
123
+ else; 0
124
+ end
125
+ end
126
+
98
127
  def sound_score(movie)
99
128
  movie.format == 'DTS' ? 1 : 0
100
129
  end
data/lib/nfo.rb CHANGED
@@ -5,7 +5,7 @@ class NFO
5
5
  attr_accessor :srt, :imdb_link
6
6
 
7
7
  def initialize(url)
8
- @nfo = open(url).read
8
+ @nfo = open(url.gsub(/\/$/,'')).read
9
9
  @srt = []
10
10
 
11
11
  parse_nfo
data/lib/nzb.rb CHANGED
@@ -13,50 +13,57 @@ class NZB
13
13
  def initialize(inspector, download_path, options = {})
14
14
  @options = options
15
15
  @options[:age] ||= 160
16
- @options[:page] ||= 1
16
+ @options[:pages] ||= 2
17
17
 
18
- @nzb_url = "#{URL}/?group=143&minage=&age=160&min=4000&max=max&q=&m=search&adv=1&offset=#{(@options[:page].to_i - 1) * 60}"
18
+ @nzb_urls = []
19
19
  @movies = []
20
20
 
21
+ (1..(@options[:pages].to_i)).each do |page|
22
+ @nzb_urls << "#{URL}/?group=143&minage=&age=160&min=4000&max=max&q=&m=search&adv=1&offset=#{(page.to_i - 1) * 60}"
23
+ end
24
+
21
25
  parse_newzleech
22
26
  movies.each do |movie|
23
- $stdout.print "#{movie.dirname}, imdb score: #{movie.score} age: #{movie.age.to_i} day(s)\n"
27
+ $stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age.to_i} day(s)\n"
24
28
  if inspector.need?(movie)
25
29
  $stdout.print " => DOWNLOAD: #{movie.name} (#{movie.year})\n"
26
- download_nzb(download_path, movie)
30
+ download_nzb(download_path, movie, inspector.backup)
27
31
  end
28
32
  end
29
33
  $stdout.print "No nzb found, maybe change -age or -page setting\n" if @movies.empty?
30
34
  end
31
35
 
32
- def download_nzb(download_path, movie)
36
+ def download_nzb(download_path, movie, backup_path = nil)
33
37
  path = download_path.gsub(/\/$/,'') # removed / at the end
34
38
  Tempfile.open("movie.nzb") do |tempfile|
35
39
  tempfile.write(open(movie.nzb_link).read) # download the nzb
36
40
  tempfile.close
37
41
  File.move(tempfile.path, "#{path}/#{movie.dirname}.nzb")
42
+ File.copy("#{path}/#{movie.dirname}.nzb", "#{backup_path}/#{movie.dirname}.nzb") if backup_path
38
43
  end
39
44
  end
40
45
 
41
46
  private
42
47
 
43
48
  def parse_newzleech
44
- $stdout.print "Parsing #{URL} for new x264 HD nzb movies\n"
45
- doc = Hpricot(open(@nzb_url))
46
- doc.search("table.contentt").each do |table|
47
- if (a = table.search("td.subject a[@href^='posts/?p=']").first) && a.inner_html !=~ /^\<img/
48
- age = parse_age(table.search("td.age").first.inner_html) # get age of the nzb
49
- if age <= @options[:age].to_f
50
- raw_name = a.inner_html
51
- nfo_link = (nfo = table.search("td.subject a[@href^='nfo.php?id=']").first) && "#{URL}/#{nfo[:href]}"
52
- imdb_link = (imdb = table.search("td.subject a[@href^='http://anonym.to/?http://www.imdb.com']").first) && imdb[:href].match(/\?(.*)/)[1]
53
- nzb_link = (nzb = table.search("td.get a[@href^='?m=gen&dl=1']").first) && "#{URL}/#{nzb[:href]}"
49
+ $stdout.print "Parsing #{URL} for new x264 HD nzb movies in last #{@options[:pages]} page(s)\n"
50
+ @nzb_urls.each do |url|
51
+ doc = Hpricot(open(url))
52
+ doc.search("table.contentt").each do |table|
53
+ if (a = table.search("td.subject a[@href^='posts/?p=']").first) && a.inner_html !=~ /^\<img/
54
+ age = parse_age(table.search("td.age").first.inner_html) # get age of the nzb
55
+ if age <= @options[:age].to_f
56
+ raw_name = a.inner_html
57
+ nfo_link = (nfo = table.search("td.subject a[@href^='nfo.php?id=']").first) && "#{URL}/#{nfo[:href]}"
58
+ imdb_link = (imdb = table.search("td.subject a[@href^='http://anonym.to/?http://www.imdb.com']").first) && imdb[:href].match(/\?(.*)/)[1]
59
+ nzb_link = (nzb = table.search("td.get a[@href^='?m=gen&dl=1']").first) && "#{URL}/#{nzb[:href]}"
54
60
 
55
- movie = Movie.new(raw_name, :nfo_link => nfo_link, :imdb_link => imdb_link, :nzb_link => nzb_link, :age => age)
56
- @movies << movie
61
+ movie = Movie.new(raw_name, :nfo_link => nfo_link, :imdb_link => imdb_link, :nzb_link => nzb_link, :age => age)
62
+ @movies << movie
57
63
 
58
- $stdout.print '.'
59
- $stdout.flush
64
+ $stdout.print '.'
65
+ $stdout.flush
66
+ end
60
67
  end
61
68
  end
62
69
  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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pirate