kieranj-imdb 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +72 -0
- data/lib/imdb/imdb_image.rb +19 -0
- data/lib/imdb/imdb_movie.rb +110 -0
- data/lib/imdb/imdb_search.rb +23 -0
- data/lib/imdb.rb +11 -0
- data/lib/string_extensions.rb +16 -0
- metadata +75 -0
data/README
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
• Added ability to get large poster via ImdbImage class
|
2
|
+
• Now retrieves character name along with actor name
|
3
|
+
|
4
|
+
ImdbMovie
|
5
|
+
|
6
|
+
ImdbMovie Indiana Jones and the Last Crusade
|
7
|
+
- should query IMDB url
|
8
|
+
- should get the image
|
9
|
+
|
10
|
+
ImdbMovie
|
11
|
+
|
12
|
+
ImdbMovie Indiana Jones and the Last Crusade
|
13
|
+
- should query IMDB url
|
14
|
+
- should get the title
|
15
|
+
- should get director(s)
|
16
|
+
- should get the poster url
|
17
|
+
- should return an ImdbImage object
|
18
|
+
- should get cast members
|
19
|
+
- should get the writers
|
20
|
+
- should get the release date
|
21
|
+
- should get the genres
|
22
|
+
- should get the plot
|
23
|
+
- should get the length
|
24
|
+
- should get the countries
|
25
|
+
- should get the languages
|
26
|
+
- should get the color
|
27
|
+
- should get the company
|
28
|
+
- should get some photos
|
29
|
+
- should get the tagline
|
30
|
+
- should get the aspect ratio
|
31
|
+
|
32
|
+
ImdbMovie Han robado una estrella
|
33
|
+
- should query IMDB url
|
34
|
+
- should get the title
|
35
|
+
- should get director(s)
|
36
|
+
- should not get the poster
|
37
|
+
- should get cast members
|
38
|
+
- should get the writers
|
39
|
+
- should get the release date
|
40
|
+
- should get the genres
|
41
|
+
- should not get the plot
|
42
|
+
- should get the length
|
43
|
+
- should get the countries
|
44
|
+
- should get the languages
|
45
|
+
- should not get the color
|
46
|
+
- should get the company
|
47
|
+
- should not get any photos
|
48
|
+
|
49
|
+
ImdbSearch
|
50
|
+
|
51
|
+
ImdbSearch Indiana Jones
|
52
|
+
- should query IMDB url
|
53
|
+
|
54
|
+
ImdbSearch Indiana Jones movies
|
55
|
+
- should be a collection of ImdbMovie instances
|
56
|
+
|
57
|
+
ImdbSearch searches with potential encoding issues
|
58
|
+
|
59
|
+
ImdbSearch searches with potential encoding issues movies
|
60
|
+
|
61
|
+
String
|
62
|
+
|
63
|
+
String unescape_html
|
64
|
+
- should convert & to &
|
65
|
+
- should convert ó to ó
|
66
|
+
|
67
|
+
String strip_tags
|
68
|
+
- should strip HTML tags
|
69
|
+
|
70
|
+
Finished in 3.878195 seconds
|
71
|
+
|
72
|
+
40 examples, 0 failures
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# @imdb_movie.poster.should == 'http://ia.media-imdb.com/images/M/MV5BMTkzODA5ODYwOV5BMl5BanBnXkFtZTcwMjAyNDYyMQ@@._V1._SX216_SY316_.jpg'
|
2
|
+
|
3
|
+
class ImdbImage
|
4
|
+
|
5
|
+
attr_accessor :url
|
6
|
+
|
7
|
+
def initialize(url)
|
8
|
+
@url = File.join("http://www.imdb.com/", url)
|
9
|
+
end
|
10
|
+
|
11
|
+
def image
|
12
|
+
document.at("table#principal tr td img")['src'] rescue nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def document
|
16
|
+
@document ||= Hpricot(open(self.url).read)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class ImdbMovie
|
2
|
+
|
3
|
+
attr_accessor :id, :url, :title
|
4
|
+
|
5
|
+
def initialize(id)
|
6
|
+
@id = id
|
7
|
+
@url = "http://www.imdb.com/title/tt#{self.id}/"
|
8
|
+
end
|
9
|
+
|
10
|
+
def title
|
11
|
+
document.at("div#tn15title h1").innerHTML.split('<span>').first.strip.unescape_html rescue nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def directors
|
15
|
+
document.search("h5[text()^='Director'] ~ a").map { |link| link.innerHTML.strip.unescape_html }.reject { |w| w == 'more' }.uniq rescue []
|
16
|
+
end
|
17
|
+
|
18
|
+
def poster_url
|
19
|
+
# File.join(self.url, document.at("a[@name='poster']")['href']) rescue nil
|
20
|
+
# File.join("http://www.imdb.com", document.at("a[@name='poster']")['href']) rescue nil
|
21
|
+
document.at("a[@name='poster']")['href'] rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def poster
|
25
|
+
ImdbImage.new(poster_url) rescue nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def cast_members
|
29
|
+
# document.search("table.cast td.nm a").map { |link| link.innerHTML.strip.unescape_html } rescue []
|
30
|
+
document.search("table.cast tr").inject([]) do |result, row|
|
31
|
+
a = row.search("td.nm a").innerHTML.strip.unescape_html
|
32
|
+
c = row.search("td.char a").innerHTML.strip.unescape_html
|
33
|
+
if c.empty?
|
34
|
+
c = row.search("td.char").innerHTML.strip.unescape_html
|
35
|
+
end
|
36
|
+
result << [a,c]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def writers
|
41
|
+
document.search("h5[text()^='Writer'] ~ a").map { |link| link.innerHTML.strip.unescape_html }.reject { |w| w == 'more' }.uniq rescue []
|
42
|
+
end
|
43
|
+
|
44
|
+
def release_date
|
45
|
+
date = document.search("//h5[text()^='Release Date']/..").innerHTML[/^\d{1,2} \w+ \d{4}/]
|
46
|
+
Date.parse(Chronic.parse(date).strftime('%Y/%m/%d'))
|
47
|
+
rescue
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def genres
|
52
|
+
document.search("h5[text()='Genre:'] ~ a[@href*=/Sections/Genres/']").map { |link| link.innerHTML.strip.unescape_html } rescue []
|
53
|
+
end
|
54
|
+
|
55
|
+
def plot
|
56
|
+
document.search("//h5[text()^='Plot']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.unescape_html rescue nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def tagline
|
60
|
+
document.search("//h5[text()^='Tagline']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.unescape_html rescue nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def aspect_ratio
|
64
|
+
document.search("//h5[text()^='Aspect Ratio']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.unescape_html rescue nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def length
|
68
|
+
document.search("//h5[text()^='Runtime']/..").innerHTML[/\d+ min/] rescue nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def countries
|
72
|
+
document.search("h5[text()='Country:'] ~ a[@href*=/Sections/Countries/']").map { |link| link.innerHTML.strip.unescape_html } rescue []
|
73
|
+
end
|
74
|
+
|
75
|
+
def languages
|
76
|
+
document.search("h5[text()='Language:'] ~ a[@href*=/Sections/Languages/']").map { |link| link.innerHTML.strip.unescape_html } rescue []
|
77
|
+
end
|
78
|
+
|
79
|
+
def color
|
80
|
+
document.at("h5[text()='Color:'] ~ a[@href*=color-info']").innerHTML.strip.unescape_html rescue nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def company
|
84
|
+
document.at("h5[text()='Company:'] ~ a[@href*=/company/']").innerHTML.strip.unescape_html rescue nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def photos
|
88
|
+
document.search(".media_strip_thumb img").map { |img| img['src'] } rescue []
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_data
|
92
|
+
update_title
|
93
|
+
end
|
94
|
+
|
95
|
+
def title2
|
96
|
+
document.at("div#tn15title h1").innerHTML.split('<span>').first.unescape_html rescue nil
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def update_title
|
102
|
+
# @title = document.at("h1").innerHTML.split('<span').first.strip.unescape_html rescue nil
|
103
|
+
document.at("div#tn15title h1").innerHTML.split('<span>').first.unescape_html rescue nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def document
|
107
|
+
@document ||= Hpricot(open(self.url).read)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ImdbSearch
|
2
|
+
|
3
|
+
attr_accessor :query
|
4
|
+
|
5
|
+
def initialize(query)
|
6
|
+
self.query = query
|
7
|
+
end
|
8
|
+
|
9
|
+
def movies
|
10
|
+
@movies ||= document.search('a[@href^="/title/tt"]').reject do |element|
|
11
|
+
element.innerHTML.strip_tags.empty?
|
12
|
+
end.map do |element|
|
13
|
+
ImdbMovie.new(element['href'][/\d+/])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def document
|
20
|
+
@document ||= Hpricot(open("http://www.imdb.com/find?q=#{CGI::escape(query)};s=tt").read)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/imdb.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'date'
|
3
|
+
require 'cgi'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'hpricot'
|
6
|
+
require 'chronic'
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/imdb/imdb_search'
|
9
|
+
require File.dirname(__FILE__) + '/imdb/imdb_movie'
|
10
|
+
require File.dirname(__FILE__) + '/imdb/imdb_image'
|
11
|
+
require File.dirname(__FILE__) + '/string_extensions'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'iconv'
|
3
|
+
|
4
|
+
module ImdbStringExtensions
|
5
|
+
|
6
|
+
def unescape_html
|
7
|
+
Iconv.conv("UTF-8", 'ISO-8859-1', CGI::unescapeHTML(self))
|
8
|
+
end
|
9
|
+
|
10
|
+
def strip_tags
|
11
|
+
gsub(/<\/?[^>]*>/, "")
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
String.send :include, ImdbStringExtensions
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kieranj-imdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergio Gil
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0.6"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: chronic
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
description:
|
34
|
+
email: sgilperez@gmail.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- lib/imdb/imdb_movie.rb
|
43
|
+
- lib/imdb/imdb_search.rb
|
44
|
+
- lib/imdb/imdb_image.rb
|
45
|
+
- lib/imdb.rb
|
46
|
+
- lib/string_extensions.rb
|
47
|
+
- README
|
48
|
+
has_rdoc: false
|
49
|
+
homepage:
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.2.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: Internet Movie DataBase
|
74
|
+
test_files: []
|
75
|
+
|