imdb 0.0.1
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/History.txt +3 -0
- data/Manifest.txt +14 -0
- data/README.rdoc +56 -0
- data/Rakefile +28 -0
- data/lib/imdb.rb +13 -0
- data/lib/imdb/movie.rb +66 -0
- data/lib/imdb/string_extensions.rb +17 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/imdb_movie_spec.rb +73 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +109 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
lib/imdb.rb
|
6
|
+
lib/imdb/movie.rb
|
7
|
+
lib/imdb/string_extensions.rb
|
8
|
+
script/console
|
9
|
+
script/destroy
|
10
|
+
script/generate
|
11
|
+
spec/imdb_movie_spec.rb
|
12
|
+
spec/spec.opts
|
13
|
+
spec/spec_helper.rb
|
14
|
+
tasks/rspec.rake
|
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= imdb
|
2
|
+
|
3
|
+
* http://github.com/ariejan/imdb
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This packages allows you to easy access publicly available data from IMDB.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Searching is not yet supported.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
i = Imdb::Movie.new("0095016")
|
16
|
+
|
17
|
+
i.title
|
18
|
+
#=> "Die Hard"
|
19
|
+
i.cast_member.first
|
20
|
+
#=> "Bruce Willis"
|
21
|
+
|
22
|
+
== REQUIREMENTS:
|
23
|
+
|
24
|
+
All required gems are installed automagically through RubyGems.
|
25
|
+
|
26
|
+
* Hpricot 0.8.1
|
27
|
+
* HTTParty 0.4.3
|
28
|
+
|
29
|
+
== INSTALL:
|
30
|
+
|
31
|
+
* sudo gem install imdb
|
32
|
+
|
33
|
+
== LICENSE:
|
34
|
+
|
35
|
+
(The MIT License)
|
36
|
+
|
37
|
+
Copyright (c) 2009 Ariejan de Vroom
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
'Software'), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
54
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
55
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
56
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/imdb'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('imdb', Imdb::VERSION) do |p|
|
7
|
+
p.developer('Ariejan de Vroom', 'ariejan@ariejan.net')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.rubyforge_name = 'imdb'
|
10
|
+
p.extra_deps = [
|
11
|
+
['httparty','>= 0.4.3'],
|
12
|
+
['hpricot', '>= 0.8.1']
|
13
|
+
]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
+
]
|
17
|
+
|
18
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
+
# task :default => [:spec, :features]
|
data/lib/imdb.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'httparty'
|
6
|
+
require 'hpricot'
|
7
|
+
|
8
|
+
require 'imdb/movie'
|
9
|
+
require 'imdb/string_extensions'
|
10
|
+
|
11
|
+
module Imdb
|
12
|
+
VERSION = '0.0.1'
|
13
|
+
end
|
data/lib/imdb/movie.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module Imdb
|
2
|
+
|
3
|
+
class Movie
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
attr_accessor :id, :url
|
7
|
+
|
8
|
+
# Initialize a new IMDB movie object.
|
9
|
+
def initialize(imdb_id)
|
10
|
+
@id = imdb_id
|
11
|
+
@url = "http://www.imdb.com/title/tt#{imdb_id}/"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast_members
|
15
|
+
document.search("table.cast td.nm a").map { |link| link.innerHTML.strip.imdb_unescape_html } rescue []
|
16
|
+
end
|
17
|
+
|
18
|
+
def director
|
19
|
+
document.at("h5[text()='Director:'] ~ a").innerHTML.strip.imdb_unescape_html rescue nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def genres
|
23
|
+
document.search("h5[text()='Genre:'] ~ a[@href*=/Sections/Genres/']").map { |link| link.innerHTML.strip.imdb_unescape_html } rescue []
|
24
|
+
end
|
25
|
+
|
26
|
+
def length
|
27
|
+
document.search("//h5[text()^='Runtime']/..").innerHTML[/\d+ min/].to_i rescue nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def plot
|
31
|
+
document.search("//h5[text()^='Plot']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.imdb_unescape_html rescue nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def poster
|
35
|
+
document.at("a[@name='poster'] img")['src'][/http:.+@@/] + '.jpg' rescue nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def rating
|
39
|
+
document.at(".general.rating b").innerHTML.strip.imdb_unescape_html.split('/').first.to_f rescue nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def tagline
|
43
|
+
document.search("//h5[text()^='Tagline']/..").innerHTML.split("\n")[2].gsub(/<.+>.+<\/.+>/, '').strip.imdb_unescape_html rescue nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def title
|
47
|
+
document.at("h1").innerHTML.split('<span').first.strip.imdb_unescape_html rescue nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def year
|
51
|
+
document.search('a[@href^="/Sections/Years/"]').innerHTML.to_i
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def document
|
57
|
+
@document ||= Hpricot(Imdb::Movie.find_by_id(@id))
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.find_by_id(imdb_id)
|
61
|
+
get("http://www.imdb.com/title/tt#{imdb_id}/")
|
62
|
+
end
|
63
|
+
|
64
|
+
end # Movie
|
65
|
+
|
66
|
+
end # Imdb
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'iconv'
|
3
|
+
|
4
|
+
module Imdb
|
5
|
+
module StringExtensions
|
6
|
+
|
7
|
+
def imdb_unescape_html
|
8
|
+
Iconv.conv("UTF-8", 'ISO-8859-1', CGI::unescapeHTML(self))
|
9
|
+
end
|
10
|
+
|
11
|
+
def imdb_strip_tags
|
12
|
+
gsub(/<\/?[^>]*>/, "")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
String.send :include, Imdb::StringExtensions
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/imdb.rb'}"
|
9
|
+
puts "Loading imdb gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
### WARNING: This spec uses live data!
|
4
|
+
#
|
5
|
+
# Many may object to testing against a live website, and for good reason.
|
6
|
+
# However, the IMDB interface changes over time, and to guarantee the parser
|
7
|
+
# works with the currently available IMDB website, tests are run against
|
8
|
+
# IMDB.com instead.
|
9
|
+
#
|
10
|
+
# This test uses "Die hard (1988)" as a testing sample:
|
11
|
+
#
|
12
|
+
# http://www.imdb.com/title/tt0095016/
|
13
|
+
#
|
14
|
+
|
15
|
+
describe "Imdb::Movie" do
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
# Get Die Hard (1988)
|
19
|
+
@movie = Imdb::Movie.new("0095016")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should find the cast members" do
|
23
|
+
cast = @movie.cast_members
|
24
|
+
|
25
|
+
cast.should be_an(Array)
|
26
|
+
cast.should include("Bruce Willis")
|
27
|
+
cast.should include("Bonnie Bedelia")
|
28
|
+
cast.should include("Alan Rickman")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should find the director" do
|
32
|
+
@movie.director.should =~ /John McTiernan/
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should find the genres" do
|
36
|
+
genres = @movie.genres
|
37
|
+
|
38
|
+
genres.should be_an(Array)
|
39
|
+
genres.should include('Action')
|
40
|
+
genres.should include('Crime')
|
41
|
+
genres.should include('Drama')
|
42
|
+
genres.should include('Thriller')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should find the length (in minutes)" do
|
46
|
+
@movie.length.should eql(131)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should find the plot" do
|
50
|
+
@movie.plot.should eql("New York cop John McClane gives terrorists a dose of their own medicine as they hold hostages in an LA office building.")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should find the poster" do
|
54
|
+
@movie.poster.should eql("http://ia.media-imdb.com/images/M/MV5BMTIxNTY3NjM0OV5BMl5BanBnXkFtZTcwNzg5MzY0MQ@@.jpg")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should find the rating" do
|
58
|
+
@movie.rating.should eql(8.3)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should find the title" do
|
62
|
+
@movie.title.should =~ /Die Hard/
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should find the tagline" do
|
66
|
+
@movie.tagline.should =~ /It will blow you through the back wall of the theater/
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should find the year" do
|
70
|
+
@movie.year.should eql(1988)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ariejan de Vroom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-03 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hpricot
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: newgem
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.3.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: hoe
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.8.0
|
54
|
+
version:
|
55
|
+
description: This packages allows you to easy access publicly available data from IMDB.
|
56
|
+
email:
|
57
|
+
- ariejan@ariejan.net
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
63
|
+
- History.txt
|
64
|
+
- Manifest.txt
|
65
|
+
- README.rdoc
|
66
|
+
files:
|
67
|
+
- History.txt
|
68
|
+
- Manifest.txt
|
69
|
+
- README.rdoc
|
70
|
+
- Rakefile
|
71
|
+
- lib/imdb.rb
|
72
|
+
- lib/imdb/movie.rb
|
73
|
+
- lib/imdb/string_extensions.rb
|
74
|
+
- script/console
|
75
|
+
- script/destroy
|
76
|
+
- script/generate
|
77
|
+
- spec/imdb_movie_spec.rb
|
78
|
+
- spec/spec.opts
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- tasks/rspec.rake
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://github.com/ariejan/imdb
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options:
|
85
|
+
- --main
|
86
|
+
- README.rdoc
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: imdb
|
104
|
+
rubygems_version: 1.3.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 2
|
107
|
+
summary: This packages allows you to easy access publicly available data from IMDB.
|
108
|
+
test_files: []
|
109
|
+
|