pirate-autonzb 0.3.5 → 0.4

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.
Files changed (6) hide show
  1. data/Rakefile +1 -1
  2. data/autonzb.gemspec +2 -5
  3. data/lib/imdb.rb +13 -8
  4. data/lib/movie.rb +56 -17
  5. data/lib/nzb.rb +42 -12
  6. metadata +2 -11
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.5') do |p|
6
+ Echoe.new('autonzb', '0.4') 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,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{autonzb}
5
- s.version = "0.3.5"
5
+ s.version = "0.4"
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-01-02}
9
+ s.date = %q{2009-02-07}
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}
@@ -30,19 +30,16 @@ Gem::Specification.new do |s|
30
30
  s.add_runtime_dependency(%q<optiflag>, [">= 0"])
31
31
  s.add_runtime_dependency(%q<rubyzip>, [">= 0"])
32
32
  s.add_runtime_dependency(%q<htmlentities>, [">= 0"])
33
- s.add_development_dependency(%q<echoe>, [">= 0"])
34
33
  else
35
34
  s.add_dependency(%q<hpricot>, [">= 0"])
36
35
  s.add_dependency(%q<optiflag>, [">= 0"])
37
36
  s.add_dependency(%q<rubyzip>, [">= 0"])
38
37
  s.add_dependency(%q<htmlentities>, [">= 0"])
39
- s.add_dependency(%q<echoe>, [">= 0"])
40
38
  end
41
39
  else
42
40
  s.add_dependency(%q<hpricot>, [">= 0"])
43
41
  s.add_dependency(%q<optiflag>, [">= 0"])
44
42
  s.add_dependency(%q<rubyzip>, [">= 0"])
45
43
  s.add_dependency(%q<htmlentities>, [">= 0"])
46
- s.add_dependency(%q<echoe>, [">= 0"])
47
44
  end
48
45
  end
data/lib/imdb.rb CHANGED
@@ -5,12 +5,13 @@ require 'htmlentities'
5
5
 
6
6
  class IMDB
7
7
 
8
- attr_accessor :link
8
+ attr_accessor :link, :doc, :id
9
9
 
10
10
  def initialize(name, year = nil, link = nil)
11
11
  @name, @year, @link = name, year, link
12
12
  @coder = HTMLEntities.new
13
13
  set_doc
14
+ set_id
14
15
  end
15
16
 
16
17
  def score
@@ -29,32 +30,36 @@ class IMDB
29
30
  $KCODE = 'utf-8'
