kinopoisk_parser 1.0.2 → 1.0.3
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 +8 -8
- data/README.md +2 -1
- data/kinopoisk_parser.gemspec +1 -1
- data/lib/kinopoisk/movie.rb +20 -4
- data/lib/kinopoisk/person.rb +2 -2
- data/lib/kinopoisk_parser.rb +3 -2
- data/spec/kinopoisk/movie_spec.rb +43 -36
- data/spec/kinopoisk/person_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDFiMTk5NjRlZjk2Mjk1NjIyMzhkYWFmYzI2NWQyODgzNTkwOGUxNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzRmYzQxNjRhODRlNTFlNWQ0ZDE1ZTNiMDA2MzA0NjZhZGM1MGUwZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTFhZDJlMDY5MTdlMjY3NDE2YjIxMGE0MDc5NDkzYjlhN2NkOTNlYWQxNjBj
|
10
|
+
MWJjMDA3MDdhMjFlZjMwZmU1ODk5MzdjMzUwNzgyNTAxZDM1MTU0YzM4MmNi
|
11
|
+
MTExZDdmMjFlZTdiYjRlMDViMWNkYTQ3M2Q5YWEyZDQzYzE1NzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjBhNWFiZGQ2MjRiZDE5MGUwYTk5ZjFlMDZlMThkYTJjMjcyNWZjNTRjZDY3
|
14
|
+
MTc0NDhmNzkwNjAzYTFhNGJhMzA5ZDllMWE3YjhiMTk1NTY2MWIxM2NhNDhj
|
15
|
+
NDljZDZhYjBjOTM0NzU0OTVhNzJmYzk5ODZkNThlYWUzYmU1NjQ=
|
data/README.md
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
Easily search and access information on kinopoisk.ru
|
4
4
|
|
5
5
|
[](http://travis-ci.org/RavWar/kinopoisk_parser)
|
6
|
-
[](https://codeclimate.com/github/RavWar/kinopoisk_parser)
|
7
6
|
[](https://gemnasium.com/RavWar/kinopoisk_parser)
|
7
|
+
[](http://badge.fury.io/rb/kinopoisk_parser)
|
8
|
+
[](https://codeclimate.com/github/RavWar/kinopoisk_parser)
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
data/kinopoisk_parser.gemspec
CHANGED
data/lib/kinopoisk/movie.rb
CHANGED
@@ -42,15 +42,31 @@ module Kinopoisk
|
|
42
42
|
doc.search("table.info a[href*='/m_act%5Bcountry%5D/']").map(&:text)
|
43
43
|
end
|
44
44
|
|
45
|
+
def budget
|
46
|
+
doc.search("//td[text()='бюджет']/following-sibling::*//a").text
|
47
|
+
end
|
48
|
+
|
49
|
+
def gross_ru
|
50
|
+
doc.search("td#div_rus_box_td2 a").text
|
51
|
+
end
|
52
|
+
|
53
|
+
def gross_us
|
54
|
+
doc.search("td#div_usa_box_td2 a").text
|
55
|
+
end
|
56
|
+
|
57
|
+
def gross_world
|
58
|
+
doc.search("td#div_world_box_td2 a").text
|
59
|
+
end
|
60
|
+
|
45
61
|
def poster
|
46
62
|
doc.search("img[itemprop='image']").first.attr 'src'
|
47
63
|
end
|
48
64
|
|
49
|
-
def
|
65
|
+
def premiere_world
|
50
66
|
doc.search('td#div_world_prem_td2 a:first').text
|
51
67
|
end
|
52
68
|
|
53
|
-
def
|
69
|
+
def premiere_ru
|
54
70
|
doc.search('td#div_rus_prem_td2 a:first').text
|
55
71
|
end
|
56
72
|
|
@@ -63,7 +79,7 @@ module Kinopoisk
|
|
63
79
|
end
|
64
80
|
|
65
81
|
def length
|
66
|
-
doc.search('td#runtime').text
|
82
|
+
doc.search('td#runtime').text.to_i
|
67
83
|
end
|
68
84
|
|
69
85
|
def directors
|
@@ -132,7 +148,7 @@ module Kinopoisk
|
|
132
148
|
end
|
133
149
|
|
134
150
|
def search_by_text(name)
|
135
|
-
doc.search("//td[text()='#{name}']").
|
151
|
+
doc.search("//td[text()='#{name}']/following-sibling::*").text
|
136
152
|
end
|
137
153
|
|
138
154
|
def to_array(string)
|
data/lib/kinopoisk/person.rb
CHANGED
@@ -22,7 +22,7 @@ module Kinopoisk
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def partner
|
25
|
-
doc.search("//td[@class='type'][contains(text(),'супруг')]").
|
25
|
+
doc.search("//td[@class='type'][contains(text(),'супруг')]/following-sibling::*").text
|
26
26
|
end
|
27
27
|
|
28
28
|
def birthdate
|
@@ -68,7 +68,7 @@ module Kinopoisk
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def search_by_text(name)
|
71
|
-
doc.search("//td[@class='type'][text()='#{name}']").
|
71
|
+
doc.search("//td[@class='type'][text()='#{name}']/following-sibling::*").text
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
data/lib/kinopoisk_parser.rb
CHANGED
@@ -6,6 +6,7 @@ require 'kinopoisk/person'
|
|
6
6
|
|
7
7
|
module Kinopoisk
|
8
8
|
SEARCH_URL = "http://www.kinopoisk.ru/index.php?kp_query="
|
9
|
+
NotFound = Class.new StandardError
|
9
10
|
|
10
11
|
# Headers are needed to mimic proper request so kinopoisk won't block it
|
11
12
|
def self.fetch(url)
|
@@ -13,7 +14,7 @@ module Kinopoisk
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.parse(url)
|
16
|
-
|
17
|
-
|
17
|
+
p = fetch url
|
18
|
+
p.status==200 ? Nokogiri::HTML(p.body.encode('utf-8')) : raise(NotFound)
|
18
19
|
end
|
19
20
|
end
|
@@ -1,39 +1,46 @@
|
|
1
1
|
#coding: UTF-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe Kinopoisk::Movie, vcr: { cassette_name: '
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
24
|
-
it {
|
25
|
-
it {
|
26
|
-
it {
|
27
|
-
it {
|
28
|
-
it {
|
29
|
-
it {
|
30
|
-
it {
|
31
|
-
it {
|
4
|
+
describe Kinopoisk::Movie, vcr: { cassette_name: 'movies' } do
|
5
|
+
let(:dexter) { Kinopoisk::Movie.new 277537 }
|
6
|
+
let(:avatar) { Kinopoisk::Movie.new 251733 }
|
7
|
+
|
8
|
+
it { dexter.url.should eq('http://www.kinopoisk.ru/film/277537/') }
|
9
|
+
it { dexter.title.should eq('Правосудие Декстера') }
|
10
|
+
it { dexter.title_en.should eq('Dexter') }
|
11
|
+
it { dexter.countries.should eq(['США']) }
|
12
|
+
it { dexter.year.should eq(2006) }
|
13
|
+
it { dexter.poster.should eq('http://st.kinopoisk.ru/images/film/277537.jpg') }
|
14
|
+
it { dexter.poster_big.should eq('http://st.kinopoisk.ru/images/film_big/277537.jpg') }
|
15
|
+
it { dexter.producers.should eq(['Сара Коллетон','Джон Голдвин','Роберт Ллойд Льюис']) }
|
16
|
+
it { dexter.art_directors.should eq(['Джессика Кендер','Энтони Коули','Эрик Уейлер']) }
|
17
|
+
it { dexter.operators.should eq(['Ромео Тироне','Джеф Джёр','Мартин Дж. Лэйтон']) }
|
18
|
+
it { dexter.editors.should eq(['Луис Ф. Циоффи','Стюарт Шилл','Мэттью Колонна']) }
|
19
|
+
it { dexter.writers.should eq(['Джефф Линдсэй','Джеймс Манос мл.','Скотт Бак']) }
|
20
|
+
it { dexter.actors.should include('Майкл С. Холл', 'Дженнифер Карпентер') }
|
21
|
+
it { dexter.genres.should eq(['триллер','драма','криминал', 'детектив']) }
|
22
|
+
it { dexter.directors.should eq(['Джон Дал','Стив Шилл','Кит Гордон']) }
|
23
|
+
it { dexter.slogan.should eq('«Takes life. Seriously.»') }
|
24
|
+
it { dexter.description.should match('Декстер Морган.') }
|
25
|
+
it { dexter.premiere_world.should eq('1 октября 2006') }
|
26
|
+
it { dexter.premiere_ru.should eq('3 ноября 2008') }
|
27
|
+
it { dexter.composers.should eq(['Дэниэл Лихт']) }
|
28
|
+
it { dexter.imdb_rating_count.should be_a(Integer) }
|
29
|
+
it { dexter.imdb_rating.should be_a(Float) }
|
30
|
+
it { dexter.rating_count.should be_a(Integer) }
|
31
|
+
it { dexter.rating.should be_a(Float) }
|
32
|
+
it { dexter.gross_ru.should eq('') }
|
33
|
+
|
34
|
+
it { avatar.gross_world.should match('[$\d]') }
|
35
|
+
it { avatar.gross_ru.should match('[$\d]') }
|
36
|
+
it { avatar.gross_us.should match('[$\d]') }
|
37
|
+
it { avatar.budget.should eq("$237 000 000") }
|
38
|
+
it { avatar.length.should eq(162) }
|
32
39
|
|
33
40
|
it 'should make only one request' do
|
34
|
-
|
35
|
-
|
36
|
-
a_request(:get,
|
41
|
+
dexter.title
|
42
|
+
dexter.countries
|
43
|
+
a_request(:get, dexter.url).should have_been_made.once
|
37
44
|
end
|
38
45
|
|
39
46
|
it 'should raise error if nothing found' do
|
@@ -41,18 +48,18 @@ describe Kinopoisk::Movie, vcr: { cassette_name: 'movie' } do
|
|
41
48
|
end
|
42
49
|
|
43
50
|
context 'by title' do
|
44
|
-
let(:
|
51
|
+
let(:dexter_by_title) { Kinopoisk::Movie.new 'Dexter' }
|
45
52
|
|
46
|
-
it {
|
53
|
+
it { dexter.url.should eq(dexter_by_title.url) }
|
47
54
|
|
48
55
|
it 'should make only one request to initialize' do
|
49
|
-
|
56
|
+
dexter_by_title
|
50
57
|
a_request(:get, /.*/).should have_been_made.once
|
51
58
|
end
|
52
59
|
|
53
60
|
it 'should make max two requests' do
|
54
|
-
|
55
|
-
|
61
|
+
dexter_by_title.title
|
62
|
+
dexter_by_title.countries
|
56
63
|
a_request(:get, /.*/).should have_been_made.twice
|
57
64
|
end
|
58
65
|
end
|