ruby-imdb 0.0.3
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +0 -0
- data/README +0 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/features/search.feature +6 -0
- data/features/step_definitions/imdb_test.rb +18 -0
- data/lib/imdb.rb +24 -0
- data/lib/imdb/movie.rb +23 -0
- data/lib/imdb/person.rb +13 -0
- data/lib/imdb/search.rb +24 -0
- data/ruby-imdb.gemspec +56 -0
- metadata +98 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
File without changes
|
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "jeweler"
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "ruby-imdb"
|
7
|
+
s.summary = "Ruby IMDB Parsing Library"
|
8
|
+
s.description = s.summary
|
9
|
+
s.email = "yalcin@webliyacelebi.com"
|
10
|
+
s.homepage = "http://github.com/yalcin/ruby-imdb"
|
11
|
+
s.authors = ["Yalcin Acikyildiz"]
|
12
|
+
s.files = FileList["[A-Za-z]*", "{lib,features}/**/*", ".gitignore"]
|
13
|
+
s.add_dependency "bundler"
|
14
|
+
s.add_dependency "nokogiri"
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
18
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
@@ -0,0 +1,18 @@
|
|
1
|
+
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end
|
2
|
+
require 'cucumber/formatter/unicode'
|
3
|
+
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
4
|
+
require 'imdb'
|
5
|
+
|
6
|
+
Before do
|
7
|
+
end
|
8
|
+
|
9
|
+
After do
|
10
|
+
end
|
11
|
+
|
12
|
+
Given /I have keyword "(.*)" for the search/ do |n|
|
13
|
+
@result = IMDB::Search.movie(n.to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
Then /the result should be equal or greater than (\d+)/ do |result|
|
17
|
+
@result.should >= result.to_i
|
18
|
+
end
|
data/lib/imdb.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.require(:default)
|
3
|
+
|
4
|
+
require "cgi"
|
5
|
+
require "open-uri"
|
6
|
+
|
7
|
+
require "imdb/search"
|
8
|
+
require "imdb/movie"
|
9
|
+
require "imdb/person"
|
10
|
+
|
11
|
+
#IMDB::Search.movie("fight club").each do
|
12
|
+
# |result|
|
13
|
+
# movie = IMDB::Movie.new(result.id)
|
14
|
+
# p movie.title
|
15
|
+
# movie.cast.each do
|
16
|
+
# |cast|
|
17
|
+
# p "#{cast.name} as #{cast.char}"
|
18
|
+
# end
|
19
|
+
# p movie.poster
|
20
|
+
#end
|
21
|
+
|
22
|
+
#movie = IMDB::Movie.new('0133093')
|
23
|
+
#p movie.poster
|
24
|
+
|
data/lib/imdb/movie.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module IMDB
|
2
|
+
class Movie
|
3
|
+
attr_accessor :title, :link, :cast, :id, :poster
|
4
|
+
|
5
|
+
def initialize(id)
|
6
|
+
@id = id
|
7
|
+
@link = "http://www.imdb.com/title/tt#{id}"
|
8
|
+
doc = Nokogiri::HTML(open("#{@link}/fullcredits"))
|
9
|
+
|
10
|
+
@title = doc.at("//head/meta[@name='title']")["content"].split(/\(\d+\)/)[0].strip!
|
11
|
+
@poster = doc.at("a[@name='poster'] img")['src'][/http:.+/] + '.jpg' rescue nil
|
12
|
+
@cast = []
|
13
|
+
doc.search("table.cast tr").map do |link|
|
14
|
+
picture = link.children[0].search("img")[0]["src"] rescue nil
|
15
|
+
name = link.children[1].content rescue nil
|
16
|
+
char = link.children[3].content rescue nil
|
17
|
+
@cast.push(IMDB::Person.new(name, char, picture, picture)) if name and char and picture != nil
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end # Movie
|
22
|
+
end # IMDB
|
23
|
+
|
data/lib/imdb/person.rb
ADDED
data/lib/imdb/search.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module IMDB
|
2
|
+
class Search
|
3
|
+
def self.movie(keyword)
|
4
|
+
doc = Nokogiri::HTML(open("http://www.imdb.com/find?s=tt&q=#{CGI.escape(keyword)}"))
|
5
|
+
ret_val = []
|
6
|
+
doc.search('a[@href^="/title/tt"]').reject { |node|
|
7
|
+
ret_val.push(IMDB::Result.new(node["href"][/\d+/], node.content, "http://www.imdb.com#{node['href']}"))
|
8
|
+
}
|
9
|
+
return ret_val
|
10
|
+
end
|
11
|
+
|
12
|
+
end # Search
|
13
|
+
|
14
|
+
class Result
|
15
|
+
attr_accessor :id, :title, :link, :year
|
16
|
+
|
17
|
+
def initialize(id, title, link)
|
18
|
+
@title = title
|
19
|
+
@link = link
|
20
|
+
@id = id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/ruby-imdb.gemspec
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ruby-imdb}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Yalcin Acikyildiz"]
|
12
|
+
s.date = %q{2010-04-26}
|
13
|
+
s.description = %q{Ruby IMDB Parsing Library}
|
14
|
+
s.email = %q{yalcin@webliyacelebi.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE",
|
23
|
+
"README",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"features/search.feature",
|
27
|
+
"features/step_definitions/imdb_test.rb",
|
28
|
+
"lib/imdb.rb",
|
29
|
+
"lib/imdb/movie.rb",
|
30
|
+
"lib/imdb/person.rb",
|
31
|
+
"lib/imdb/search.rb",
|
32
|
+
"ruby-imdb.gemspec"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/yalcin/ruby-imdb}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.6}
|
38
|
+
s.summary = %q{Ruby IMDB Parsing Library}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<bundler>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
49
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
53
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-imdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Yalcin Acikyildiz
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-26 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: nokogiri
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
description: Ruby IMDB Parsing Library
|
45
|
+
email: yalcin@webliyacelebi.com
|
46
|
+
executables: []
|
47
|
+
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
extra_rdoc_files:
|
51
|
+
- LICENSE
|
52
|
+
- README
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README
|
58
|
+
- Rakefile
|
59
|
+
- VERSION
|
60
|
+
- features/search.feature
|
61
|
+
- features/step_definitions/imdb_test.rb
|
62
|
+
- lib/imdb.rb
|
63
|
+
- lib/imdb/movie.rb
|
64
|
+
- lib/imdb/person.rb
|
65
|
+
- lib/imdb/search.rb
|
66
|
+
- ruby-imdb.gemspec
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/yalcin/ruby-imdb
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --charset=UTF-8
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Ruby IMDB Parsing Library
|
97
|
+
test_files: []
|
98
|
+
|