imdb_title 0.0.8 → 0.0.10
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 +4 -4
- data/lib/exceptions.rb +1 -1
- data/lib/imdb_title.rb +31 -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 +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c93d7763c58767a3c60055a67d1d74aef8d90e9fe89cbd80a90b7105adbe0975
|
4
|
+
data.tar.gz: cf326e23a86e2dbc46c176216fff601b4f59ca0a21e58c6c1e4bc55877fd2538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02fae1cd0b1ebd2a26c7257469c45215fc1f9072e4980e6544ba1e88540ef239aa1137b1a9182c3e72795ee0e6610f2079ae5821e64b08b0aa4e244c656eb824
|
7
|
+
data.tar.gz: 31f483bb6bee4458a5897654f9f104d1b26f01d611f5226b980d3b8559567cabd50d70f8e891618739cbb047634a5e879f8e09318bc1d789f4888ebdae8f4300
|
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,82 @@ Dir.glob(File.join(__dir__, "**", "*.rb"), &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
|
41
|
+
else raise UnSupportedMediaType, "Unknown media type"
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
48
|
-
#
|
45
|
+
# lists all top cast (Array)
|
49
46
|
def casts
|
50
|
-
|
47
|
+
html = document.css("a[data-testid=title-cast-item__actor]")
|
48
|
+
return if html.empty?
|
49
|
+
|
50
|
+
html.map(&:text)
|
51
51
|
end
|
52
52
|
|
53
|
-
#
|
53
|
+
# list of directors (Array)
|
54
54
|
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
|
55
|
+
html = document.css("li[data-testid=title-pc-principal-credit]").first
|
56
|
+
return unless html.text.include? "Director"
|
61
57
|
|
62
|
-
|
63
|
-
def duration
|
64
|
-
inspect_this document.css("li[data-testid=title-techspec_runtime] div").text
|
58
|
+
html.css("div li").map(&:text)
|
65
59
|
end
|
66
60
|
|
67
|
-
#
|
61
|
+
# list of genres (Array)
|
68
62
|
def genres
|
69
|
-
|
63
|
+
document.css("div[data-testid=genres] div a").map(&:text)
|
70
64
|
end
|
71
65
|
|
72
|
-
#
|
66
|
+
# ID that differentiates each media type on imdb.com (String)
|
73
67
|
def imdb_id
|
74
68
|
document.css("meta[property*=pageConst]").attribute("content").value
|
75
69
|
end
|
76
70
|
|
77
|
-
#
|
71
|
+
# number of users rated (String)
|
78
72
|
def popularity
|
79
73
|
document.css("div[data-testid=hero-rating-bar__aggregate-rating] span div").last&.text
|
80
74
|
end
|
81
75
|
|
82
|
-
#
|
76
|
+
# list of production companies (Array/String)
|
83
77
|
def production_companies
|
84
|
-
|
78
|
+
document.css("li[data-testid=title-details-companies] li").map(&:text)
|
85
79
|
end
|
86
80
|
|
87
|
-
#
|
81
|
+
# average ratings (String)
|
88
82
|
def ratings
|
89
83
|
document.css("div[data-testid=hero-rating-bar__aggregate-rating__score] span").first&.text
|
90
84
|
end
|
91
85
|
|
92
|
-
#
|
86
|
+
# the date it was release on (String)
|
93
87
|
def release_date
|
94
|
-
|
88
|
+
document.css("li[data-testid=title-details-releasedate] div").first&.text
|
95
89
|
end
|
96
90
|
|
97
|
-
#
|
91
|
+
# short introduction
|
98
92
|
def tagline
|
99
|
-
|
93
|
+
document.css("span[data-testid=plot-xl]").first&.text
|
100
94
|
end
|
101
95
|
|
102
|
-
#
|
96
|
+
# name or title
|
103
97
|
def title
|
104
98
|
document.css("h1").text
|
105
99
|
end
|
106
100
|
|
101
|
+
# full url
|
107
102
|
def url
|
108
103
|
document.css("meta[property*=url]").attribute("content").value
|
109
104
|
end
|
@@ -112,37 +107,18 @@ module IMDb
|
|
112
107
|
|
113
108
|
attr_reader :document
|
114
109
|
|
115
|
-
# checks IMDb id from URL (
|
110
|
+
# checks IMDb id from URL (should not return 404 Error Page)
|
116
111
|
def correct_id?(url)
|
117
112
|
response = HTTParty.get(url, {headers: {"User-Agent" => "Httparty"}})
|
118
113
|
@document = Nokogiri::HTML(response.body)
|
119
114
|
document.title != "404 Error - IMDb"
|
120
115
|
end
|
121
116
|
|
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
|
117
|
+
def media_type
|
142
118
|
document.css("meta[property*=type]").attribute("content").value
|
143
119
|
end
|
144
120
|
|
145
|
-
# validates domain name, slug
|
121
|
+
# validates domain name, slug, IMDb ID & its length
|
146
122
|
def valid?(url)
|
147
123
|
url.match?("https://www.imdb.com/title/tt#{/\d+{7,}/i}") && correct_id?(url)
|
148
124
|
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.10
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -85,9 +85,8 @@ dependencies:
|
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: 1.31.1
|
87
87
|
description: |2
|
88
|
-
|
89
|
-
|
90
|
-
title, tagline, ratings, casts, productions, etc will be a method call away.
|
88
|
+
Extract useful information about your favorite Movies, TV shows, Episodes, or Games
|
89
|
+
with our data extraction library. All the information you need is a method call away.
|
91
90
|
email: juzershakir.webdev@gmail.com
|
92
91
|
executables: []
|
93
92
|
extensions: []
|
@@ -95,6 +94,7 @@ extra_rdoc_files: []
|
|
95
94
|
files:
|
96
95
|
- lib/exceptions.rb
|
97
96
|
- lib/imdb_title.rb
|
97
|
+
- lib/non_interactive.rb
|
98
98
|
- lib/titles/episode.rb
|
99
99
|
- lib/titles/movie.rb
|
100
100
|
- lib/titles/tv_show.rb
|
@@ -102,9 +102,10 @@ files:
|
|
102
102
|
homepage: https://github.com/JuzerShakir/imdb
|
103
103
|
licenses:
|
104
104
|
- MIT
|
105
|
-
- GPL-2.0
|
106
105
|
metadata:
|
107
106
|
source_code_uri: https://github.com/JuzerShakir/imdb
|
107
|
+
changelog_uri: https://github.com/JuzerShakir/imdb/CHANGELOG.md
|
108
|
+
bug_tracker_uri: https://github.com/JuzerShakir/imdb/Issues
|
108
109
|
post_install_message:
|
109
110
|
rdoc_options: []
|
110
111
|
require_paths:
|
@@ -113,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
114
|
requirements:
|
114
115
|
- - ">="
|
115
116
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
117
|
+
version: 2.7.0
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
requirements:
|
119
120
|
- - ">="
|