imdb_title 0.0.9 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/exceptions.rb +0 -3
- data/lib/imdb_title.rb +30 -55
- data/lib/non_interactive.rb +21 -0
- data/lib/titles/episode.rb +3 -3
- data/lib/titles/movie.rb +7 -6
- data/lib/titles/tv_show.rb +3 -3
- data/lib/titles/video_game.rb +2 -9
- metadata +3 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d800873fb8e5ce95526320f79336bf3ddee8ba46646f7fb92964f73ea4273cf4
|
4
|
+
data.tar.gz: 5c4e4147d480b343bcc64f46ba60dd70bf277fd114f3a54673d73aeea54d40b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99e7b36f91aab41560f6a788ee59668cadcb79f57a58202041649ae40abfd8fe89e0d2c415622ec3cd2afc02fc8fdda0d98a98c2cbdd34d09484ec35f029f045
|
7
|
+
data.tar.gz: c67c2ca7d45a26610269c61b81166849f26b1f9768f90bcc47722ec50b4e4f0e722bd548e3c569b2e170adc37572177e58a966016f19ee85c3bfc8f064c251fc
|
data/lib/exceptions.rb
CHANGED
data/lib/imdb_title.rb
CHANGED
@@ -4,8 +4,9 @@
|
|
4
4
|
require "nokogiri"
|
5
5
|
require "httparty"
|
6
6
|
|
7
|
-
# require all files & folders of
|
8
|
-
|
7
|
+
# require all files & folders of the current directory 'lib'
|
8
|
+
lib = __dir__
|
9
|
+
Dir.glob(File.join(lib, "**", "*.rb")).sort.each(&method(:require))
|
9
10
|
|
10
11
|
##
|
11
12
|
##
|
@@ -22,88 +23,81 @@ Dir.glob(File.join(__dir__, "**", "*.rb")).sort.each(&method(:require))
|
|
22
23
|
#### ------- DETAILS ---------
|
23
24
|
### 9. Prodcution Companies
|
24
25
|
### 10. Release Date
|
25
|
-
#### ------- TECHNICAL SPECS ---------
|
26
|
-
### 11. Runtime
|
27
26
|
##
|
28
27
|
##
|
29
28
|
##
|
30
29
|
|
31
|
-
# :reek:TooManyMethods
|
32
30
|
module IMDb
|
33
|
-
#
|
31
|
+
# pass any Movie, TV-show, Episode or Game url from imdb.com
|
34
32
|
class Title
|
35
|
-
# pass valid imdb title url
|
36
33
|
def initialize(url)
|
37
34
|
raise InvalidURL, "Please input a valid IMDb URL" unless valid?(url)
|
38
35
|
|
39
|
-
case
|
36
|
+
case media_type
|
40
37
|
when "video.movie" then extend Movie
|
41
38
|
when "video.tv_show" then extend TvShow
|
42
39
|
when "video.episode" then extend Episode
|
43
40
|
when "video.other" then extend VideoGame
|
44
|
-
else raise UnSupportedTypeError, "Unknown title type"
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
48
|
-
#
|
44
|
+
# lists all top cast (Array)
|
49
45
|
def casts
|
50
|
-
|
46
|
+
html = document.css("a[data-testid=title-cast-item__actor]")
|
47
|
+
return if html.empty?
|
48
|
+
|
49
|
+
html.map(&:text)
|
51
50
|
end
|
52
51
|
|
53
|
-
#
|
52
|
+
# list of directors (Array)
|
54
53
|
def directors
|
55
|
-
html = document.css("li[data-testid=title-pc-principal-credit]")
|
56
|
-
|
57
|
-
return unless text.include? "Director"
|
58
|
-
|
59
|
-
split_these html.css("ul").first.text
|
60
|
-
end
|
54
|
+
html = document.css("li[data-testid=title-pc-principal-credit]").first
|
55
|
+
return unless html.text.match?(/Director|Creator/)
|
61
56
|
|
62
|
-
|
63
|
-
def duration
|
64
|
-
inspect_this document.css("li[data-testid=title-techspec_runtime] div").text
|
57
|
+
html.css("div li").map(&:text)
|
65
58
|
end
|
66
59
|
|
67
|
-
#
|
60
|
+
# list of genres (Array)
|
68
61
|
def genres
|
69
|
-
|
62
|
+
document.css("div[data-testid=genres] div a").map(&:text)
|
70
63
|
end
|
71
64
|
|
72
|
-
#
|
65
|
+
# ID that differentiates each media type on imdb.com (String)
|
73
66
|
def imdb_id
|
74
67
|
document.css("meta[property*=pageConst]").attribute("content").value
|
75
68
|
end
|
76
69
|
|
77
|
-
#
|
70
|
+
# number of users rated (String)
|
78
71
|
def popularity
|
79
72
|
document.css("div[data-testid=hero-rating-bar__aggregate-rating] span div").last&.text
|
80
73
|
end
|
81
74
|
|
82
|
-
#
|
75
|
+
# list of production companies (Array/String)
|
83
76
|
def production_companies
|
84
|
-
|
77
|
+
document.css("li[data-testid=title-details-companies] li").map(&:text)
|
85
78
|
end
|
86
79
|
|
87
|
-
#
|
80
|
+
# average ratings (String)
|
88
81
|
def ratings
|
89
82
|
document.css("div[data-testid=hero-rating-bar__aggregate-rating__score] span").first&.text
|
90
83
|
end
|
91
84
|
|
92
|
-
#
|
85
|
+
# the date it was release on (String)
|
93
86
|
def release_date
|
94
|
-
|
87
|
+
document.css("li[data-testid=title-details-releasedate] div").first&.text
|
95
88
|
end
|
96
89
|
|
97
|
-
#
|
90
|
+
# short introduction
|
98
91
|
def tagline
|
99
|
-
|
92
|
+
document.css("span[data-testid=plot-xl]").first&.text
|
100
93
|
end
|
101
94
|
|
102
|
-
#
|
95
|
+
# name or title
|
103
96
|
def title
|
104
97
|
document.css("h1").text
|
105
98
|
end
|
106
99
|
|
100
|
+
# full url
|
107
101
|
def url
|
108
102
|
document.css("meta[property*=url]").attribute("content").value
|
109
103
|
end
|
@@ -112,37 +106,18 @@ module IMDb
|
|
112
106
|
|
113
107
|
attr_reader :document
|
114
108
|
|
115
|
-
# checks IMDb id from URL (
|
109
|
+
# checks IMDb id from URL (should not return 404 Error Page)
|
116
110
|
def correct_id?(url)
|
117
111
|
response = HTTParty.get(url, {headers: {"User-Agent" => "Httparty"}})
|
118
112
|
@document = Nokogiri::HTML(response.body)
|
119
113
|
document.title != "404 Error - IMDb"
|
120
114
|
end
|
121
115
|
|
122
|
-
|
123
|
-
# returns proper output
|
124
|
-
def inspect_this(input)
|
125
|
-
if input.empty?
|
126
|
-
nil
|
127
|
-
elsif input.length == 1
|
128
|
-
input.join
|
129
|
-
else
|
130
|
-
input
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# spilits camel case names to array
|
135
|
-
def split_these(names)
|
136
|
-
list = names.split(/(?<=[a-z)])(?=[A-Z])/)
|
137
|
-
inspect_this(list)
|
138
|
-
end
|
139
|
-
|
140
|
-
# returns type of title
|
141
|
-
def title_type
|
116
|
+
def media_type
|
142
117
|
document.css("meta[property*=type]").attribute("content").value
|
143
118
|
end
|
144
119
|
|
145
|
-
# validates domain name, slug
|
120
|
+
# validates domain name, slug, IMDb ID & its length
|
146
121
|
def valid?(url)
|
147
122
|
url.match?("https://www.imdb.com/title/tt#{/\d+{7,}/i}") && correct_id?(url)
|
148
123
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
##
|
5
|
+
##
|
6
|
+
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
+
### All features are available from Title class
|
8
|
+
|
9
|
+
## 1. duration
|
10
|
+
##
|
11
|
+
##
|
12
|
+
|
13
|
+
# features exclusive to Movies, Tv-Shows & Episode media type
|
14
|
+
module NonInteractive
|
15
|
+
# returns runtime of the media
|
16
|
+
def duration
|
17
|
+
document.css("li[data-testid=title-techspec_runtime] div").first&.text
|
18
|
+
end
|
19
|
+
|
20
|
+
# define streaming_on method that returns on which platform the media is streaming
|
21
|
+
end
|
data/lib/titles/episode.rb
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
##
|
5
5
|
##
|
6
6
|
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
-
### All features are available from
|
8
|
-
|
7
|
+
### All features are available from Title class
|
9
8
|
##
|
10
9
|
##
|
11
10
|
##
|
12
11
|
|
13
|
-
# features exclusive to Episode
|
12
|
+
# features exclusive to Episode media type
|
14
13
|
module Episode
|
14
|
+
prepend NonInteractive
|
15
15
|
end
|
data/lib/titles/movie.rb
CHANGED
@@ -4,8 +4,7 @@
|
|
4
4
|
##
|
5
5
|
##
|
6
6
|
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
-
### All features are available from
|
8
|
-
|
7
|
+
### All features are available from Title class
|
9
8
|
#### ------- BOX OFFICE ---------
|
10
9
|
### 12. Budget
|
11
10
|
### 13. Gross Worldwide (Revenue)
|
@@ -13,15 +12,17 @@
|
|
13
12
|
##
|
14
13
|
##
|
15
14
|
|
16
|
-
# features exclusive to Movie
|
15
|
+
# features exclusive to Movie media type
|
17
16
|
module Movie
|
18
|
-
|
17
|
+
prepend NonInteractive
|
18
|
+
|
19
|
+
# budget (String)
|
19
20
|
def budget
|
20
21
|
document.css("li[data-testid=title-boxoffice-budget] div").text[/\$\S+/]
|
21
22
|
end
|
22
23
|
|
23
|
-
#
|
24
|
+
# revenue / Gross Worldwide (String)
|
24
25
|
def revenue
|
25
|
-
|
26
|
+
document.css("li[data-testid=title-boxoffice-cumulativeworldwidegross] div").first&.text
|
26
27
|
end
|
27
28
|
end
|
data/lib/titles/tv_show.rb
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
##
|
5
5
|
##
|
6
6
|
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
-
### All features are available from
|
8
|
-
|
7
|
+
### All features are available from Title class
|
9
8
|
##
|
10
9
|
##
|
11
10
|
##
|
12
11
|
|
13
|
-
# features exclusive to Tv-Show
|
12
|
+
# features exclusive to Tv-Show media type
|
14
13
|
module TvShow
|
14
|
+
prepend NonInteractive
|
15
15
|
end
|
data/lib/titles/video_game.rb
CHANGED
@@ -4,18 +4,11 @@
|
|
4
4
|
##
|
5
5
|
##
|
6
6
|
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
-
### All features are available from
|
8
|
-
|
7
|
+
### All features are available from Title class
|
9
8
|
##
|
10
9
|
##
|
11
10
|
##
|
12
11
|
|
13
|
-
# features exclusive to Video Game
|
12
|
+
# features exclusive to Video Game media type
|
14
13
|
module VideoGame
|
15
|
-
# remove duration instance method as its not relevant for the game object
|
16
|
-
def self.extended(obj)
|
17
|
-
obj.class.instance_eval do
|
18
|
-
undef_method :duration
|
19
|
-
end
|
20
|
-
end
|
21
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imdb_title
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juzer Shakir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -44,46 +44,6 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 1.15.4
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: reek
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '6.1'
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 6.1.4
|
57
|
-
type: :development
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - "~>"
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '6.1'
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 6.1.4
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: standard
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '1.31'
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 1.31.1
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - "~>"
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '1.31'
|
84
|
-
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version: 1.31.1
|
87
47
|
description: |2
|
88
48
|
Extract useful information about your favorite Movies, TV shows, Episodes, or Games
|
89
49
|
with our data extraction library. All the information you need is a method call away.
|
@@ -94,6 +54,7 @@ extra_rdoc_files: []
|
|
94
54
|
files:
|
95
55
|
- lib/exceptions.rb
|
96
56
|
- lib/imdb_title.rb
|
57
|
+
- lib/non_interactive.rb
|
97
58
|
- lib/titles/episode.rb
|
98
59
|
- lib/titles/movie.rb
|
99
60
|
- lib/titles/tv_show.rb
|