30
31
  @doc ? @coder.decode(@doc.search("title").inner_html.match(/(.*)\s\(/u)[1]) : @name
31
32
  end
32
-
33
+
33
34
  private
34
35
 
35
36
  def set_doc
36
- if link
37
- @doc = Hpricot(open(link.gsub(/\/\s*$/,'')))
37
+ if @link
38
+ @doc = Hpricot(open(@link.gsub(/\/\s*$/,'')))
38
39
  else
39
40
  query = "#{@name} (#{@year})"
40
41
  search_url = "http://www.imdb.com/find?q=#{CGI::escape(query)}"
41
42
  doc = Hpricot(open(search_url))
42
43
  case doc.search("title").inner_html
43
- when "IMDb Title Search" # search result page
44
+ when "IMDb Title Search", "IMDb Search" # search result page
44
45
  if !doc.search("b[text()*='Media from'] a").empty?
45
46
  imdb_id = doc.search("b[text()*='Media from'] a").first[:href]
46
47
  movie_url = "http://www.imdb.com#{imdb_id}"
47
48
  elsif !doc.search("td[@valign='top'] a[@href^='/title/tt']").empty?
48
49
  imdb_id = doc.search("td[@valign='top'] a[@href^='/title/tt']").first[:href]
49
50
  movie_url = "http://www.imdb.com#{imdb_id}"
51
+ else
52
+ movie_url = nil
50
53
  end
51
- @doc = Hpricot(open(movie_url))
52
- when "IMDb Search"
53
- @doc = nil
54
+ @doc = Hpricot(open(movie_url)) if movie_url
54
55
  else # direct in movie page
55
56
  @doc = doc
56
57
  end
57
58
  end
58
59
  end
60
+
61
+ def set_id
62
+ @id = doc.search("a[@href*='/title/tt']").first[:href].match(/tt[0-9]+/)[0] if doc
63
+ end
59
64
 
60
65
  end
data/lib/movie.rb CHANGED
@@ -5,15 +5,15 @@ class Movie
5
5
  include Comparable
6
6
 
7
7
  attr_accessor :path, :name, :format, :source, :sound, :encoding, :year, :srt, :lang, :score, :tags, :age,
8
- :imdb_link, :nfo_link, :nzb_link
8
+ :imdb_link, :imdb_id, :nzb_link, :nfo
9
9
 
10
10
  def initialize(raw_name, attributes = {})
11
11
  @raw_name = raw_name.gsub(/\.|\_/,' ')
12
- attributes.each { |k,v| send("#{k}=", v) }
12
+ attributes.each { |k,v| self.send("#{k}=", v) }
13
13
  @srt, @tags = [], []
14
14
 
15
- set_imdb_link
16
15
  set_name
16
+ set_year
17
17
  set_format
18
18
  set_source
19
19
  set_sound
@@ -21,7 +21,8 @@ class Movie
21
21
  set_lang
22
22
  set_encoding
23
23
  set_tags
24
- set_year
24
+ set_imdb_id
25
+ set_data_from_imdb unless path
25
26
  end
26
27
 
27
28
  def score
@@ -29,11 +30,15 @@ class Movie
29
30
  end
30
31
 
31
32
  def dirname
32
- "#{name} (#{year}) #{tags.join(' ')} #{format} #{source} #{sound} #{encoding} #{lang} [#{srt.join(',')}]".gsub(/\s+/,' ')
33
+ "#{name} (#{year}) #{tags.join(' ')} #{format} #{source} #{sound} #{encoding} #{lang} {#{imdb_id}} [#{srt.join(',')}]".gsub(/\s+/,' ')
33
34
  end
34
35
 
35
36
  def <=>(other_movie)
36
- "#{name} #{year}".downcase <=> "#{other_movie.name} #{other_movie.year}".downcase
37
+ if imdb_id && other_movie.imdb_id
38
+ imdb_id <=> other_movie.imdb_id
39
+ else
40
+ "#{name} #{year}".downcase <=> "#{other_movie.name} #{other_movie.year}".downcase
41
+ end
37
42
  end
38
43
 
39
44
  private
@@ -41,13 +46,21 @@ private
41
46
  def imdb
42
47
  @imdb ||= IMDB.new(name, year, imdb_link)
43
48
  end
44
-
45
- def nfo
46
- @nfo ||= NFO.new(nfo_link)
49
+
50
+ def imdb_link
51
+ @imdb_link || (imdb_id && "http://imdb.com/title/#{imdb_id}")
47
52
  end
48
53
 
49
- def set_imdb_link
50
- @imdb_link = nfo.imdb_link if imdb_link.nil? && nfo_link
54
+ def set_imdb_id
55
+ if imdb_link
56
+ @imdb_id = imdb_link.match(/tt[0-9]+/)[0]
57
+ elsif matched = @raw_name.match(/\{(.*)\}/)
58
+ @imdb_id = matched[1]
59
+ elsif path
60
+ add_imdb_id_to_file
61
+ else
62
+ nil
63
+ end
51
64
  end
52
65
 
53
66
  def set_name
@@ -65,12 +78,10 @@ private
65
78
  @name.gsub!(/REPACK|LIMITED|UNRATED|PROPER|REPOST|Directors\sCut/iu,'')
66
79
  @name.gsub!(/^\s+|\s+$/u,'')
67
80
  end
68
- @name = imdb.name unless path
69
81
  end
70
82
 
71
83
  def set_year
72
- @year = imdb.year unless path
73
- if (year.nil? || year == 0) && matched = @raw_name.match(/19[0-9]{2}|20[0-9]{2}/)
84
+ if matched = @raw_name.match(/19[0-9]{2}|20[0-9]{2}/)
74
85
  @year = matched[0].to_i
75
86
  end
76
87
  end
@@ -122,7 +133,7 @@ private
122
133
  end
123
134
 
124
135
  def set_srt
125
- if nfo_link
136
+ if nfo
126
137
  @srt = nfo.srt
127
138
  elsif matched = @raw_name.match(/\[(.*)\]/)
128
139
  matched[1].split(',').each { |srt| @srt << srt }
@@ -131,10 +142,14 @@ private
131
142
 
132
143
  def set_lang
133
144
  @lang = case @raw_name
134
- when /FRENCH/
145
+ when /FRENCH/i
135
146
  'FRENCH'
136
- when /GERMAN/
147
+ when /GERMAN/i
137
148
  'GERMAN'
149
+ when /DANISH/i
150
+ 'DANISH'
151
+ when /NORDIC/i
152
+ 'NORDIC'
138
153
  end
139
154
  end
140
155
 
@@ -148,4 +163,28 @@ private
148
163
  @tags << 'Directors Cut' if @raw_name =~ /Directors\sCut|DirCut/i
149
164
  end
150
165
 
166
+ def set_data_from_imdb
167
+ @name = imdb.name
168
+ imdb_year = imdb.year
169
+ if !imdb_year.nil? && imdb_year != 0
170
+ @year = imdb_year
171
+ end
172
+ end
173
+
174
+ def add_imdb_id_to_file_if_not_present
175
+ @imdb_id = imdb.id
176
+ dir_name = File.dirname(path)
177
+ ext_name = File.extname(path)
178
+ base_name = File.basename(path, ext_name)
179
+ if matched = base_name.match(/^(.*)\s(\[{1}.*\]{1})$/)
180
+ base_name_without_srts = matched[1]
181
+ srts = matched[2]
182
+ new_base_name = "#{base_name_without_srts} {#{imdb_id}} #{srts}#{ext_name}"
183
+ else
184
+ new_base_name = "#{base_name} {#{imdb_id}}#{ext_name}"
185
+ end
186
+ File.rename(path, "#{dir_name}/#{new_base_name}")
187
+ $stdout.print "Added {#{imdb_id}} (imdb id) => #{dir_name}/#{new_base_name}\n"
188
+ end
189
+
151
190
  end
data/lib/nzb.rb CHANGED
@@ -20,7 +20,7 @@ class NZB
20
20
  @movies = []
21
21
 
22
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}"
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
24
  end
