royw-imdb 0.0.8 → 0.0.9
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/README +8 -3
- data/lib/imdb/imdb_movie.rb +17 -8
- data/lib/imdb/imdb_search.rb +19 -20
- metadata +2 -2
data/README
CHANGED
@@ -59,7 +59,12 @@ ImdbSearch searches that match on AKA title movies
|
|
59
59
|
|
60
60
|
ImdbSearch searches that match on AKA title but without search_aka enabled movies
|
61
61
|
- should have multiple movies
|
62
|
-
- should have
|
62
|
+
- should have no movies from 1998 because title is an aka
|
63
|
+
|
64
|
+
ImdbSearch searches that match on AKA title "Open Season" movies
|
65
|
+
- should have multiple movies
|
66
|
+
- should find id tt0400717
|
67
|
+
- should have only one movie from 2006
|
63
68
|
|
64
69
|
ImdbMovie Indiana Jones and the Last Crusade
|
65
70
|
- should query IMDB url
|
@@ -72,6 +77,6 @@ String unescape_html
|
|
72
77
|
String strip_tags
|
73
78
|
- should strip HTML tags
|
74
79
|
|
75
|
-
Finished in
|
80
|
+
Finished in 19.495014 seconds
|
76
81
|
|
77
|
-
|
82
|
+
56 examples, 0 failures
|
data/lib/imdb/imdb_movie.rb
CHANGED
@@ -5,8 +5,8 @@ class ImdbMovie
|
|
5
5
|
|
6
6
|
def initialize(id, title = nil)
|
7
7
|
@id = id
|
8
|
-
|
9
|
-
|
8
|
+
@url = "http://www.imdb.com/title/tt#{@id}/"
|
9
|
+
# @url = sprintf(ImdbMovie::url_format, @id.to_s)
|
10
10
|
@title = title
|
11
11
|
end
|
12
12
|
|
@@ -14,9 +14,9 @@ class ImdbMovie
|
|
14
14
|
# should return the path to the cached html file
|
15
15
|
# Note, the returned String should have one '%s'
|
16
16
|
# which will replaced by sprintf with @id.to_s
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
# def self.url_format
|
18
|
+
# 'http://www.imdb.com/title/tt%s/'
|
19
|
+
# end
|
20
20
|
|
21
21
|
# this is intended to be stubed by rspec where it
|
22
22
|
# should return true.
|
@@ -192,9 +192,18 @@ class ImdbMovie
|
|
192
192
|
def document
|
193
193
|
attempts = 0
|
194
194
|
begin
|
195
|
-
|
195
|
+
if ImdbMovie::use_html_cache
|
196
|
+
begin
|
197
|
+
filespec = self.url.gsub(/^http:\//, 'spec/samples').gsub(/\/$/, '.html')
|
198
|
+
html = open(filespec).read
|
199
|
+
rescue Exception
|
200
|
+
html = open(self.url).read
|
201
|
+
cache_html_files(html)
|
202
|
+
end
|
203
|
+
else
|
204
|
+
html = open(self.url).read
|
205
|
+
end
|
196
206
|
@document ||= Hpricot(html)
|
197
|
-
cache_html_files(html) if ImdbMovie::use_html_cache
|
198
207
|
rescue Exception => e
|
199
208
|
attempts += 1
|
200
209
|
if attempts > MAX_ATTEMPTS
|
@@ -212,7 +221,7 @@ class ImdbMovie
|
|
212
221
|
begin
|
213
222
|
filespec = self.url.gsub(/^http:\//, 'spec/samples').gsub(/\/$/, '.html')
|
214
223
|
unless File.exist?(filespec)
|
215
|
-
puts filespec
|
224
|
+
puts "caching #{filespec}"
|
216
225
|
File.mkdirs(File.dirname(filespec))
|
217
226
|
File.open(filespec, 'w') { |f| f.puts html }
|
218
227
|
end
|
data/lib/imdb/imdb_search.rb
CHANGED
@@ -17,22 +17,17 @@ class ImdbSearch
|
|
17
17
|
# and the release year.
|
18
18
|
def find_id(options={})
|
19
19
|
id = nil
|
20
|
-
found_movies = self.movies
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
result = imdb_compare_titles(m.title, aka, @query) && !m.video_game? && !m.release_year.nil?
|
25
|
-
if result
|
26
|
-
unless options[:years].nil?
|
27
|
-
result = options[:years].include?(m.release_year.to_i)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
result
|
31
|
-
end
|
32
|
-
ids = desired_movies.collect{|m| m.id}.uniq.compact
|
33
|
-
if ids.length == 1
|
34
|
-
id = "tt#{ids[0]}"
|
20
|
+
found_movies = self.movies.select do |m|
|
21
|
+
result = true
|
22
|
+
unless options[:years].nil?
|
23
|
+
result = options[:years].include?(m.release_year.to_i)
|
35
24
|
end
|
25
|
+
result
|
26
|
+
end
|
27
|
+
# p found_movies.collect{|m| [m.id, m.title, m.year]}
|
28
|
+
ids = found_movies.collect{|m| m.id}.uniq.compact
|
29
|
+
if ids.length == 1
|
30
|
+
id = "tt#{ids[0]}"
|
36
31
|
end
|
37
32
|
id
|
38
33
|
end
|
@@ -93,14 +88,18 @@ class ImdbSearch
|
|
93
88
|
|
94
89
|
films = ids_and_titles.map do |id_and_title|
|
95
90
|
ImdbMovie.new(id_and_title[0], id_and_title[1])
|
96
|
-
end.uniq
|
91
|
+
end.uniq.compact
|
97
92
|
|
98
|
-
if films.length > 1
|
99
|
-
|
100
|
-
aka = m.also_known_as
|
101
|
-
imdb_compare_titles(m.title, aka, @query)
|
93
|
+
if films.length > 1
|
94
|
+
same_title_films = films.select do |m|
|
95
|
+
aka = (@search_akas ? m.also_known_as : [])
|
96
|
+
!m.video_game? && imdb_compare_titles(m.title, aka, @query)
|
97
|
+
end
|
98
|
+
if same_title_films.size > 0
|
99
|
+
films = same_title_films
|
102
100
|
end
|
103
101
|
end
|
102
|
+
|
104
103
|
films
|
105
104
|
end
|
106
105
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: royw-imdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Gil
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|