imdb_title 0.0.2
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/lib/imdb/exceptions.rb +12 -0
- data/lib/imdb/titles/episode.rb +15 -0
- data/lib/imdb/titles/movie.rb +27 -0
- data/lib/imdb/titles/tv_show.rb +15 -0
- data/lib/imdb/titles/video_game.rb +21 -0
- data/lib/imdb.rb +148 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f2fc3cac635deca895d0d4189f92b175b023091c7e69e5fd6adb96802c6ad5a2
|
4
|
+
data.tar.gz: 949e0fc71c0ff76bf11dcf29b1770a7674c8976b8cc728dea6da89da2b60772f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa0263da758fc96f977e4b0065df386f646b1686bd96c14dfeba2f748936ef06c372ef50cf2e96f2de4749cbe99d4f691abf818d2fc99b06017f8d2c10bafeaa
|
7
|
+
data.tar.gz: 74379acd1efe8174758e61f37af49ba8733ea1abcce7dc562fbcae9c8fddd6d06fd3c5e6c94c5fdf1bd0ef20d39465b5c581ca0a01d4d259f2db78d358bbd637
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IMDb
|
4
|
+
# All custom errors will inherit from this class
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
# Will raise this error for incorrect url input
|
8
|
+
class InvalidURL < Error; end
|
9
|
+
|
10
|
+
# Will raise this error if URL is UNSUPPORTED title type
|
11
|
+
class UnSupportedType < InvalidURL; end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
##
|
5
|
+
##
|
6
|
+
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
+
### All features are available from Base class
|
8
|
+
|
9
|
+
##
|
10
|
+
##
|
11
|
+
##
|
12
|
+
|
13
|
+
# features exclusive to Episode title type
|
14
|
+
module Episode
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
##
|
5
|
+
##
|
6
|
+
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
+
### All features are available from Base class
|
8
|
+
|
9
|
+
#### ------- BOX OFFICE ---------
|
10
|
+
### 12. Budget
|
11
|
+
### 13. Gross Worldwide (Revenue)
|
12
|
+
##
|
13
|
+
##
|
14
|
+
##
|
15
|
+
|
16
|
+
# features exclusive to Movie title type
|
17
|
+
module Movie
|
18
|
+
# returns budget price of the movie
|
19
|
+
def budget
|
20
|
+
document.css("li[data-testid=title-boxoffice-budget] div").text[/\$\S+/]
|
21
|
+
end
|
22
|
+
|
23
|
+
# returns revenue price of the movie
|
24
|
+
def revenue
|
25
|
+
inspect_this document.css("li[data-testid=title-boxoffice-cumulativeworldwidegross] div").text
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
##
|
5
|
+
##
|
6
|
+
###### ---------------- List of features/data avialable to extract -----------------------
|
7
|
+
### All features are available from Base class
|
8
|
+
|
9
|
+
##
|
10
|
+
##
|
11
|
+
##
|
12
|
+
|
13
|
+
# features exclusive to Tv-Show title type
|
14
|
+
module TvShow
|
15
|
+
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 Base class
|
8
|
+
|
9
|
+
##
|
10
|
+
##
|
11
|
+
##
|
12
|
+
|
13
|
+
# features exclusive to Video Game title type
|
14
|
+
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
|
+
end
|
data/lib/imdb.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "require_all"
|
4
|
+
require "nokogiri"
|
5
|
+
require "httparty"
|
6
|
+
require_all "lib/imdb/"
|
7
|
+
|
8
|
+
##
|
9
|
+
##
|
10
|
+
##
|
11
|
+
###### ---------------- List of features/data avialable to extract -----------------------
|
12
|
+
### 1. Cast
|
13
|
+
### 2. Director
|
14
|
+
### 3. Genres
|
15
|
+
### 4. IMDb ID
|
16
|
+
### 5. Popularity
|
17
|
+
### 6. Ratings
|
18
|
+
### 7. Title
|
19
|
+
### 8. Tagline
|
20
|
+
#### ------- DETAILS ---------
|
21
|
+
### 9. Prodcution Companies
|
22
|
+
### 10. Release Date
|
23
|
+
#### ------- TECHNICAL SPECS ---------
|
24
|
+
### 11. Runtime
|
25
|
+
##
|
26
|
+
##
|
27
|
+
##
|
28
|
+
|
29
|
+
# :reek:TooManyMethods
|
30
|
+
module IMDb
|
31
|
+
# Extracts common data from titles - Movie, TV-shows, Episode, Game from imdb.com
|
32
|
+
class Title
|
33
|
+
# pass valid imdb title url
|
34
|
+
def initialize(url)
|
35
|
+
raise InvalidURL, "Please input a valid IMDb URL" unless valid?(url)
|
36
|
+
|
37
|
+
case title_type
|
38
|
+
when "video.movie" then extend Movie
|
39
|
+
when "video.tv_show" then extend TvShow
|
40
|
+
when "video.episode" then extend Episode
|
41
|
+
when "video.other" then extend VideoGame
|
42
|
+
else raise UnSupportedTypeError, "Unknown title type"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# returns list of casts
|
47
|
+
def casts
|
48
|
+
split_these document.css("a[data-testid=title-cast-item__actor]").text
|
49
|
+
end
|
50
|
+
|
51
|
+
# returns list of directors
|
52
|
+
def directors
|
53
|
+
html = document.css("li[data-testid=title-pc-principal-credit]")
|
54
|
+
text = html.text
|
55
|
+
return unless text.include? "Director"
|
56
|
+
|
57
|
+
split_these html.css("ul").first.text
|
58
|
+
end
|
59
|
+
|
60
|
+
# returns runtime of the title
|
61
|
+
def duration
|
62
|
+
inspect_this document.css("li[data-testid=title-techspec_runtime] div").text
|
63
|
+
end
|
64
|
+
|
65
|
+
# returns list of genres
|
66
|
+
def genres
|
67
|
+
split_these document.css("div[data-testid=genres]").text
|
68
|
+
end
|
69
|
+
|
70
|
+
# returns a unique id set by imdb
|
71
|
+
def imdb_id
|
72
|
+
document.css("meta[property*=pageConst]").attribute("content").value
|
73
|
+
end
|
74
|
+
|
75
|
+
# returns number of users rated
|
76
|
+
def popularity
|
77
|
+
document.css("div[data-testid=hero-rating-bar__aggregate-rating] span div").last&.text
|
78
|
+
end
|
79
|
+
|
80
|
+
# returns list of production companies
|
81
|
+
def production_companies
|
82
|
+
split_these document.css("li[data-testid=title-details-companies] li").text
|
83
|
+
end
|
84
|
+
|
85
|
+
# returns user average rating score
|
86
|
+
def ratings
|
87
|
+
document.css("div[data-testid=hero-rating-bar__aggregate-rating__score] span").first&.text
|
88
|
+
end
|
89
|
+
|
90
|
+
# returns release date
|
91
|
+
def release_date
|
92
|
+
inspect_this document.css("li[data-testid=title-details-releasedate] div").text
|
93
|
+
end
|
94
|
+
|
95
|
+
# returns short introduction of the title
|
96
|
+
def tagline
|
97
|
+
inspect_this document.css("span[data-testid=plot-xl]").text
|
98
|
+
end
|
99
|
+
|
100
|
+
# returns name of the title
|
101
|
+
def title
|
102
|
+
document.css("h1").text
|
103
|
+
end
|
104
|
+
|
105
|
+
def url
|
106
|
+
document.css("meta[property*=url]").attribute("content").value
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
attr_reader :document
|
112
|
+
|
113
|
+
# checks IMDb id from URL (dosen't return 404 Error Page)
|
114
|
+
def correct_id?(url)
|
115
|
+
response = HTTParty.get(url, {headers: {"User-Agent" => "Httparty"}})
|
116
|
+
@document = Nokogiri::HTML(response.body)
|
117
|
+
document.title != "404 Error - IMDb"
|
118
|
+
end
|
119
|
+
|
120
|
+
# :reek:UtilityFunction
|
121
|
+
# returns proper output
|
122
|
+
def inspect_this(input)
|
123
|
+
if input.empty?
|
124
|
+
nil
|
125
|
+
elsif input.length == 1
|
126
|
+
input.join
|
127
|
+
else
|
128
|
+
input
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# spilits camel case names to array
|
133
|
+
def split_these(names)
|
134
|
+
list = names.split(/(?<=[a-z)])(?=[A-Z])/)
|
135
|
+
inspect_this(list)
|
136
|
+
end
|
137
|
+
|
138
|
+
# returns type of title
|
139
|
+
def title_type
|
140
|
+
document.css("meta[property*=type]").attribute("content").value
|
141
|
+
end
|
142
|
+
|
143
|
+
# validates domain name, slug & IMDb ID length and returns title page
|
144
|
+
def valid?(url)
|
145
|
+
url.match?("https://www.imdb.com/title/tt#{/\d+{7,}/i}") && correct_id?(url)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imdb_title
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juzer Shakir
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.21.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.21.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.15.4
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.15'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.15.4
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: require_all
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: reek
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '6.1'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 6.1.4
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '6.1'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 6.1.4
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: standard
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.31'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.31.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.31'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.31.1
|
101
|
+
description: |2
|
102
|
+
Want to know everything about your favorite movies, TV shows, episodes, and games?
|
103
|
+
Look no further than our data extraction tool! All the information you need such as
|
104
|
+
title, tagline, ratings, casts, productions, etc will be a method call away.
|
105
|
+
email: juzershakir.webdev@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- lib/imdb.rb
|
111
|
+
- lib/imdb/exceptions.rb
|
112
|
+
- lib/imdb/titles/episode.rb
|
113
|
+
- lib/imdb/titles/movie.rb
|
114
|
+
- lib/imdb/titles/tv_show.rb
|
115
|
+
- lib/imdb/titles/video_game.rb
|
116
|
+
homepage: https://github.com/JuzerShakir/imdb
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
- GPL-2.0
|
120
|
+
metadata:
|
121
|
+
source_code_uri: https://github.com/JuzerShakir/imdb
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubygems_version: 3.4.20
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Access info of any Movie, Tv Show, Episode or Game from imdb.com
|
141
|
+
test_files: []
|