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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f44608ead04c5297b68d40fb20f21a9b901b14d0858e39d67564298887ac15e
4
- data.tar.gz: 0f49f0182eada0524d13eefe73eef7c073e0c6ab99a678b781db41a9e7643868
3
+ metadata.gz: d800873fb8e5ce95526320f79336bf3ddee8ba46646f7fb92964f73ea4273cf4
4
+ data.tar.gz: 5c4e4147d480b343bcc64f46ba60dd70bf277fd114f3a54673d73aeea54d40b7
5
5
  SHA512:
6
- metadata.gz: bf11fcede9ae7f8aac511843a9b6a0c0548032674ca20fcce190327140913412fdc38601b05fa24c9d3915597eecacc86530bb993543412b0f8500563ff8273d
7
- data.tar.gz: f48939fae4617ae808c765dc5d4026c65c683eaee22ef2e287138315f404c016ca0dd3de845653d1b6c2e4c752699a2df36e92353d6c4dee77e79ba93a1f338e
6
+ metadata.gz: 99e7b36f91aab41560f6a788ee59668cadcb79f57a58202041649ae40abfd8fe89e0d2c415622ec3cd2afc02fc8fdda0d98a98c2cbdd34d09484ec35f029f045
7
+ data.tar.gz: c67c2ca7d45a26610269c61b81166849f26b1f9768f90bcc47722ec50b4e4f0e722bd548e3c569b2e170adc37572177e58a966016f19ee85c3bfc8f064c251fc
data/lib/exceptions.rb CHANGED
@@ -6,7 +6,4 @@ module IMDb
6
6
 
7
7
  # Will raise this error for incorrect url input
8
8
  class InvalidURL < Error; end
9
-
10
- # Will raise this error if URL is UNSUPPORTED title type
11
- class UnSupportedType < InvalidURL; end
12
9
  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")).sort.each(&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,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
- # 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"
45
41
  end
46
42
  end
47
43
 
48
- # returns list of casts
44
+ # lists all top cast (Array)
49
45
  def casts
50
- split_these document.css("a[data-testid=title-cast-item__actor]").text
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
- # returns list of directors
52
+ # list of directors (Array)
54
53
  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
54
+ html = document.css("li[data-testid=title-pc-principal-credit]").first
55
+ return unless html.text.match?(/Director|Creator/)
61
56
 
62
- # returns runtime of the title
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
- # returns list of genres
60
+ # list of genres (Array)
68
61
  def genres
69
- split_these document.css("div[data-testid=genres]").text
62
+ document.css("div[data-testid=genres] div a").map(&:text)
70
63
  end
71
64
 
72
- # returns a unique id set by imdb
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
- # returns number of users rated
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
- # returns list of production companies
75
+ # list of production companies (Array/String)
83
76
  def production_companies
84
- split_these document.css("li[data-testid=title-details-companies] li").text
77
+ document.css("li[data-testid=title-details-companies] li").map(&:text)
85
78
  end
86
79
 
87
- # returns user average rating score
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
- # returns release date
85
+ # the date it was release on (String)
93
86
  def release_date
94
- inspect_this document.css("li[data-testid=title-details-releasedate] div").text
87
+ document.css("li[data-testid=title-details-releasedate] div").first&.text
95
88
  end
96
89
 
97
- # returns short introduction of the title
90
+ # short introduction
98
91
  def tagline
99
- inspect_this document.css("span[data-testid=plot-xl]").text
92
+ document.css("span[data-testid=plot-xl]").first&.text
100
93
  end
101
94
 
102
- # returns name of the title
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 (dosen't return 404 Error Page)
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
- # :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
116
+ def media_type
142
117
  document.css("meta[property*=type]").attribute("content").value
143
118
  end
144
119
 
145
- # validates domain name, slug & IMDb ID length and returns title page
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
@@ -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.9
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-05 00:00:00.000000000 Z
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