public
Fork of maddox/imdb
Description: Imdb library to get movie meta from IMDB.com, since they're too cool to give us an API
Clone URL: git://github.com/mschrag/imdb.git
reorganzied and changed up the api
maddox (author)
Wed Feb 13 23:18:58 -0800 2008
commit  0ae0783dff855cc9ffa9094b926082fa0e2bb299
tree    9ec1edb1e4bea294d6fb21999532b53210cf2f0d
parent  e9afd38c612458b8c2348dde542c8ac14744fdb8
0
...
3
4
5
6
7
8
9
 
10
11
12
...
3
4
5
 
6
 
 
7
8
9
10
0
@@ -3,10 +3,8 @@ A simple ruby library to scrape IMDB
0
 USAGE:
0
 
0
 require 'Imdb'
0
-include Imdb
0
 
0
-movie = Movie.new
0
-movie.find_by_id('tt0382932')
0
+movie = Imdb.find_movie_by_id('tt0382932')
0
 
0
 puts "IMDB ID: #{movie.imdb_id}"
0
 puts "Title: #{movie.title}"
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
 
 
 
 
61
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
0
@@ -1,59 +1,5 @@
0
-module Imdb
0
-
0
- IMDB_MOVIE_BASE_URL = "http://www.imdb.com/title/"
0
-
0
- class Movie
0
-
0
- require 'rubygems'
0
- require 'hpricot'
0
- require 'open-uri'
0
-
0
- attr_accessor :imdb_id, :title, :director, :plot, :runtime, :rating, :poster_url
0
-
0
-
0
- def find_by_id(id)
0
- self.imdb_id = id
0
- data = Hpricot(open(IMDB_MOVIE_BASE_URL + id))
0
- self.title = data.at("meta[@name='title']")['content'].gsub(/\(\d\d\d\d\)/,'').strip
0
-
0
- rating_text = (data/"div.rating/b").inner_text
0
- if rating_text =~ /([\d\.]+)\/10/
0
- self.rating = $1
0
- end
0
-
0
- begin
0
- self.poster_url = data.at("div.photo/a[@name='poster']/img")['src']
0
- rescue
0
- self.poster_url = nil
0
- end
0
-
0
- (data/"div.info").each do |info|
0
- case (info/"h5").inner_text
0
- when /Directors?:/
0
- self.director = parse_info(info).strip
0
- when "Runtime:"
0
- self.runtime = parse_info(info).strip
0
- when "Plot Outline:"
0
- self.plot = parse_info(info).gsub(/more$/, '').strip
0
- end
0
- end
0
-
0
- end
0
-
0
-
0
- protected
0
-
0
- def parse_info(info)
0
- body = info.inner_text
0
- body = body.gsub(/\n/,'')
0
- if body =~ /\:(.+)/
0
- body = $1
0
- end
0
- body
0
- end
0
-
0
-
0
-
0
- end
0
-
0
-end
0
\ No newline at end of file
0
+require 'rubygems'
0
+require 'hpricot'
0
+require 'open-uri'
0
+require 'imdb/imdb'
0
+require 'imdb/imdb_movie'
0
\ No newline at end of file
...
1
2
3
4
5
6
 
7
8
9
10
 
11
12
13
 
14
15
16
17
18
19
 
20
21
22
 
23
24
25
...
1
 
2
3
4
 
5
6
7
8
 
9
10
11
 
12
13
14
15
16
17
 
18
19
 
 
20
21
22
23
0
@@ -1,25 +1,23 @@
0
 require 'imdb'
0
-include Imdb
0
 
0
 describe Imdb do
0
   it "should have an imdb movie base url" do
0
- Movie::IMDB_MOVIE_BASE_URL.should eql("http://www.imdb.com/title/")
0
+ Imdb::IMDB_MOVIE_BASE_URL.should eql("http://www.imdb.com/title/")
0
   end
0
 end
0
 
0
-describe Movie, " when first created" do
0
+describe ImdbMovie, " when first created" do
0
 
0
   it "should not have an imdb_id" do
0
- movie = Movie.new
0
+ movie = ImdbMovie.new
0
     movie.imdb_id.should be_nil
0
   end
0
 
0
 end
0
 
0
-describe Movie, " after a find_by_id" do
0
+describe ImdbMovie, " after a Imdb.find_by_id returns it" do
0
   before(:each) do
0
- @movie = Movie.new
0
- @movie.find_by_id('tt0382932')
0
+ @movie = Imdb.find_movie_by_id('tt0382932')
0
   end
0
   
0
   

Comments

    No one has commented yet.