KinopoiskAPI 0.8.2 → 0.9.0
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/.gitignore +2 -0
- data/README.md +164 -190
- data/lib/KinopoiskAPI.rb +66 -26
- data/lib/KinopoiskAPI/agent.rb +207 -13
- data/lib/KinopoiskAPI/api_error.rb +21 -0
- data/lib/KinopoiskAPI/category.rb +31 -0
- data/lib/KinopoiskAPI/film.rb +69 -224
- data/lib/KinopoiskAPI/film_search.rb +53 -0
- data/lib/KinopoiskAPI/global_search.rb +12 -80
- data/lib/KinopoiskAPI/people.rb +61 -0
- data/lib/KinopoiskAPI/people_search.rb +53 -0
- data/lib/KinopoiskAPI/today.rb +47 -0
- data/lib/KinopoiskAPI/top.rb +41 -0
- data/lib/KinopoiskAPI/version.rb +1 -1
- metadata +12 -8
- data/lib/KinopoiskAPI/gallery.rb +0 -38
- data/lib/KinopoiskAPI/genres.rb +0 -29
- data/lib/KinopoiskAPI/reviews.rb +0 -66
- data/lib/KinopoiskAPI/similar.rb +0 -42
- data/lib/KinopoiskAPI/staff.rb +0 -53
- data/lib/KinopoiskAPI/today_films.rb +0 -42
data/lib/KinopoiskAPI/film.rb
CHANGED
@@ -3,255 +3,100 @@ module KinopoiskAPI
|
|
3
3
|
attr_accessor :id, :url
|
4
4
|
|
5
5
|
def initialize(id)
|
6
|
-
@id
|
7
|
-
@url
|
6
|
+
@id = id.to_i
|
7
|
+
@url = "#{DOMAINS[:api]}/#{METHODS[:get_film][:method]}?#{METHODS[:get_film][:id]}=#{id}"
|
8
|
+
@url2 = "#{DOMAINS[:api]}/#{METHODS[:get_staff][:method]}?#{METHODS[:get_staff][:id]}=#{id}"
|
8
9
|
@json = json
|
9
|
-
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
title: title,
|
16
|
-
slogan: slogan,
|
17
|
-
description: description,
|
18
|
-
poster: poster,
|
19
|
-
year: year,
|
20
|
-
kinopoisk: kinopoisk,
|
21
|
-
imdb: imdb,
|
22
|
-
number_of_reviews: number_of_reviews,
|
23
|
-
duration: duration,
|
24
|
-
countries: countries,
|
25
|
-
genres: genres,
|
26
|
-
video: video,
|
27
|
-
is_sequel_or_prequel: is_sequel_or_prequel,
|
28
|
-
is_similar_films: is_similar_films,
|
29
|
-
is_imax: is_imax,
|
30
|
-
is_3d: is_3d,
|
31
|
-
rating_mpaa: rating_mpaa,
|
32
|
-
minimal_age: minimal_age,
|
33
|
-
names: all_names
|
34
|
-
}
|
11
|
+
unless status
|
12
|
+
raise APIerror.new(@json[:message], @json[:data])
|
13
|
+
end
|
14
|
+
|
35
15
|
end
|
36
16
|
|
37
|
-
def
|
38
|
-
@json
|
17
|
+
def view
|
18
|
+
film_hash(@json).merge(rating).merge(rent).merge(budget)
|
39
19
|
end
|
40
20
|
|
41
|
-
def
|
21
|
+
def rating
|
42
22
|
{
|
43
|
-
|
44
|
-
|
23
|
+
:rating_good_review => int_data('ratingData', 'ratingGoodReview', nil),
|
24
|
+
:rating_good_review_vote_count => int_data('ratingData', 'ratingGoodReviewVoteCount'),
|
25
|
+
:rating => int_data('ratingData', 'rating', nil, Float),
|
26
|
+
:rating_vote_count => int_data('ratingData', 'ratingVoteCount'),
|
27
|
+
:rating_await => int_data('ratingData', 'ratingAwait', nil),
|
28
|
+
:rating_await_count => int_data('ratingData', 'ratingAwaitCount'),
|
29
|
+
:rating_imdb => int_data('ratingData', 'ratingIMDb', nil, Float),
|
30
|
+
:rating_imdb_vote_count => int_data('ratingData', 'ratingIMDbVoteCount'),
|
31
|
+
:rating_film_critics => int_data('ratingData', 'ratingFilmCritics', nil),
|
32
|
+
:rating_film_critics_vote_count => int_data('ratingData', 'ratingFilmCriticsVoteCount'),
|
33
|
+
:rating_rf_critics => int_data('ratingData', 'ratingRFCritics', nil),
|
34
|
+
:rating_fr_critics_vote_count => int_data('ratingData', 'ratingRFCriticsVoteCount')
|
45
35
|
}
|
46
36
|
end
|
47
37
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
def year
|
61
|
-
@json['year'].present? ? @json['year'] : nil
|
62
|
-
end
|
63
|
-
|
64
|
-
def kinopoisk
|
65
|
-
if @json.present?
|
66
|
-
local_data = @json['ratingData']
|
67
|
-
|
68
|
-
if !local_data.nil?
|
69
|
-
rating = local_data['rating'].nil? ? nil : local_data['rating']
|
70
|
-
quantity = local_data['ratingVoteCount'].nil? ? nil : local_data['ratingVoteCount'].to_s.delete(' ').to_i
|
71
|
-
|
72
|
-
good_reviews_in_percentage = local_data['ratingGoodReview'].nil? ? nil : local_data['ratingGoodReview']
|
73
|
-
number_of_good_reviews = local_data['ratingGoodReviewVoteCount'].nil? ? nil : local_data['ratingGoodReviewVoteCount'].to_s.delete(' ').to_i
|
74
|
-
|
75
|
-
waiting_in_percentage = local_data['ratingAwait'].nil? ? nil : local_data['ratingAwait']
|
76
|
-
number_of_waiting = local_data['ratingAwaitCount'].nil? ? nil : local_data['ratingAwaitCount'].to_s.delete(' ').to_i
|
77
|
-
|
78
|
-
film_critics_in_percentage = local_data['ratingFilmCritics'].nil? ? nil : local_data['ratingFilmCritics']
|
79
|
-
film_critics = local_data['ratingFilmCriticsVoteCount'].nil? ? nil : local_data['ratingFilmCriticsVoteCount'].to_s.delete(' ').to_i
|
80
|
-
|
81
|
-
rf_critics_in_percentage = local_data['ratingRFCritics'].nil? ? nil : local_data['ratingRFCritics']
|
82
|
-
rf_critics = local_data['ratingRFCriticsVoteCount'].nil? ? nil : local_data['ratingRFCriticsVoteCount'].to_s.delete(' ').to_i
|
83
|
-
else
|
84
|
-
rating = 0.0
|
85
|
-
quantity = 0
|
86
|
-
|
87
|
-
good_reviews_in_percentage = '0%'
|
88
|
-
number_of_good_reviews = 0
|
89
|
-
|
90
|
-
waiting_in_percentage = '0%'
|
91
|
-
number_of_waiting = 0
|
92
|
-
|
93
|
-
film_critics_in_percentage = '0%'
|
94
|
-
film_critics = 0
|
95
|
-
|
96
|
-
rf_critics_in_percentage = '0%'
|
97
|
-
rf_critics = 0
|
98
|
-
end
|
99
|
-
|
100
|
-
{
|
101
|
-
rating: rating,
|
102
|
-
quantity: quantity,
|
103
|
-
|
104
|
-
good_reviews_in_percentage: good_reviews_in_percentage,
|
105
|
-
number_of_good_reviews: number_of_good_reviews,
|
106
|
-
|
107
|
-
waiting_in_percentage: waiting_in_percentage,
|
108
|
-
number_of_waiting: number_of_waiting,
|
109
|
-
|
110
|
-
film_critics_in_percentage: film_critics_in_percentage,
|
111
|
-
film_critics: film_critics,
|
112
|
-
|
113
|
-
rf_critics_in_percentage: rf_critics_in_percentage,
|
114
|
-
rf_critics: rf_critics
|
115
|
-
}
|
116
|
-
else
|
117
|
-
nil
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def imdb
|
122
|
-
if @json.present?
|
123
|
-
local_data = @json['ratingData']
|
124
|
-
|
125
|
-
if !local_data.nil?
|
126
|
-
rating = local_data['ratingIMDb'].nil? ? 0.0 : local_data['ratingIMDb']
|
127
|
-
quantity = local_data['ratingIMDbVoteCount'].nil? ? 0 : local_data['ratingIMDbVoteCount'].to_s.delete(' ').to_i
|
128
|
-
else
|
129
|
-
rating = 0.0
|
130
|
-
quantity = 0
|
131
|
-
end
|
132
|
-
|
133
|
-
{
|
134
|
-
id: @json['imdbID'],
|
135
|
-
rating: rating,
|
136
|
-
quantity: quantity
|
137
|
-
}
|
138
|
-
else
|
139
|
-
nil
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def number_of_reviews
|
144
|
-
@json['reviewsCount'].present? ? @json['year'] : nil
|
145
|
-
end
|
146
|
-
|
147
|
-
def duration
|
148
|
-
@json['filmLength'].present? ? @json['filmLength'] : 0
|
38
|
+
def rent
|
39
|
+
{
|
40
|
+
:distributors => str_data('rentData', 'Distributors'),
|
41
|
+
:premiere_world_country => str_data('rentData', 'premiereWorldCountry'),
|
42
|
+
:distributor_release => str_data('rentData', 'distributorRelease'),
|
43
|
+
:premiere_ru => time_data('rentData', 'premiereRU'),
|
44
|
+
:premiere_world => time_data('rentData', 'premiereWorld'),
|
45
|
+
:premiere_dvd => time_data('rentData', 'premiereDVD'),
|
46
|
+
:premiere_blu_ray => time_data('rentData', 'premiereBluRay')
|
47
|
+
}
|
149
48
|
end
|
150
49
|
|
151
|
-
def
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
nil
|
156
|
-
|
50
|
+
def budget
|
51
|
+
{
|
52
|
+
:gross_ru => int_data('budgetData', 'grossRU', nil),
|
53
|
+
:gross_usa => int_data('budgetData', 'grossUSA', nil),
|
54
|
+
:gross_world => int_data('budgetData', 'grossWorld', nil),
|
55
|
+
:budget => int_data('budgetData', 'budget', nil)
|
56
|
+
}
|
157
57
|
end
|
158
58
|
|
159
|
-
def
|
160
|
-
|
161
|
-
@json['
|
162
|
-
|
163
|
-
|
59
|
+
def peoples
|
60
|
+
unless @json['creators'].nil?
|
61
|
+
@json['creators'].map { |items|
|
62
|
+
items.map do |item|
|
63
|
+
people_hash_old(item)
|
64
|
+
end
|
65
|
+
}.flatten
|
164
66
|
end
|
165
67
|
end
|
166
68
|
|
167
|
-
def
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
def is_similar_films
|
176
|
-
@json['isHasSimilarFilms'].present? ? @json['isHasSimilarFilms'] : false
|
177
|
-
end
|
178
|
-
|
179
|
-
def is_imax
|
180
|
-
@json['isIMAX'].present? ? @json['isIMAX'] : false
|
181
|
-
end
|
182
|
-
|
183
|
-
def is_3d
|
184
|
-
@json['is3D'].present? ? @json['is3D'] : false
|
185
|
-
end
|
186
|
-
|
187
|
-
def rating_mpaa
|
188
|
-
@json['ratingMPAA'].present? ? @json['ratingMPAA'] : nil
|
189
|
-
end
|
190
|
-
|
191
|
-
def minimal_age
|
192
|
-
@json['ratingAgeLimits'].present? ? @json['ratingAgeLimits'] : 0
|
193
|
-
end
|
194
|
-
|
195
|
-
def all_names
|
196
|
-
correctly = {}
|
197
|
-
unless creators.nil?
|
198
|
-
creators.each do |items|
|
199
|
-
new_items = []
|
200
|
-
items.each do |item|
|
201
|
-
poster = item['posterURL'].present? ? "#{DOMAINS[:kinopoisk][:poster][:name]}_#{item['id']}.jpg" : nil
|
202
|
-
new_item = {
|
203
|
-
id: item['id'],
|
204
|
-
url: "#{DOMAINS[:kinopoisk][:main]}/name/#{item['id']}",
|
205
|
-
full_name: {
|
206
|
-
ru: item['nameRU'].present? ? item['nameRU'] : nil,
|
207
|
-
en: item['nameEN'].present? ? item['nameEN'] : nil
|
208
|
-
},
|
209
|
-
description: item['description'].present? ? item['description'] : nil,
|
210
|
-
poster: poster,
|
211
|
-
profession: item['professionText'].present? ? item['professionText'] : nil
|
212
|
-
}
|
213
|
-
new_items.push(new_item)
|
69
|
+
def peoples_full
|
70
|
+
json2
|
71
|
+
unless @json2['creators'].nil?
|
72
|
+
@json2['creators'].map { |items|
|
73
|
+
items.map do |item|
|
74
|
+
people_hash_old(item)
|
214
75
|
end
|
215
|
-
|
216
|
-
correctly[item['professionKey']] = new_items
|
217
|
-
end
|
218
|
-
end
|
76
|
+
}.flatten
|
219
77
|
end
|
220
|
-
correctly
|
221
|
-
end
|
222
|
-
|
223
|
-
def name_profession(name)
|
224
|
-
names[name].nil? ? nil : names[name]
|
225
78
|
end
|
226
79
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
if !local_data.nil?
|
231
|
-
ru = local_data['premiereRU'].nil? ? nil : Date.parse(local_data['premiereRU'])
|
232
|
-
world = local_data['premiereWorld'].nil? ? nil : Date.parse(local_data['premiereWorld'])
|
233
|
-
world_country = local_data['premiereWorldCountry'].nil? ? nil : local_data['premiereWorldCountry']
|
234
|
-
else
|
235
|
-
ru = nil
|
236
|
-
world = nil
|
237
|
-
world_country = nil
|
238
|
-
end
|
80
|
+
##########################
|
81
|
+
##########################
|
82
|
+
##########################
|
239
83
|
|
240
|
-
{
|
241
|
-
ru: ru,
|
242
|
-
world: world,
|
243
|
-
world_country: world_country
|
244
|
-
}
|
245
|
-
end
|
246
84
|
|
247
85
|
private
|
248
86
|
|
249
|
-
def
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
87
|
+
def people_hash_old(item)
|
88
|
+
Hash[
|
89
|
+
[
|
90
|
+
[:id, item['id'].to_i ],
|
91
|
+
[:kp_type, item['type'] ],
|
92
|
+
[:poster_url, item['posterURL'].present? ? "#{DOMAINS[:kinopoisk][:poster][:name]}_#{item['id']}.jpg" : nil],
|
93
|
+
[:name_ru, item['nameRU'] ],
|
94
|
+
[:name_en, item['nameEN'] ],
|
95
|
+
[:description, item['description'] ],
|
96
|
+
[:profession_text, item['professionText']],
|
97
|
+
[:profession_key, item['professionKey'] ]
|
98
|
+
]
|
99
|
+
]
|
255
100
|
end
|
256
101
|
|
257
102
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module KinopoiskAPI
|
2
|
+
class FilmSearch < Agent
|
3
|
+
attr_accessor :keyword, :url
|
4
|
+
|
5
|
+
def initialize(keyword)
|
6
|
+
@keyword = URI.encode(keyword)
|
7
|
+
@page = 1
|
8
|
+
gen_url
|
9
|
+
@json = json
|
10
|
+
@page_count = @json['pagesCount']
|
11
|
+
end
|
12
|
+
|
13
|
+
def films_count
|
14
|
+
@json['searchFilmsCountResult']
|
15
|
+
end
|
16
|
+
|
17
|
+
def page_count
|
18
|
+
@page_count
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_page
|
22
|
+
@current_page
|
23
|
+
end
|
24
|
+
|
25
|
+
def view
|
26
|
+
@json['searchFilms'].map do |film|
|
27
|
+
film_hash(film)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def next_page
|
32
|
+
if @page < @page_count
|
33
|
+
@page += 1
|
34
|
+
gen_url
|
35
|
+
@json = json
|
36
|
+
true
|
37
|
+
else
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def gen_url
|
45
|
+
@url = [
|
46
|
+
"#{DOMAINS[:api]}/#{METHODS[:search_film][:method]}",
|
47
|
+
"?#{METHODS[:search_film][:keyword]}=#{@keyword}",
|
48
|
+
"&#{METHODS[:search_film][:page]}=#{@page}"
|
49
|
+
].join('')
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -4,102 +4,34 @@ module KinopoiskAPI
|
|
4
4
|
|
5
5
|
def initialize(keyword)
|
6
6
|
@keyword = URI.encode(keyword)
|
7
|
-
@url
|
8
|
-
@json
|
7
|
+
@url = "#{DOMAINS[:api]}/#{METHODS[:search_global][:method]}?#{METHODS[:search_global][:keyword]}=#{@keyword}"
|
8
|
+
@json = json
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
{
|
13
|
-
keyword: keyword,
|
14
|
-
quantity: {
|
15
|
-
films: number_of_films,
|
16
|
-
names: number_of_names
|
17
|
-
},
|
18
|
-
exactly: exactly,
|
19
|
-
maybe: maybe,
|
20
|
-
names: names
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def keyword
|
25
|
-
@json['keyword']
|
26
|
-
end
|
27
|
-
|
28
|
-
def number_of_films
|
11
|
+
def films_count
|
29
12
|
@json['searchFilmsCountResult']
|
30
13
|
end
|
31
14
|
|
32
|
-
def
|
15
|
+
def names_count
|
33
16
|
@json['searchPeoplesCountResult']
|
34
17
|
end
|
35
18
|
|
36
|
-
def
|
37
|
-
|
38
|
-
id: json_exactly['id'],
|
39
|
-
title: {
|
40
|
-
ru: json_exactly['nameRU'],
|
41
|
-
en: json_exactly['nameEN']
|
42
|
-
},
|
43
|
-
info: json_exactly['description'],
|
44
|
-
duration: json_exactly['filmLength'],
|
45
|
-
year: json_exactly['year'],
|
46
|
-
countries: json_exactly['country'].split(',').map { |country| country.strip },
|
47
|
-
genres: json_exactly['genre'].split(',').map { |genre| genre.strip },
|
48
|
-
rating: json_exactly['rating'],
|
49
|
-
poster: "#{DOMAINS[:kinopoisk][:poster][:film]}_#{json_exactly['id']}.jpg"
|
50
|
-
}
|
19
|
+
def youmean
|
20
|
+
film_hash(@json['youmean'])
|
51
21
|
end
|
52
22
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
new_item = {
|
57
|
-
id: json_exactly['id'],
|
58
|
-
title: {
|
59
|
-
ru: json_exactly['nameRU'],
|
60
|
-
en: json_exactly['nameEN']
|
61
|
-
},
|
62
|
-
info: film['description'],
|
63
|
-
duration: film['filmLength'],
|
64
|
-
year: film['year'],
|
65
|
-
countries: film['country'].split(',').map { |country| country.strip },
|
66
|
-
genres: film['genre'].split(',').map { |genre| genre.strip },
|
67
|
-
poster: "#{DOMAINS[:kinopoisk][:poster][:film]}_#{film['id']}.jpg"
|
68
|
-
}
|
69
|
-
correctly.push(new_item)
|
23
|
+
def films
|
24
|
+
@json['searchFilms'].map do |film|
|
25
|
+
film_hash(film)
|
70
26
|
end
|
71
|
-
correctly
|
72
27
|
end
|
73
28
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
new_item = {
|
78
|
-
full_name: {
|
79
|
-
ru: name['nameRU'],
|
80
|
-
en: name['nameEN']
|
81
|
-
},
|
82
|
-
info: name['description'],
|
83
|
-
poster: "#{DOMAINS[:kinopoisk][:poster][:name]}_#{name['id']}.jpg"
|
84
|
-
}
|
85
|
-
correctly.push(new_item)
|
29
|
+
def peoples
|
30
|
+
json['searchPeople'].map do |name|
|
31
|
+
people_hash(name)
|
86
32
|
end
|
87
|
-
correctly
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
def json_exactly
|
93
|
-
@json['youmean']
|
94
33
|
end
|
95
34
|
|
96
|
-
def json_films
|
97
|
-
@json['searchFilms']
|
98
|
-
end
|
99
|
-
|
100
|
-
def json_names
|
101
|
-
@json['searchPeople']
|
102
|
-
end
|
103
35
|
|
104
36
|
end
|
105
37
|
end
|