imdb_movies 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/imdb_movies/cli.rb +54 -28
- data/lib/imdb_movies/imdb_scraper.rb +45 -29
- data/lib/imdb_movies/movie.rb +91 -74
- data/lib/imdb_movies/movie_links_scraper.rb +51 -34
- data/lib/imdb_movies/version.rb +1 -1
- data/lib/imdb_movies.rb +0 -1
- metadata +1 -2
- data/lib/imdb_movies/display.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0358af84ea07e6522acd36a70735567d372d46a0
|
4
|
+
data.tar.gz: ae8259f1a5cedd56ed433956f827d388bff30957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ff009df862f8ca7cd9c95bcb02304cb17ca90ee9ad88307687489c2e8bd670553a7176bea63f59ddfd9aa4f2b1131e8459a8a000c1fde73eb018ae8abfc1d7
|
7
|
+
data.tar.gz: 31014695b1c78565ce2976ac9265a0a127c67a9d48acbc24a232f3c573d301cb467cc99bb035b36ad59b47398c606fdd714e83bbd0f261d2bcf06d0aaf1f43cd
|
data/lib/imdb_movies/cli.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
# CLI Controller
|
2
|
-
|
2
|
+
class ImdbMovies::CLI
|
3
3
|
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :opening_movie_names, :opening_week, :now_playing_movie_names, :coming_soon_movie_names, :coming_soon_week, :all_movie_names, :all_movie_links
|
5
5
|
|
6
6
|
SKIP_MENU_DISPLAY = ["1", "2", "3", "opening this week", "now playing", "coming soon", "exit", "quit", ""]
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
imdb_movies_info = ImdbScraper.new.scrape
|
11
|
+
|
12
|
+
@opening_movie_names = imdb_movies_info[0]
|
13
|
+
@opening_week = imdb_movies_info[1]
|
14
|
+
@now_playing_movie_names = imdb_movies_info[2]
|
15
|
+
@coming_soon_movie_names = imdb_movies_info[3]
|
16
|
+
@coming_soon_week = imdb_movies_info[4]
|
17
|
+
@all_movie_names = imdb_movies_info[5]
|
18
|
+
@all_movie_links = imdb_movies_info[6]
|
11
19
|
|
12
|
-
@imdb_page.each{|cat| @nav_links << cat[0][1] }
|
13
|
-
@imdb_page.each{|cat| cat[1].movie_links.each{|movie| @movie_links << movie}}
|
14
20
|
end
|
15
21
|
|
16
22
|
# Main CLI
|
@@ -23,52 +29,72 @@
|
|
23
29
|
|
24
30
|
until user_input == "exit" || user_input == "quit"
|
25
31
|
puts "\nYou can enter 1-3, a specific movie name, 'menu' or 'exit/quit'."
|
26
|
-
|
32
|
+
puts "The movie name does not have to be case sensitive to get the info."
|
33
|
+
print "\nInput : "
|
27
34
|
|
28
35
|
user_input = gets.strip.downcase
|
29
|
-
input(user_input
|
36
|
+
input(user_input)
|
30
37
|
|
31
38
|
# Only displays the menu again if they entered a movie name or 'menu'
|
32
39
|
main_menu if !SKIP_MENU_DISPLAY.include?(user_input)
|
33
40
|
end
|
34
41
|
|
35
|
-
puts "\
|
42
|
+
puts "\nThank You for using IMDB Movies."
|
36
43
|
end
|
37
44
|
|
38
|
-
# Displays categories (opening this week,
|
45
|
+
# Displays movie categories (now playing, opening this week, coming soon) as well as first 5 movies if applicable
|
39
46
|
def main_menu
|
40
47
|
|
48
|
+
# Displays movies already in theaters
|
49
|
+
puts "\n1 - Now Playing"
|
50
|
+
@now_playing_movie_names[0...5].each {|movie_name| puts "\t\t#{movie_name}"}
|
51
|
+
puts "\tEnter '1' to see more movies that are playing."
|
52
|
+
|
53
|
+
# Displays opening week movies
|
54
|
+
puts "\n2 - #{opening_week}"
|
55
|
+
@opening_movie_names[0...5].each {|movie_name| puts "\t\t#{movie_name}"}
|
56
|
+
puts "\tEnter '2' to see more movies that are opening this week."
|
57
|
+
|
41
58
|
# Displays categories
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
puts "\t\t#{movie[0]}"
|
46
|
-
}
|
47
|
-
puts "\tEnter '#{index}' to see more."
|
48
|
-
}
|
59
|
+
puts "\n3 - #{coming_soon_week}"
|
60
|
+
@coming_soon_movie_names[0...5].each {|movie_name| puts "\t\t#{movie_name}"}
|
61
|
+
puts "\tEnter '3' to see more movies that are coming after this week."
|
49
62
|
end
|
50
63
|
|
51
64
|
# Gets user's input and calls a different navigation methood based on input
|
52
|
-
def input(user_input
|
65
|
+
def input(user_input)
|
53
66
|
|
54
67
|
case user_input
|
55
68
|
when "", "menu", "exit", "quit"
|
56
69
|
when "1", "opening this week"
|
57
|
-
|
70
|
+
display_movie_names(@opening_movie_names)
|
58
71
|
when "2", "now playing"
|
59
|
-
|
72
|
+
display_movie_names(@now_playing_movie_names)
|
60
73
|
when "3", "coming soon"
|
61
|
-
|
74
|
+
display_movie_names(@coming_soon_movie_names)
|
62
75
|
|
63
|
-
# When movie is entered it
|
64
|
-
# Otherwise it outputs a message.
|
76
|
+
# When movie is found is entered it creates a new instance of Movie from
|
65
77
|
else
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
78
|
+
# Search inside the @all_movie_names array. If you user input is included inside a movie title then store the index you found it at
|
79
|
+
found_movie_index = @all_movie_names.index{|movie_name| movie_name.downcase.gsub(/[^\w\s]+/, '').squeeze(" ").include?(user_input)}
|
80
|
+
|
81
|
+
# Create a new instance of Movie and have it display the info
|
82
|
+
# Otherwise show a message saying you're not sure what that was and display the menu again
|
83
|
+
if found_movie_index
|
84
|
+
movie = Movie.new(@all_movie_links[found_movie_index])
|
85
|
+
movie.display_info
|
86
|
+
|
87
|
+
print "\nDo you want to see the trailer on Youtube? Y / N "
|
88
|
+
input = gets.strip.downcase
|
89
|
+
movie.open_trailer if input == "yes" || input == "y"
|
90
|
+
else
|
91
|
+
puts "\nI'm sorry I don't know what you mean."
|
92
|
+
end
|
71
93
|
end
|
72
94
|
end
|
73
95
|
|
96
|
+
def display_movie_names(movie_names)
|
97
|
+
movie_names.each{|movie_name| puts "\t\t#{movie_name}"}
|
98
|
+
end
|
99
|
+
|
74
100
|
end
|
@@ -3,49 +3,65 @@
|
|
3
3
|
|
4
4
|
IMDB = "http://www.imdb.com"
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :opening_movie_names, :opening_movie_links, :opening_week, :now_playing_movie_names, :now_playing_movie_links, :coming_soon_movie_names, :coming_soon_movie_links, :coming_soon_week, :all_movie_names, :all_movie_links
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@
|
9
|
+
@opening_movie_names = []
|
10
|
+
@opening_movie_links = []
|
11
|
+
@opening_week = ""
|
12
|
+
@now_playing_movie_names = []
|
13
|
+
@now_playing_movie_links = []
|
14
|
+
@coming_soon_movie_names = []
|
15
|
+
@coming_soon_movie_links = []
|
16
|
+
@coming_soon_week = ""
|
17
|
+
@all_movie_names = []
|
18
|
+
@all_movie_links = []
|
10
19
|
end
|
11
20
|
|
12
21
|
def scrape
|
13
22
|
doc = Nokogiri::HTML(open(IMDB))
|
23
|
+
|
24
|
+
# Gets the HTML for the divs on the sidebar
|
14
25
|
sections = doc.css("#sidebar div.aux-content-widget-2")
|
15
26
|
|
16
|
-
|
27
|
+
# For each section, it gets and stores the movie names, links and the week if applicable
|
28
|
+
sections.each do |section|
|
17
29
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
30
|
+
# Stores the category header in category.
|
31
|
+
# We only want the movies, not the television or social media
|
32
|
+
category = section.css(".widget_header .oneline h3").text
|
33
|
+
|
34
|
+
case category
|
35
|
+
when "Opening This Week", "Now Playing (Box Office)", "Coming Soon"
|
36
|
+
|
37
|
+
# Gets the see more url so that MovieLinksScraper knows where to get the movie links from
|
38
|
+
category_link = IMDB + section.css(".seemore a").attr("href").value
|
39
|
+
|
40
|
+
# Looks inside the linked page to get the movies for that category
|
41
|
+
# Stores the array of movie names and links inside @movie_names and @movie_links to be flattened later
|
42
|
+
category_movies = MovieLinksScraper.new(category_link)
|
43
|
+
case category
|
44
|
+
when "Opening This Week"
|
45
|
+
@opening_movie_names, @opening_movie_links, @opening_week = category_movies.opening
|
46
|
+
when "Now Playing (Box Office)"
|
47
|
+
@now_playing_movie_names, @now_playing_movie_links = category_movies.now_playing
|
48
|
+
when "Coming Soon"
|
49
|
+
@coming_soon_movie_names, @coming_soon_movie_links, @coming_soon_week = category_movies.coming_soon
|
50
|
+
@coming_soon_week = "Coming Soon - Week of " + @coming_soon_week
|
51
|
+
end
|
24
52
|
|
25
|
-
begin
|
26
|
-
category_movies = MovieLinksScraper.new(category_link)
|
27
|
-
case category
|
28
|
-
when "Opening This Week"
|
29
|
-
category_movies.opening
|
30
|
-
when "Now Playing (Box Office)"
|
31
|
-
category_movies.now_playing
|
32
|
-
when "Coming Soon"
|
33
|
-
category_movies.coming_soon
|
34
53
|
end
|
35
|
-
movie_links = category_movies
|
36
|
-
rescue NoMethodError
|
37
54
|
end
|
38
55
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}
|
56
|
+
@all_movie_names = [@opening_movie_names, @now_playing_movie_names, @coming_soon_movie_names].flatten
|
57
|
+
@all_movie_links = [@opening_movie_links, @now_playing_movie_links, @coming_soon_movie_links].flatten
|
58
|
+
|
59
|
+
# Returning all the categories, movie names and links to the CLI to store
|
60
|
+
# We are sending back the category's link so that the Display class can look inside that page and get each movie name
|
61
|
+
# The CLI will not know what movies belong in which category, so it doesn't know how to display them
|
62
|
+
# The CLI calls the Display class so it can search for
|
47
63
|
|
48
|
-
|
64
|
+
return @opening_movie_names, @opening_week, @now_playing_movie_names, @coming_soon_movie_names, @coming_soon_week, @all_movie_names, @all_movie_links
|
49
65
|
end
|
50
66
|
|
51
67
|
end
|
data/lib/imdb_movies/movie.rb
CHANGED
@@ -1,86 +1,103 @@
|
|
1
|
-
# Accepts a url from IMDB on initialization and scrapes info
|
1
|
+
# Accepts a url from IMDB on initialization and scrapes info from IMDB
|
2
2
|
class Movie
|
3
|
-
|
3
|
+
attr_accessor :url, :name, :movie_rating, :length, :genres, :release_date, :imdb_rating, :description, :directors, :writers, :cast, :trailer_link
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
def initialize(url)
|
6
|
+
@url = url
|
7
|
+
scrape_info
|
8
|
+
end
|
9
|
+
|
10
|
+
# Scrapes and stores movie's info from IMDB page
|
11
|
+
def scrape_info
|
12
|
+
info = Nokogiri::HTML(open(@url)).css(".article.title-overview")
|
13
|
+
|
14
|
+
@name = info.css("tbody h1.header span[itemprop = 'name']").text.strip
|
15
|
+
|
16
|
+
begin
|
17
|
+
@movie_rating = info.css(".infobar meta[itemprop = 'contentRating']").attr("content").value.strip
|
18
|
+
rescue NoMethodError
|
19
|
+
end
|
20
|
+
|
21
|
+
@length = info.css(".infobar time[itemprop = 'duration']").text.strip
|
22
|
+
@release_date = info.css("a[title = 'See all release dates']").text.strip.gsub(/\s+/, " ")
|
23
|
+
@imdb_rating = info.css(".titlePageSprite.star-box-giga-star").text.strip
|
24
|
+
@description = info.css("p[itemprop = 'description']").text.strip
|
7
25
|
|
8
|
-
|
9
|
-
|
26
|
+
genres = info.css("span[itemprop = 'genre']")
|
27
|
+
@genres = []
|
28
|
+
genres.each{|g| @genres << g.text }
|
29
|
+
@genres = @genres.join(", ")
|
10
30
|
|
11
|
-
|
12
|
-
|
13
|
-
|
31
|
+
directors = info.css("div[itemprop = 'director'] span[itemprop = 'name']")
|
32
|
+
@directors = []
|
33
|
+
directors.each{|d| @directors << d.text}
|
14
34
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
35
|
+
writers = info.css("div[itemprop = 'creator'] span[itemprop = 'name']")
|
36
|
+
@writers = []
|
37
|
+
writers.each{|w| @writers << w.text}
|
38
|
+
|
39
|
+
cast = info.css("div[itemprop = 'actors'] span[itemprop = 'name']")
|
40
|
+
@cast = []
|
41
|
+
cast.each{|c| @cast << c.text}
|
42
|
+
|
43
|
+
@trailer_link = trailer
|
20
44
|
end
|
21
45
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
directors.each{|d| @directors << d.text}
|
35
|
-
|
36
|
-
writers = info.css("div[itemprop = 'creator'] span[itemprop = 'name']")
|
37
|
-
@writers = []
|
38
|
-
writers.each{|w| @writers << w.text}
|
39
|
-
|
40
|
-
cast = info.css("div[itemprop = 'actors'] span[itemprop = 'name']")
|
41
|
-
@cast = []
|
42
|
-
cast.each{|c| @cast << c.text}
|
43
|
-
|
44
|
-
@trailer_link = trailer
|
45
|
-
end
|
46
|
-
|
47
|
-
# Scrapes Youtube search results for first video link
|
48
|
-
# searches movie name + ' trailer'
|
49
|
-
def trailer
|
50
|
-
name = @name.downcase.split(/\W+/).join("+")
|
51
|
-
youtube_search = "https://www.youtube.com/results?search_query="
|
52
|
-
youtube_search_query = Nokogiri::HTML(open(youtube_search + name + "+trailer", ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE))
|
53
|
-
|
54
|
-
trailer_link = "https://youtube.com" + youtube_search_query.css("#results ol.section-list li ol.item-section li div.yt-lockup-dismissable div.yt-lockup-content h3.yt-lockup-title a").attr("href").value
|
55
|
-
end
|
56
|
-
|
57
|
-
def display_info
|
58
|
-
puts "\n#{@name}\n\n"
|
59
|
-
puts "Movie Rating: \t#{@movie_rating}"
|
60
|
-
puts "Length: \t#{@length}"
|
61
|
-
puts "Genre: \t\t#{@genres}"
|
62
|
-
puts "Release Date: \t#{@release_date}"
|
63
|
-
@imdb_rating != "" ? (puts "IMDB Rating: \t#{@imdb_rating}/10.0") : (puts "IMDB Rating: \tNo Ratings Yet")
|
64
|
-
puts "Description: \t#{@description}"
|
65
|
-
puts "Director(s): \t#{@directors.join(", ")}"
|
66
|
-
puts "Writer(s): \t#{@writers.join(", ")}"
|
67
|
-
puts "Cast: \t\t#{@cast.join(", ")}"
|
68
|
-
puts "\nTrailer: \t#{@trailer_link}"
|
69
|
-
end
|
70
|
-
|
71
|
-
def open_trailer
|
72
|
-
begin
|
73
|
-
exec("open #{@trailer_link}")
|
74
|
-
rescue SystemCallError
|
46
|
+
# Scrapes Youtube search results for first video link
|
47
|
+
# searches movie name + ' trailer'
|
48
|
+
def trailer
|
49
|
+
movie_name = @name.downcase.split(/\W+/).join("+")
|
50
|
+
youtube_search = "https://www.youtube.com/results?search_query=" + movie_name + "+trailer"
|
51
|
+
|
52
|
+
# Scrapes HTML for Youtube search results
|
53
|
+
# 'ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE' is to get past SSL verification for open-uri when getting Youtube's HTML
|
54
|
+
youtube_search_query = Nokogiri::HTML(open(youtube_search, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE))
|
55
|
+
|
56
|
+
# Scrape first link
|
57
|
+
trailer_link = "https://youtube.com" + youtube_search_query.css("#results ol.section-list li ol.item-section li div.yt-lockup-dismissable div.yt-lockup-content h3.yt-lockup-title a").attr("href").value
|
75
58
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
59
|
+
|
60
|
+
def display_info
|
61
|
+
puts "\n#{@name}\n\n"
|
62
|
+
puts "Movie Rating: \t#{@movie_rating}"
|
63
|
+
puts "Length: \t#{@length}"
|
64
|
+
puts "Genre: \t\t#{@genres}"
|
65
|
+
puts "Release Date: \t#{@release_date}"
|
66
|
+
|
67
|
+
if @imdb_rating != ""
|
68
|
+
puts "IMDB Rating: \t#{@imdb_rating}/10.0"
|
69
|
+
else
|
70
|
+
puts "IMDB Rating: \tNo Ratings Yet"
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "Description: \t#{@description}"
|
74
|
+
puts "Director(s): \t#{@directors.join(", ")}"
|
75
|
+
puts "Writer(s): \t#{@writers.join(", ")}"
|
76
|
+
puts "Cast: \t\t#{@cast.join(", ")}"
|
77
|
+
puts "\nTrailer: \t#{@trailer_link}"
|
79
78
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
|
80
|
+
# Executes command to open youtube link inside browser
|
81
|
+
def open_trailer
|
82
|
+
|
83
|
+
# Mac OS X
|
84
|
+
begin
|
85
|
+
exec("open #{@trailer_link}")
|
86
|
+
rescue SystemCallError
|
87
|
+
end
|
88
|
+
|
89
|
+
# Windows
|
90
|
+
begin
|
91
|
+
exec("start #{@trailer_link}")
|
92
|
+
rescue SystemCallError
|
93
|
+
end
|
94
|
+
|
95
|
+
# Linux/Unix
|
96
|
+
begin
|
97
|
+
exec("xdg-open #{@trailer_link}")
|
98
|
+
rescue SystemCallError
|
99
|
+
end
|
100
|
+
|
83
101
|
end
|
84
|
-
end
|
85
102
|
end
|
86
103
|
|
@@ -1,46 +1,63 @@
|
|
1
1
|
class MovieLinksScraper
|
2
|
-
|
2
|
+
attr_accessor :url, :movie_names, :movie_links, :opening_week, :upcomming_week
|
3
3
|
|
4
|
-
|
4
|
+
IMDB = "http://www.imdb.com"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(url)
|
7
|
+
@url = url
|
8
|
+
@movie_names = []
|
9
|
+
@movie_links = []
|
10
|
+
@opening_week = ""
|
11
|
+
@comming_soon_week = ""
|
12
|
+
end
|
13
|
+
|
14
|
+
# Gets the links and opening week from IMDB for the movies that are opening up this week
|
15
|
+
# The movie names and links to the movies' IMDB pages are returned back to ImdbScraper
|
16
|
+
def opening
|
17
|
+
doc = Nokogiri::HTML(open(@url))
|
18
|
+
movie_links = doc.css(".article .list")[1].css(".list_item h4[itemprop = 'name'] a")
|
19
|
+
add_movie_name_and_links(movie_links)
|
9
20
|
|
10
|
-
|
11
|
-
|
21
|
+
# Stores the header that is shown on the opening week movies page
|
22
|
+
# Example: 'Opening This Week - January 22' is stored
|
23
|
+
@opening_week = doc.css(".article .list h3").first.text
|
12
24
|
|
13
|
-
|
14
|
-
doc = Nokogiri::HTML(open(@url))
|
15
|
-
movie_links = doc.css(".article .list")[1].css(".list_item h4[itemprop = 'name'] a")
|
16
|
-
begin
|
17
|
-
movie_links.each{|m_link| @movie_links.push( [ m_link.text.gsub(/\(\w+\)/, ""), (IMDB + m_link.attr("href")) ] )}
|
18
|
-
rescue NoMethodError
|
25
|
+
return @movie_names, @movie_links, @opening_week
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
# Gets the links from IMDB for the movies that are popular and in theaters now
|
29
|
+
# The movie names and links to the movies' IMDB pages are returned back to ImdbScraper
|
30
|
+
def now_playing
|
31
|
+
doc = Nokogiri::HTML(open(@url))
|
32
|
+
movie_links = doc.css("tbody tr td.titleColumn a")
|
33
|
+
add_movie_name_and_links(movie_links)
|
24
34
|
|
25
|
-
|
26
|
-
doc = Nokogiri::HTML(open(@url))
|
27
|
-
movie_links = doc.css("tbody tr td.titleColumn a")
|
28
|
-
begin
|
29
|
-
movie_links.each{|m_link| @movie_links.push( [ m_link.text.gsub(/\(\w+\)/, ""), (IMDB + m_link.attr("href")) ] )}
|
30
|
-
rescue NoMethodError
|
35
|
+
return @movie_names, @movie_links
|
31
36
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
|
38
|
+
# Gets the links and opening week from IMDB for the movies that are comming up in 2 weeks
|
39
|
+
# The movie names and links to the movies' IMDB pages are returned back to ImdbScraper
|
40
|
+
def coming_soon
|
41
|
+
doc = Nokogiri::HTML(open(@url))
|
42
|
+
movie_links = doc.css(".list.detail .list_item h4[itemprop = 'name'] a")
|
43
|
+
add_movie_name_and_links(movie_links)
|
44
|
+
|
45
|
+
# Stores the header that is show on the coming soon movies page
|
46
|
+
# Example: 'January 29' is stored
|
47
|
+
@coming_soon_week = doc.css(".list.detail h4.li_group a").first.text
|
48
|
+
return @movie_names, @movie_links, @coming_soon_week
|
41
49
|
end
|
42
50
|
|
43
|
-
|
44
|
-
|
45
|
-
|
51
|
+
# Gets an array movie links that were scraped from an IMDB
|
52
|
+
# Each movie link has the movie name as the text.
|
53
|
+
# We are pushing each movie name and link inside @movie_names and @movie_links
|
54
|
+
def add_movie_name_and_links(movie_links)
|
55
|
+
# Pulls anchors which are movie names with links to that movie's page on IMDB
|
56
|
+
movie_links.each do |link|
|
57
|
+
# Gets the movie name from text
|
58
|
+
@movie_names << link.text.gsub(/\(\w+\)/, '')
|
59
|
+
# Gets the movie's url
|
60
|
+
@movie_links << IMDB + link.attr("href")
|
61
|
+
end
|
62
|
+
end
|
46
63
|
end
|
data/lib/imdb_movies/version.rb
CHANGED
data/lib/imdb_movies.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imdb_movies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- azheng249
|
@@ -102,7 +102,6 @@ files:
|
|
102
102
|
- imdb_movies.gemspec
|
103
103
|
- lib/imdb_movies.rb
|
104
104
|
- lib/imdb_movies/cli.rb
|
105
|
-
- lib/imdb_movies/display.rb
|
106
105
|
- lib/imdb_movies/imdb_scraper.rb
|
107
106
|
- lib/imdb_movies/movie.rb
|
108
107
|
- lib/imdb_movies/movie_links_scraper.rb
|
data/lib/imdb_movies/display.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
class Display
|
2
|
-
|
3
|
-
attr_accessor :links
|
4
|
-
|
5
|
-
def initialize(links = nil)
|
6
|
-
@links = links
|
7
|
-
end
|
8
|
-
|
9
|
-
def opening
|
10
|
-
puts @links.opening_week + "\n\n"
|
11
|
-
@links.movie_links.each{|m| puts "\t\t#{m[0]}"}
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def now_playing
|
16
|
-
puts "Now Playing\n\n"
|
17
|
-
@links.movie_links.each{|m| puts "\t\t#{m[0]}"}
|
18
|
-
end
|
19
|
-
|
20
|
-
def coming_soon
|
21
|
-
puts "Coming Soon - \t" + @links.opening_week + "\n\n"
|
22
|
-
@links.movie_links.each{|m| puts "\t\t#{m[0]}"}
|
23
|
-
end
|
24
|
-
|
25
|
-
def movie(movie_url)
|
26
|
-
movie = Movie.new(movie_url)
|
27
|
-
movie.display_info
|
28
|
-
|
29
|
-
print "\nDo you want to see the trailer for this movie (Y/N):\t"
|
30
|
-
user_input = gets.strip.downcase
|
31
|
-
|
32
|
-
movie.open_trailer if user_input == "y" || user_input == "yes"
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|