imdb_term 1.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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +103 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/imdb_term +73 -0
- data/imdb_term.gemspec +29 -0
- data/lib/imdb_term.rb +7 -0
- data/lib/imdb_term/CLI.rb +132 -0
- data/lib/imdb_term/movie.rb +69 -0
- data/lib/imdb_term/scraper.rb +74 -0
- data/lib/imdb_term/version.rb +3 -0
- data/spec.md +6 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f8461de3a8903a0f78b85450d30e35dac10ac52c
|
4
|
+
data.tar.gz: e8e024c96d42a07257e579f5ea474b498c301821
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02b728c9635813013663032d74fb03dd9ba7a7d189ba17cb3aa70e7e4aaf529bbb285f6b4769b389e5e843d364932fd9d727fa6a30db1ea8753aa7f9dff1b212
|
7
|
+
data.tar.gz: ecabf03f83562ff3c038cb6eb91df9be450b4fdced77ffcce3622e9ae13164e0e08f3b92a37cd568611d54d45bffe09fcd8ec07b1751a88e0d52158e3f17137c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Hiram Cruz
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# IMDbTerm
|
2
|
+
|
3
|
+
IMDbTerm is a terminal application used for querying the IMDb site.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'imdb_term'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install imdb_term
|
20
|
+
---
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Run imdb_term from terminal to start IMDbTerm.
|
24
|
+
Once started you will be greeted with a prompt.
|
25
|
+
<code>imdbterm: </code>
|
26
|
+
|
27
|
+
<code>now playing</code>
|
28
|
+
Returns a list of movies currently in theaters
|
29
|
+
|
30
|
+
**Example:**
|
31
|
+
|
32
|
+
[id] - [title]
|
33
|
+
[id] - [title]
|
34
|
+
[id] - [title]
|
35
|
+
...
|
36
|
+
[id] - [title]
|
37
|
+
|
38
|
+
<code>this week</code>
|
39
|
+
Returns a list of movies opening this week
|
40
|
+
|
41
|
+
**Example:**
|
42
|
+
|
43
|
+
[id] - [title]
|
44
|
+
[id] - [title]
|
45
|
+
[id] - [title]
|
46
|
+
...
|
47
|
+
[id] - [title]
|
48
|
+
|
49
|
+
<code>search [title]</code>
|
50
|
+
Searches IMDb for movies with [title]
|
51
|
+
Returns top 5 results
|
52
|
+
|
53
|
+
**Example:**
|
54
|
+
|
55
|
+
[id] - [title] ([release_year])
|
56
|
+
[id] - [title] ([release_year])
|
57
|
+
[id] - [title] ([release_year])
|
58
|
+
...
|
59
|
+
[id] - [title] ([release_year])
|
60
|
+
|
61
|
+
<code>details [id]</code>
|
62
|
+
Gives detailed information about movie with id [id]
|
63
|
+
|
64
|
+
**Example:**
|
65
|
+
|
66
|
+
[movie_title] ([year])
|
67
|
+
[rating] | [runtime] | [genres]
|
68
|
+
Director(s): [director]
|
69
|
+
Stars: [stars]
|
70
|
+
Summary: [summary]
|
71
|
+
|
72
|
+
<code>save [id]</code>
|
73
|
+
If movie id is included will save information about movie with id <movie id>
|
74
|
+
Otherwise saves all movies from previous command
|
75
|
+
|
76
|
+
**Example**
|
77
|
+
|
78
|
+
[Movie saved] || [Movies saved] || [No movie to save]
|
79
|
+
|
80
|
+
<code>[list] [detailed]</code>
|
81
|
+
If detailed option is included lists full details of all saved movies
|
82
|
+
Otherwise lists only id, name, and release year
|
83
|
+
|
84
|
+
**Example**
|
85
|
+
|
86
|
+
[id] - [name] [(release year)]
|
87
|
+
or
|
88
|
+
[title] [(release year)]
|
89
|
+
[content rating] | [runtime] | [genres]
|
90
|
+
Director(s): [director(s)]
|
91
|
+
Stars: [top billed stars]
|
92
|
+
Summary: [movie summary]
|
93
|
+
|
94
|
+
---
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/forgiv/imdb_term.
|
99
|
+
|
100
|
+
|
101
|
+
## License
|
102
|
+
|
103
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "imdb_term"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/imdb_term
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/imdb_term'
|
3
|
+
|
4
|
+
HELP_DOC = "" +
|
5
|
+
"\n [command] <param>" +
|
6
|
+
"\n [description]" +
|
7
|
+
"\n Example:" +
|
8
|
+
"\n [example output]" +
|
9
|
+
"\n" +
|
10
|
+
"\n Commands:" +
|
11
|
+
"\n" +
|
12
|
+
"\n [this week] <no params>" +
|
13
|
+
"\n Prints list of movies releasing this week" +
|
14
|
+
"\n Example:" +
|
15
|
+
"\n [id] - [title]" +
|
16
|
+
"\n" +
|
17
|
+
"\n [now playing] <no params>" +
|
18
|
+
"\n Prints list of movies currently in theaters" +
|
19
|
+
"\n Example:" +
|
20
|
+
"\n [id] - [title]" +
|
21
|
+
"\n" +
|
22
|
+
"\n [search] <movie title>" +
|
23
|
+
"\n Prints top ten search results for movie title" +
|
24
|
+
"\n Example:" +
|
25
|
+
"\n [id] - [title] [(release year)]" +
|
26
|
+
"\n" +
|
27
|
+
"\n [details] <movie id>" +
|
28
|
+
"\n Prints extended details about movie" +
|
29
|
+
"\n Example:" +
|
30
|
+
"\n [title] [(release year)]" +
|
31
|
+
"\n [content rating] | [runtime] | [genres]" +
|
32
|
+
"\n Director(s): [director(s)]" +
|
33
|
+
"\n Stars: [top billed stars]" +
|
34
|
+
"\n Summary: [movie summary]" +
|
35
|
+
"\n" +
|
36
|
+
"\n [save] <movie id>" +
|
37
|
+
"\n If movie id is included will save information about movie with id <movie id>" +
|
38
|
+
"\n Otherwise saves all movies from previous command" +
|
39
|
+
"\n Example:" +
|
40
|
+
"\n [Movie saved] || [Movies saved] || [No movie to save]" +
|
41
|
+
"\n" +
|
42
|
+
"\n [list] [detailed]" +
|
43
|
+
"\n If detailed option is included lists full details of all saved movies" +
|
44
|
+
"\n Otherwise lists only id, name, and release year" +
|
45
|
+
"\n Example:" +
|
46
|
+
"\n [id] - [name] [(release year)]" +
|
47
|
+
"\n or " +
|
48
|
+
"\n [title] [(release year)]" +
|
49
|
+
"\n [content rating] | [runtime] | [genres]" +
|
50
|
+
"\n Director(s): [director(s)]" +
|
51
|
+
"\n Stars: [top billed stars]" +
|
52
|
+
"\n Summary: [movie summary]"
|
53
|
+
|
54
|
+
|
55
|
+
cli = CLI.new
|
56
|
+
|
57
|
+
loop do
|
58
|
+
|
59
|
+
print "\nimdb_term: "
|
60
|
+
input = gets.chomp.strip.downcase
|
61
|
+
|
62
|
+
case input
|
63
|
+
|
64
|
+
when 'quit'
|
65
|
+
break
|
66
|
+
when 'exit'
|
67
|
+
break
|
68
|
+
when 'help'
|
69
|
+
puts HELP_DOC
|
70
|
+
else
|
71
|
+
cli.parse input
|
72
|
+
end
|
73
|
+
end
|
data/imdb_term.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'imdb_term/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "imdb_term"
|
8
|
+
spec.version = ImdbTerm::VERSION
|
9
|
+
spec.authors = ["Hiram Cruz"]
|
10
|
+
spec.email = ["hiram0101@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "IMDb cli"
|
13
|
+
spec.description = "IMDb CLI with searching, movie info, and showings"
|
14
|
+
spec.homepage = "https://github.com/forgiv/imdb_term"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_dependency "nokogiri", "~> 1.7.0"
|
29
|
+
end
|
data/lib/imdb_term.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
class CLI
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@movies = nil
|
5
|
+
@movie = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse(command)
|
9
|
+
if command.eql? 'now playing'
|
10
|
+
now_playing
|
11
|
+
elsif command.eql? 'this week'
|
12
|
+
this_week
|
13
|
+
elsif command.split(' ')[0].eql? 'search'
|
14
|
+
search(command.split(' ')[(1..-1)])
|
15
|
+
elsif command.split(' ')[0].eql? 'details'
|
16
|
+
details(command.split(' ')[1])
|
17
|
+
elsif command.split(' ')[0].eql? 'save'
|
18
|
+
if command.split(' ').size == 2
|
19
|
+
save(command.split(' ')[1])
|
20
|
+
else
|
21
|
+
save
|
22
|
+
end
|
23
|
+
elsif command.split(' ')[0].eql? 'list'
|
24
|
+
if command.split(' ')[1].eql? 'detailed'
|
25
|
+
list(true)
|
26
|
+
else
|
27
|
+
list
|
28
|
+
end
|
29
|
+
else
|
30
|
+
puts 'Unknown Command'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def now_playing
|
35
|
+
@movie = nil
|
36
|
+
movie_data = Scraper.scrape_now_playing
|
37
|
+
@movies = Movie.new_from_array(movie_data)
|
38
|
+
@movies.each do |movie|
|
39
|
+
puts "#{movie.id} - #{movie.title}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def this_week
|
44
|
+
@movie = nil
|
45
|
+
movie_data = Scraper.scrape_opening_this_week
|
46
|
+
@movies = Movie.new_from_array(movie_data)
|
47
|
+
@movies.each do |movie|
|
48
|
+
puts "#{movie.id} - #{movie.title}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def search(title)
|
53
|
+
@movie = nil
|
54
|
+
title = title.map{|e| e.capitalize}.join('+')
|
55
|
+
movie_data = Scraper.scrape_movie_by_title(title)
|
56
|
+
@movies = Movie.new_from_array(movie_data)
|
57
|
+
@movies.each do |movie|
|
58
|
+
print "#{movie.id} - #{movie.title} (#{movie.release_year}) "
|
59
|
+
if movie.type
|
60
|
+
print "(#{movie.type})\n"
|
61
|
+
else
|
62
|
+
print "\n"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def details(id)
|
68
|
+
@movies = nil
|
69
|
+
movie_data = Scraper.scrape_movie_by_id(id)
|
70
|
+
@movie = Movie.new(movie_data)
|
71
|
+
movie = @movie
|
72
|
+
|
73
|
+
puts "#{movie.title} (#{movie.release_year})"
|
74
|
+
puts "#{movie.content_rating} | #{movie.runtime} | #{movie.genres.join(', ')}"
|
75
|
+
print "Director(s): "
|
76
|
+
puts "#{movie.director}"
|
77
|
+
print "Stars: "
|
78
|
+
puts "#{movie.stars.join(', ')}"
|
79
|
+
print "Summary: "
|
80
|
+
puts "#{movie.summary}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def save(id = nil)
|
84
|
+
if id.nil?
|
85
|
+
if @movies.nil? && @movie.nil?
|
86
|
+
puts 'No movie to save'
|
87
|
+
elsif !@movie.nil?
|
88
|
+
movie_data = Scraper.scrape_movie_by_id(@movie[:id])
|
89
|
+
Movie.create_or_update(movie_data)
|
90
|
+
@movie = nil
|
91
|
+
puts 'Movie saved'
|
92
|
+
elsif !@movies.nil?
|
93
|
+
movies_data = @movies.map{|e| Scraper.scrape_movie_by_id(e.id)}
|
94
|
+
Movie.create_from_array(movies_data)
|
95
|
+
@movies = nil
|
96
|
+
puts 'Movies saved'
|
97
|
+
end
|
98
|
+
else
|
99
|
+
@movie = @movies = nil
|
100
|
+
movie_data = Scraper.scrape_movie_by_id(id)
|
101
|
+
Movie.create_or_update(movie_data)
|
102
|
+
puts 'Movie Saved'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def list(detailed = false)
|
107
|
+
if detailed
|
108
|
+
@movie = @movies = nil
|
109
|
+
Movie.all.each do |movie|
|
110
|
+
puts "#{movie.title} (#{movie.release_year})"
|
111
|
+
puts "#{movie.content_rating} | #{movie.runtime} | #{movie.genres.join(', ')}"
|
112
|
+
print "Director(s): "
|
113
|
+
puts "#{movie.director}"
|
114
|
+
print "Stars: "
|
115
|
+
puts "#{movie.stars.join(', ')}"
|
116
|
+
print "Summary: "
|
117
|
+
puts "#{movie.summary}"
|
118
|
+
puts ""
|
119
|
+
end
|
120
|
+
else
|
121
|
+
@movie = @movies = nil
|
122
|
+
Movie.all.each do |movie|
|
123
|
+
print "#{movie.id} - #{movie.title} (#{movie.release_year}) "
|
124
|
+
if movie.type
|
125
|
+
print "(#{movie.type})\n"
|
126
|
+
else
|
127
|
+
print "\n"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Movie
|
2
|
+
|
3
|
+
attr_accessor :id, :title, :release_year, :content_rating, :runtime, :genres, :summary, :director, :stars, :type
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(movie_data)
|
8
|
+
movie_data.each do |key, value|
|
9
|
+
self.send("#{key}=", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(movie_data)
|
14
|
+
movie_data.each do |key, value|
|
15
|
+
self.send("#{key}=", value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def save
|
20
|
+
@@all << self
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.all
|
25
|
+
@@all
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.create(movie_data)
|
29
|
+
movie = self.new(movie_data)
|
30
|
+
movie.save
|
31
|
+
movie
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.create_or_update(movie_data)
|
35
|
+
movie = self.find_by_id(movie_data[:id])
|
36
|
+
if movie.nil?
|
37
|
+
movie = self.create(movie_data)
|
38
|
+
else
|
39
|
+
movie.update(movie_data)
|
40
|
+
end
|
41
|
+
movie
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.new_from_array(array)
|
45
|
+
movies = Array.new
|
46
|
+
array.each do |movie_data|
|
47
|
+
movies << self.new(movie_data)
|
48
|
+
end
|
49
|
+
movies
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.create_from_array(array)
|
53
|
+
movies = Array.new
|
54
|
+
array.each do |movie_data|
|
55
|
+
movies << self.create_or_update(movie_data)
|
56
|
+
end
|
57
|
+
movies
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.find_by_id(id)
|
61
|
+
self.all.detect { |movie| movie.id.eql?(id) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.find_or_create_by_id(id)
|
65
|
+
movie = self.find_by_id(id)
|
66
|
+
movie.nil? ? self.create({:id => id}) : movie
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
class Scraper
|
5
|
+
|
6
|
+
BASE_URL = 'http://www.imdb.com'
|
7
|
+
|
8
|
+
def self.scrape_now_playing
|
9
|
+
doc = Nokogiri::HTML(open("#{BASE_URL}/movies-in-theaters"))
|
10
|
+
movies = doc.css('div#main div.list.detail.sub-list')
|
11
|
+
.last.css('td#img_primary a')
|
12
|
+
movies_data = Array.new
|
13
|
+
movies.each do |movie|
|
14
|
+
movie_data = {
|
15
|
+
:id => movie.attribute('href').value.split('/')[2][(2..-1)],
|
16
|
+
:title => movie.css('img').attribute('title').value[(0..-7)].strip
|
17
|
+
}
|
18
|
+
movies_data << movie_data
|
19
|
+
end
|
20
|
+
movies_data
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.scrape_opening_this_week
|
24
|
+
doc = Nokogiri::HTML(open("#{BASE_URL}/movies-in-theaters"))
|
25
|
+
movies = doc.css('div#main div.list.detail.sub-list')
|
26
|
+
.first.css('td#img_primary a')
|
27
|
+
movies_data = Array.new
|
28
|
+
movies.each do |movie|
|
29
|
+
movie_data = {
|
30
|
+
:id => movie.attribute('href').value.split('/')[2][(2..-1)],
|
31
|
+
:title => movie.css('img').attribute('title').value[(0..-7)].strip
|
32
|
+
}
|
33
|
+
movies_data << movie_data
|
34
|
+
end
|
35
|
+
movies_data
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.scrape_movie_by_title(title) # /find?q=Iron+Man
|
39
|
+
doc = Nokogiri::HTML(open("#{BASE_URL}/find?q=#{title}"))
|
40
|
+
movies = doc.css('div.findSection').first.css('td.result_text')
|
41
|
+
movies_data = Array.new
|
42
|
+
movies.each_with_index do |movie, index|
|
43
|
+
type = movie.text.scan(/\([\w ]+\)/).reverse.detect{|e| e[1].match(/[A-Za-z]/) || break }
|
44
|
+
movie_data = {
|
45
|
+
:id => movie.css('a').attribute('href').value.split('/')[2][(2..-1)],
|
46
|
+
:title => movie.css('a').text,
|
47
|
+
:release_year => movie.text.scan(/[12]\d{3}/)[-1],
|
48
|
+
:type => begin type.match(/[\w ]+/) rescue nil end
|
49
|
+
}
|
50
|
+
movies_data << movie_data
|
51
|
+
end
|
52
|
+
movies_data
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.scrape_movie_by_id(id)
|
56
|
+
doc = Nokogiri::HTML(open("#{BASE_URL}/title/tt#{id}"))
|
57
|
+
title_overview = doc.css('div#title-overview-widget')
|
58
|
+
title_cast = doc.css('div#titleCast')
|
59
|
+
directors = title_overview.css('div.plot_summary_wrapper span[itemprop="director"] span')
|
60
|
+
movie = {
|
61
|
+
:id => id,
|
62
|
+
:title => title_overview.css('div.title_wrapper > h1').text.strip[(0..-8)],
|
63
|
+
:release_year => title_overview.css('span#titleYear a').text.strip,
|
64
|
+
:content_rating => title_overview.css('div.subtext meta').attribute('content').value,
|
65
|
+
:runtime => title_overview.css('div.subtext time').text.strip,
|
66
|
+
:genres => title_overview.css('div.subtext span.itemprop').map { |e| e.text },
|
67
|
+
:summary => title_overview.css('div.plot_summary_wrapper div.summary_text').text.strip,
|
68
|
+
:director => directors.size > 1 ? directors.map{|e| e.text}.join(', ') : directors.text,
|
69
|
+
:stars => title_overview.css('div.plot_summary_wrapper span[itemprop="actors"] span').map { |e| e.text }
|
70
|
+
}
|
71
|
+
movie
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
data/spec.md
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imdb_term
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiram Cruz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.7.0
|
69
|
+
description: IMDb CLI with searching, movie info, and showings
|
70
|
+
email:
|
71
|
+
- hiram0101@gmail.com
|
72
|
+
executables:
|
73
|
+
- imdb_term
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- exe/imdb_term
|
87
|
+
- imdb_term.gemspec
|
88
|
+
- lib/imdb_term.rb
|
89
|
+
- lib/imdb_term/CLI.rb
|
90
|
+
- lib/imdb_term/movie.rb
|
91
|
+
- lib/imdb_term/scraper.rb
|
92
|
+
- lib/imdb_term/version.rb
|
93
|
+
- spec.md
|
94
|
+
homepage: https://github.com/forgiv/imdb_term
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.6.10
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: IMDb cli
|
118
|
+
test_files: []
|