25
25
 
26
26
  parse_newzleech
@@ -31,23 +31,27 @@ class NZB
31
31
  private
32
32
 
33
33
  def parse_newzleech
34
- $stdout.print "Parsing #{URL} for new x264 HD nzb movies in last #{@options[:pages]} page(s)\n"
34
+ $stdout.print "Parsing #{URL} for new x264 HD nzb movies, with age <= #{@options[:age]}, in last #{@options[:pages]} page(s)\n"
35
35
  @nzb_urls.each do |url|
36
36
  doc = Hpricot(open(url))
37
37
  doc.search("table.contentt").each do |table|
38
- if (a = table.search("td.subject a[@href^='posts/?p=']").first) && a.inner_html !=~ /^\<img/
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')
39
46
  age = parse_age(table.search("td.age").first.inner_html) # get age of the nzb
40
47
  if age <= @options[:age].to_f
41
- raw_name = a.inner_html
42
- nfo_link = (nfo = table.search("td.subject a[@href^='nfo.php?id=']").first) && "#{URL}/#{nfo[:href]}"
43
- imdb_link = (imdb = table.search("td.subject a[@href^='http://anonym.to/?http://www.imdb.com']").first) && imdb[:href].match(/\?(.*)/)[1]
44
- nzb_link = (nzb = table.search("td.get a[@href^='?m=gen&dl=1']").first) && "#{URL}/#{nzb[:href]}"
45
-
46
- movie = Movie.new(raw_name, :nfo_link => nfo_link, :imdb_link => imdb_link, :nzb_link => nzb_link, :age => age)
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)
47
50
  @movies << movie
48
-
49
- $stdout.print '.'
50
- $stdout.flush
51
+
52
+ $stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age.to_i} day(s)\n"
53
+ # $stdout.print '.'
54
+ # $stdout.flush
51
55
  end
52
56
  end
53
57
  end
@@ -55,6 +59,32 @@ private
55
59
  $stdout.print "\n"
56
60
  end
57
61
 
62
+ def clean_raw_name(raw_name)
63
+ (find_clean_nzb_name(raw_name) || raw_name).strip
64
+ end
65
+
66
+ def find_clean_nzb_name(raw_name)
67
+ if matched = raw_name.match(/^\[[0-9]*\]-\[.*\]-\[(.*)\]-/)
68
+ matched[1]
69
+ end
70
+ end
71
+
72
+ def raw_name(table)
73
+ (a = table.search("td.subject a[@href^='?p=']").first) && a.inner_html
74
+ end
75
+
76
+ def nfo_link(table)
77
+ (nfo = table.search("td.subject a[@href^='nfo.php?id=']").first) && "#{URL}/#{nfo[:href]}"
78
+ end
79
+
80
+ def imdb_link(table)
81
+ (imdb = table.search("td.subject a[@href^='http://anonym.to/?http://www.imdb.com']").first) && imdb[:href].match(/\?(.*)/)[1]
82
+ end
83
+
84
+ def nzb_link(table)
85
+ (nzb = table.search("td.get a[@href^='?m=gen&dl=1']").first) && "#{URL}/#{nzb[:href]}"
86
+ end
87
+
58
88
  def parse_movies
59
89
  movies.each do |movie|
60
90
  $stdout.print "#{movie.dirname}, imdb score: #{movie.score}, age: #{movie.age.to_i} day(s)\n"
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.5
4
+ version: "0.4"
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-01-02 00:00:00 -08:00
12
+ date: 2009-02-07 00:00:00 -08:00
13
13
  default_executable: autonzb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,15 +48,6 @@ dependencies:
48
48
  - !ruby/object:Gem::Version
49
49
  version: "0"
50
50
  version:
51
- - !ruby/object:Gem::Dependency
52
- name: echoe
53
- version_requirement:
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
59
- version:
60
51
  description: Ruby tool to automatically download x264 HD nzb movies files from newzleech.com
61
52
  email: pirate.2061@gmail.com
62
53
  executables: