imdb_title 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adba25559e91ab2032f64e3f05fc62a3787a05d82ba4bba789b72d7f06ad2c76
4
- data.tar.gz: 396cfdecd9b4ef7d98c92a122ff17cde27fa9db760db5547e5a666b11b328e80
3
+ metadata.gz: c93d7763c58767a3c60055a67d1d74aef8d90e9fe89cbd80a90b7105adbe0975
4
+ data.tar.gz: cf326e23a86e2dbc46c176216fff601b4f59ca0a21e58c6c1e4bc55877fd2538
5
5
  SHA512:
6
- metadata.gz: 19702e3169519da7204d57a03763a5d8c2f66f512b840e89a554a90dd14a38f7cc1b7755844eb6f3806b9efd6fa5217a1c5801c8a5c53a081c73b6902111abdb
7
- data.tar.gz: c59a7c0860725586d92599e2a76a40c89cf35ba35687ac66b5eee365ce31073521b54a1957ee25d79bb8c7a1d7bdeb2c57f530a245cd368fb39756d752206f78
6
+ metadata.gz: 02fae1cd0b1ebd2a26c7257469c45215fc1f9072e4980e6544ba1e88540ef239aa1137b1a9182c3e72795ee0e6610f2079ae5821e64b08b0aa4e244c656eb824
7
+ data.tar.gz: 31f483bb6bee4458a5897654f9f104d1b26f01d611f5226b980d3b8559567cabd50d70f8e891618739cbb047634a5e879f8e09318bc1d789f4888ebdae8f4300
data/lib/exceptions.rb CHANGED
@@ -8,5 +8,5 @@ module IMDb
8
8
  class InvalidURL < Error; end
9
9
 
10
10
  # Will raise this error if URL is UNSUPPORTED title type
11
- class UnSupportedType < InvalidURL; end
11
+ class UnSupportedMediaType < InvalidURL; end
12
12
  end
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 this directory 'lib'
8
- Dir.glob(File.join(__dir__, "**", "*.rb"), &method(:require))
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
- # Extracts common data from titles - Movie, TV-shows, Episode, Game from imdb.com
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 title_type
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"
41
+ else raise UnSupportedMediaType, "Unknown media type"
45
42
  end
46
43
  end
47
44
 
48
- # returns list of casts
45
+ # lists all top cast (Array)
49
46
  def casts
50
- split_these document.css("a[data-testid=title-cast-item__actor]").text
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
- # returns list of directors
53
+ # list of directors (Array)
54
54
  def directors
55
- html = document.css("li[data-testid=title-pc-principal-credit]")
56
- text = html.text
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
- # returns runtime of the title
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
- # returns list of genres
61
+ # list of genres (Array)
68
62
  def genres
69
- split_these document.css("div[data-testid=genres]").text
63
+ document.css("div[data-testid=genres] div a").map(&:text)
70
64
  end
71
65
 
72
- # returns a unique id set by imdb
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
- # returns number of users rated
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
- # returns list of production companies
76
+ # list of production companies (Array/String)
83
77
  def production_companies
84
- split_these document.css("li[data-testid=title-details-companies] li").text
78
+ document.css("li[data-testid=title-details-companies] li").map(&:text)
85
79
  end
86
80
 
87
- # returns user average rating score
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
- # returns release date
86
+ # the date it was release on (String)
93
87
  def release_date
94
- inspect_this document.css("li[data-testid=title-details-releasedate] div").text
88
+ document.css("li[data-testid=title-details-releasedate] div").first&.text
95
89
  end
96
90
 
97
- # returns short introduction of the title
91
+ # short introduction
98
92
  def tagline
99
- inspect_this document.css("span[data-testid=plot-xl]").text
93
+ document.css("span[data-testid=plot-xl]").first&.text
100
94
  end
101
95
 
102
- # returns name of the title
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 (dosen't return 404 Error Page)
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
- # :reek:UtilityFunction
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 & IMDb ID length and returns title page
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
@@ -4,12 +4,12 @@
4
4
  ##
5
5
  ##
6
6
  ###### ---------------- List of features/data avialable to extract -----------------------
7
- ### All features are available from Base class
8
-
7
+ ### All features are available from Title class
9
8
  ##
10
9
  ##
11
10
  ##
12
11
 
13
- # features exclusive to Episode title type
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 Base class
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 title type
15
+ # features exclusive to Movie media type
17
16
  module Movie
18
- # returns budget price of the movie
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
- # returns revenue price of the movie
24
+ # revenue / Gross Worldwide (String)
24
25
  def revenue
25
- inspect_this document.css("li[data-testid=title-boxoffice-cumulativeworldwidegross] div").text
26
+ document.css("li[data-testid=title-boxoffice-cumulativeworldwidegross] div").first&.text
26
27
  end
27
28
  end
@@ -4,12 +4,12 @@
4
4
  ##
5
5
  ##
6
6
  ###### ---------------- List of features/data avialable to extract -----------------------
7
- ### All features are available from Base class
8
-
7
+ ### All features are available from Title class
9
8
  ##
10
9
  ##
11
10
  ##
12
11
 
13
- # features exclusive to Tv-Show title type
12
+ # features exclusive to Tv-Show media type
14
13
  module TvShow
14
+ prepend NonInteractive
15
15
  end
@@ -4,18 +4,11 @@
4
4
  ##
5
5
  ##
6
6
  ###### ---------------- List of features/data avialable to extract -----------------------
7
- ### All features are available from Base class
8
-
7
+ ### All features are available from Title class
9
8
  ##
10
9
  ##
11
10
  ##
12
11
 
13
- # features exclusive to Video Game title type
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.8
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-04 00:00:00.000000000 Z
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
- Want to know everything about your favorite movies, TV shows, episodes, and games?
89
- Look no further than our data extraction tool! All the information you need such as
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: '0'
117
+ version: 2.7.0
117
118
  required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  requirements:
119
120
  - - ">="