royw-imdb 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION.yml +1 -1
- data/spec/imdb_movie_spec.rb +0 -14
- data/spec/imdb_profile_spec.rb +162 -156
- data/spec/imdb_search_spec.rb +15 -39
- metadata +2 -4
- data/spec/string_extensions_spec.rb +0 -25
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
data/spec/imdb_movie_spec.rb
CHANGED
@@ -10,7 +10,6 @@ describe ImdbMovie do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should query IMDB url" do
|
13
|
-
# @imdb_movie.should_receive(:open).with("http://www.imdb.com/title/tt0050562/").and_return(open("#{$samples_dir}/sample_jet_pilot.html"))
|
14
13
|
@imdb_movie.should_receive(:fetch).with("http://www.imdb.com/title/tt0050562/").and_return(open("#{$samples_dir}/www.imdb.com/title/tt0050562.html"))
|
15
14
|
@imdb_movie.send(:document)
|
16
15
|
end
|
@@ -31,14 +30,8 @@ describe ImdbMovie do
|
|
31
30
|
|
32
31
|
before(:each) do
|
33
32
|
@imdb_movie = ImdbMovie.new('0097576')
|
34
|
-
# @imdb_movie.stub!(:open).and_return(open("#{$samples_dir}/sample_movie.html"))
|
35
33
|
end
|
36
34
|
|
37
|
-
# it "should query IMDB url" do
|
38
|
-
# @imdb_movie.should_receive(:open).with("http://www.imdb.com/title/tt0097576/").and_return(open("#{$samples_dir}/www.imdb.com/title/tt0097576.html"))
|
39
|
-
# @imdb_movie.send(:document)
|
40
|
-
# end
|
41
|
-
|
42
35
|
it "should get the title" do
|
43
36
|
@imdb_movie.title.should == "Indiana Jones and the Last Crusade"
|
44
37
|
end
|
@@ -157,15 +150,8 @@ describe ImdbMovie do
|
|
157
150
|
|
158
151
|
before(:each) do
|
159
152
|
@imdb_movie = ImdbMovie.new('0054961')
|
160
|
-
# @imdb_movie.stub!(:open).and_return(open("#{$samples_dir}/sample_incomplete_movie.html"))
|
161
153
|
end
|
162
154
|
|
163
|
-
# it "should query IMDB url" do
|
164
|
-
# @imdb_movie.should_receive(:open).with("http://www.imdb.com/title/tt0054961/").and_return(open("#{$samples_dir}/sample_incomplete_movie.html"))
|
165
|
-
# @imdb_movie.should_receive(:open).with("http://www.imdb.com/title/tt0054961/").and_return(open("#{$samples_dir}/www.imdb.com/title/tt0054961.html"))
|
166
|
-
# @imdb_movie.send(:document)
|
167
|
-
# end
|
168
|
-
|
169
155
|
it "should get the title" do
|
170
156
|
@imdb_movie.title.should == "Han robado una estrella"
|
171
157
|
end
|
data/spec/imdb_profile_spec.rb
CHANGED
@@ -17,205 +17,211 @@ describe "ImdbProfile" do
|
|
17
17
|
Dir.glob(File.join(TMPDIR, "imdb_profile_spec*")).each { |filename| File.delete(filename) }
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
describe "Simple finds using ImdbProfile.first" do
|
21
|
+
it "should find by imdb_id that is prefixed with a 'tt'" do
|
22
|
+
profile = ImdbProfile.first(:imdb_id => 'tt0465234')
|
23
|
+
profile.should_not == nil
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
it "should find by imdb_id that is not prefixed with 'tt'" do
|
27
|
+
profile = ImdbProfile.first(:imdb_id => '0465234')
|
28
|
+
profile.should_not == nil
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
it "should find by single title" do
|
32
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'])
|
33
|
+
profile.should_not == nil
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
it "should find by multiple title" do
|
37
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets', 'National Treasure 2'])
|
38
|
+
profile.should_not == nil
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
it "should find by multiple title embedded in arrays" do
|
42
|
+
profile = ImdbProfile.first(:titles => [['National Treasure: Book of Secrets'], 'National Treasure 2'])
|
43
|
+
profile.should_not == nil
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
it "should find by AKA title" do
|
47
|
+
profile = ImdbProfile.first(:titles => ['National Treasure 2'])
|
48
|
+
profile.should_not == nil
|
49
|
+
end
|
48
50
|
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
describe "multiple finds using ImdbProfile.all" do
|
53
|
+
# We use two versions of "The Alamo" to test for year discrimination
|
54
|
+
# John Wayne's The Alamo produced and released in 1960, IMDB ID => tt0053580
|
55
|
+
# John Lee Hancock's The Alamo produced and released in 2004, IMDB ID => tt0318974
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
# test all()
|
58
|
+
it "should find multiple versions of The Alamo" do
|
59
|
+
profiles = ImdbProfile.all(:titles => ['The Alamo'])
|
60
|
+
profiles.length.should > 1
|
61
|
+
end
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
it "should find the two versions of The Alamo that we are interested in" do
|
64
|
+
profiles = ImdbProfile.all(:titles => ['The Alamo'])
|
65
|
+
imdb_ids = profiles.collect{|profile| profile.imdb_id}
|
66
|
+
imdb_ids = imdb_ids.select{|ident| ident == 'tt0053580' || ident == 'tt0318974'}
|
67
|
+
imdb_ids.uniq.compact.length.should == 2
|
68
|
+
end
|
65
69
|
end
|
66
70
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
71
|
+
describe "find first using title and media year" do
|
72
|
+
it "should find John Wayne's The Alamo by title with media year" do
|
73
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :media_years => [1960])
|
74
|
+
profile.imdb_id.should == 'tt0053580'
|
75
|
+
end
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
+
it "should find John Lee Hancock's The Alamo by title with media year" do
|
78
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :media_years => [2004])
|
79
|
+
profile.imdb_id.should == 'tt0318974'
|
80
|
+
end
|
77
81
|
end
|
78
82
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
83
|
+
describe "find first using title and production year" do
|
84
|
+
it "should find John Wayne's The Alamo by title with production year" do
|
85
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :production_years => [1960])
|
86
|
+
profile.imdb_id.should == 'tt0053580'
|
87
|
+
end
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
+
it "should find John Lee Hancock's The Alamo by title with production year" do
|
90
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :production_years => [2004])
|
91
|
+
profile.imdb_id.should == 'tt0318974'
|
92
|
+
end
|
89
93
|
end
|
90
94
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
95
|
+
describe "find first using title and released year" do
|
96
|
+
it "should find John Wayne's The Alamo by title with released year" do
|
97
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1960])
|
98
|
+
profile.imdb_id.should == 'tt0053580'
|
99
|
+
end
|
97
100
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
+
it "should find John Lee Hancock's The Alamo by title with released year" do
|
102
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [2004])
|
103
|
+
profile.imdb_id.should == 'tt0318974'
|
104
|
+
end
|
101
105
|
end
|
102
106
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
107
|
+
describe "fuzzy year matching (plus or minus a year)" do
|
108
|
+
# fuzzy years are only supported for production and released years, not media years
|
109
|
+
it "should not find John Wayne's The Alamo by title with the media year off by a year" do
|
110
|
+
profile1 = ImdbProfile.first(:titles => ['The Alamo'], :media_years => [1959])
|
111
|
+
profile2 = ImdbProfile.first(:titles => ['The Alamo'], :media_years => [1961])
|
112
|
+
(profile1.should be_nil) && (profile2.should be_nil)
|
113
|
+
end
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
115
|
+
it "should find John Wayne's The Alamo by title with the production year off by a year" do
|
116
|
+
profile1 = ImdbProfile.first(:titles => ['The Alamo'], :production_years => [1959])
|
117
|
+
profile2 = ImdbProfile.first(:titles => ['The Alamo'], :production_years => [1961])
|
118
|
+
(profile1.imdb_id.should == 'tt0053580') && (profile2.imdb_id.should == 'tt0053580')
|
119
|
+
end
|
117
120
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
it "should find John Wayne's The Alamo by title with the released year off by a year" do
|
122
|
+
profile1 = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1959])
|
123
|
+
profile2 = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1961])
|
124
|
+
(profile1.imdb_id.should == 'tt0053580') && (profile2.imdb_id.should == 'tt0053580')
|
125
|
+
end
|
123
126
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
127
|
+
it "should not find John Wayne's The Alamo by title with the production year off by two years" do
|
128
|
+
profile1 = ImdbProfile.first(:titles => ['The Alamo'], :production_years => [1958])
|
129
|
+
profile2 = ImdbProfile.first(:titles => ['The Alamo'], :production_years => [1962])
|
130
|
+
(profile1.should be_nil) && (profile2.should be_nil)
|
131
|
+
end
|
129
132
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
133
|
+
it "should not find John Wayne's The Alamo by title with the released year off by two years" do
|
134
|
+
profile1 = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1958])
|
135
|
+
profile2 = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1962])
|
136
|
+
(profile1.should be_nil) && (profile2.should be_nil)
|
137
|
+
end
|
134
138
|
end
|
135
139
|
|
136
|
-
|
137
|
-
|
138
|
-
it "should be able to convert to xml and then from xml" do
|
139
|
-
hash = nil
|
140
|
-
begin
|
141
|
-
profile = ImdbProfile.first(:imdb_id => 'tt0465234')
|
142
|
-
xml = profile.to_xml
|
143
|
-
hash = XmlSimple.xml_in(xml)
|
144
|
-
rescue
|
140
|
+
describe "let's make sure the generated xml from to_xml() is valid" do
|
141
|
+
it "should be able to convert to xml and then from xml" do
|
145
142
|
hash = nil
|
143
|
+
begin
|
144
|
+
profile = ImdbProfile.first(:imdb_id => 'tt0465234')
|
145
|
+
xml = profile.to_xml
|
146
|
+
hash = XmlSimple.xml_in(xml)
|
147
|
+
rescue
|
148
|
+
hash = nil
|
149
|
+
end
|
150
|
+
hash.should_not be_nil
|
146
151
|
end
|
147
|
-
hash.should_not be_nil
|
148
152
|
end
|
149
153
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
154
|
+
describe "test caching the profile to/from a file" do
|
155
|
+
it "should not create a file if a :filespec option is passed that is nil" do
|
156
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1960], :filespec => nil)
|
157
|
+
Dir.glob(File.join(TMPDIR, "imdb_profile_spec*")).empty?.should be_true
|
158
|
+
end
|
156
159
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
160
|
+
it "should create a file if a :filespec option is passed" do
|
161
|
+
filespec = get_temp_filename
|
162
|
+
profile = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1960], :filespec => filespec)
|
163
|
+
(File.exist?(filespec) && (File.size(filespec) > 0)).should be_true
|
164
|
+
end
|
162
165
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
166
|
+
it "should load from a file if a :filespec option is passed and the file exists" do
|
167
|
+
filespec = get_temp_filename
|
168
|
+
profile1 = ImdbProfile.first(:titles => ['The Alamo'], :released_years => [1960], :filespec => filespec)
|
169
|
+
profile2 = ImdbProfile.first(:filespec => filespec)
|
170
|
+
profile1.imdb_id.should == profile2.imdb_id
|
171
|
+
end
|
169
172
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
173
|
+
it "should not load from a file if a :filespec option is passed and the file does not exists" do
|
174
|
+
filespec = get_temp_filename
|
175
|
+
profile = ImdbProfile.first(:filespec => filespec)
|
176
|
+
profile.should be_nil
|
177
|
+
end
|
174
178
|
end
|
175
179
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
+
describe "When years are invalid (nil, 0, or '0')" do
|
181
|
+
it "should handle media year == nil" do
|
182
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :media_years => [nil])
|
183
|
+
profile.should_not == nil
|
184
|
+
end
|
180
185
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
186
|
+
it "should handle media year == 0" do
|
187
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :media_years => [0])
|
188
|
+
profile.should_not == nil
|
189
|
+
end
|
185
190
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
191
|
+
it "should handle media year == '0'" do
|
192
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :media_years => ['0'])
|
193
|
+
profile.should_not == nil
|
194
|
+
end
|
190
195
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
196
|
+
it "should handle production year == nil" do
|
197
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :production_years => [nil])
|
198
|
+
profile.should_not == nil
|
199
|
+
end
|
195
200
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
201
|
+
it "should handle media production == 0" do
|
202
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :production_years => [0])
|
203
|
+
profile.should_not == nil
|
204
|
+
end
|
200
205
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
206
|
+
it "should handle production year == '0'" do
|
207
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :production_years => ['0'])
|
208
|
+
profile.should_not == nil
|
209
|
+
end
|
205
210
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
211
|
+
it "should handle released year == nil" do
|
212
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :released_years => [nil])
|
213
|
+
profile.should_not == nil
|
214
|
+
end
|
210
215
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
216
|
+
it "should handle released year == 0" do
|
217
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :released_years => [0])
|
218
|
+
profile.should_not == nil
|
219
|
+
end
|
215
220
|
|
216
|
-
|
217
|
-
|
218
|
-
|
221
|
+
it "should handle released year == '0'" do
|
222
|
+
profile = ImdbProfile.first(:titles => ['National Treasure: Book of Secrets'], :released_years => ['0'])
|
223
|
+
profile.should_not == nil
|
224
|
+
end
|
219
225
|
end
|
220
226
|
|
221
227
|
def get_temp_filename
|
data/spec/imdb_search_spec.rb
CHANGED
@@ -6,15 +6,8 @@ describe ImdbSearch do
|
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
@imdb_search = ImdbSearch.new('indiana jones')
|
9
|
-
# @imdb_search.stub!(:open).and_return(open("#{$samples_dir}/sample_search.html"))
|
10
|
-
# ImdbMovie.stub!(:use_html_cache).and_return(true)
|
11
9
|
end
|
12
10
|
|
13
|
-
# it "should query IMDB url" do
|
14
|
-
# @imdb_search.should_receive(:open).with("http://www.imdb.com/find?q=indiana+jones;s=tt").and_return(open("#{$samples_dir}/sample_search.html"))
|
15
|
-
# @imdb_search.send(:document)
|
16
|
-
# end
|
17
|
-
|
18
11
|
describe "movies" do
|
19
12
|
|
20
13
|
it "should be a collection of ImdbMovie instances" do
|
@@ -71,24 +64,6 @@ describe ImdbSearch do
|
|
71
64
|
|
72
65
|
end
|
73
66
|
|
74
|
-
describe 'searches with potential encoding issues' do
|
75
|
-
|
76
|
-
before(:each) do
|
77
|
-
@imdb_search = ImdbSearch.new('torrente')
|
78
|
-
@imdb_search.stub!(:open).and_return(open("#{$samples_dir}/sample_spanish_search.html"))
|
79
|
-
ImdbMovie.stub!(:use_html_cache).and_return(true)
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "movies" do
|
83
|
-
|
84
|
-
# it "should include 'Misión en Marbella'" do
|
85
|
-
# @imdb_search.movies.map { |m| m.title }.should include('Misión en Marbella')
|
86
|
-
# end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
67
|
describe 'searches that match on AKA title' do
|
93
68
|
|
94
69
|
before(:each) do
|
@@ -115,23 +90,24 @@ describe ImdbSearch do
|
|
115
90
|
|
116
91
|
end
|
117
92
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
93
|
+
describe "failure test for AKA matching" do
|
94
|
+
describe 'searches that match on AKA title but without search_aka enabled' do
|
95
|
+
before(:each) do
|
96
|
+
@imdb_search = ImdbSearch.new('Who Am I?', false)
|
97
|
+
@imdb_search.stub!(:open).and_return(open("#{$samples_dir}/sample_who_am_i_search.html"))
|
98
|
+
ImdbMovie.stub!(:use_html_cache).and_return(true)
|
99
|
+
end
|
125
100
|
|
126
|
-
|
101
|
+
describe "movies" do
|
127
102
|
|
128
|
-
|
129
|
-
|
130
|
-
|
103
|
+
it "should have multiple movies" do
|
104
|
+
@imdb_search.movies.size.should > 1
|
105
|
+
end
|
131
106
|
|
132
|
-
|
133
|
-
|
134
|
-
|
107
|
+
it "should have no movies from 1998 because title is an aka" do
|
108
|
+
films = @imdb_search.movies.select{|m| m.year.to_i == 1998}
|
109
|
+
films.length.should == 0
|
110
|
+
end
|
135
111
|
end
|
136
112
|
end
|
137
113
|
end
|
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.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy Wright
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -73,7 +73,6 @@ files:
|
|
73
73
|
- spec/samples/www.imdb.com/find?q=some+extremely+specific+search+for+indiana+jones;s=tt
|
74
74
|
- spec/samples/www.imdb.com/rg/action-box-title/primary-photo/media/rm1203608832/tt0097576
|
75
75
|
- spec/spec_helper.rb
|
76
|
-
- spec/string_extensions_spec.rb
|
77
76
|
- README
|
78
77
|
has_rdoc: true
|
79
78
|
homepage: http://github.com/royw/imdb
|
@@ -106,5 +105,4 @@ test_files:
|
|
106
105
|
- spec/spec_helper.rb
|
107
106
|
- spec/imdb_search_spec.rb
|
108
107
|
- spec/imdb_image_spec.rb
|
109
|
-
- spec/string_extensions_spec.rb
|
110
108
|
- spec/imdb_profile_spec.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe String do
|
4
|
-
|
5
|
-
describe "unescape_html" do
|
6
|
-
|
7
|
-
it "should convert & to &" do
|
8
|
-
"M&M".unescape_html.should == 'M&M'
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should convert ó to ó" do
|
12
|
-
"ósmosis".unescape_html.should == 'ósmosis'
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "strip_tags" do
|
18
|
-
|
19
|
-
it "should strip HTML tags" do
|
20
|
-
"<em>Hola</em> hola".strip_tags.should == 'Hola hola'
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|