cine-passion 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/lib/cine_passion.rb +91 -55
- data/test/test_cine_passion.rb +86 -17
- metadata +5 -5
data/History.txt
CHANGED
@@ -4,9 +4,15 @@
|
|
4
4
|
|
5
5
|
* Yes!
|
6
6
|
|
7
|
-
|
8
7
|
=== 0.6.0 / 2010-08-27
|
9
8
|
|
10
9
|
* Have demo mode
|
11
10
|
|
12
11
|
* If you have'nt configure package, you are in a demo mode
|
12
|
+
|
13
|
+
=== 0.7.0 / 2010-08-30
|
14
|
+
|
15
|
+
* Extract all movies from XML
|
16
|
+
|
17
|
+
* Extract all movies from XML
|
18
|
+
* Movie can have'nt pictures
|
data/lib/cine_passion.rb
CHANGED
@@ -32,10 +32,18 @@ rescue LoadError => load_error
|
|
32
32
|
puts '*'*50
|
33
33
|
end
|
34
34
|
|
35
|
+
if not (defined? SITEURL || (not SITEURL.nil?))
|
36
|
+
raise 'Need to define SITEURL'
|
37
|
+
end
|
38
|
+
|
39
|
+
if not (defined? APIKEY || (not APIKEY.nil?))
|
40
|
+
raise 'Need to define APIKEY'
|
41
|
+
end
|
42
|
+
|
35
43
|
class CinePassion
|
36
|
-
attr_reader :xml_data, :
|
44
|
+
attr_reader :xml_data, :movies_info, :result_nb, :status, :quota
|
37
45
|
|
38
|
-
VERSION = '0.
|
46
|
+
VERSION = '0.7.0'
|
39
47
|
|
40
48
|
# This class does not require parameters
|
41
49
|
# First action is reset object
|
@@ -76,19 +84,7 @@ class CinePassion
|
|
76
84
|
|
77
85
|
# Explore XML data to extract informations
|
78
86
|
# At this time the class get there informations:
|
79
|
-
# * Movie
|
80
|
-
# - id
|
81
|
-
# - id_allocine
|
82
|
-
# - id_imdb
|
83
|
-
# - last_change
|
84
|
-
# - url
|
85
|
-
# - title
|
86
|
-
# - originaltitle
|
87
|
-
# - year
|
88
|
-
# - runtime
|
89
|
-
# - plot
|
90
|
-
# - images => TODO
|
91
|
-
# - ratings
|
87
|
+
# * Movie -> See ScrapAnalyseOneMovie function
|
92
88
|
# * Quota
|
93
89
|
# - authorize
|
94
90
|
# - use
|
@@ -97,17 +93,18 @@ class CinePassion
|
|
97
93
|
@result = {}
|
98
94
|
@line = ""
|
99
95
|
@result['status'] = 0
|
100
|
-
@movie_info = {}
|
101
96
|
@result_nb = 0
|
102
97
|
@quota = {}
|
98
|
+
@movies_info = []
|
103
99
|
|
104
100
|
doc = Document.new(@xml_data)
|
105
101
|
root = doc.root
|
106
102
|
|
107
|
-
|
108
|
-
|
109
|
-
@
|
110
|
-
|
103
|
+
@movies_info = []
|
104
|
+
root.each_element('movie') do |movie|
|
105
|
+
@movies_info.push ScrapAnalyseOneMovie(movie)
|
106
|
+
end
|
107
|
+
@result_nb = @movies_info.count()
|
111
108
|
|
112
109
|
if @result_nb == 0
|
113
110
|
@status = 0
|
@@ -116,40 +113,12 @@ class CinePassion
|
|
116
113
|
elsif @result_nb > 1
|
117
114
|
@status = 2
|
118
115
|
end
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
@movie_info['url'] = root.elements['movie'].elements['url'].text
|
126
|
-
@movie_info['title'] = root.elements['movie'].elements['title'].text
|
127
|
-
@movie_info['originaltitle'] = root.elements['movie'].elements['originaltitle'].text
|
128
|
-
@movie_info['year'] = root.elements['movie'].elements['year'].text
|
129
|
-
@movie_info['runtime'] = root.elements['movie'].elements['runtime'].text
|
130
|
-
@movie_info['plot'] = root.elements['movie'].elements['plot'].text
|
131
|
-
@movie_info['images'] = []
|
132
|
-
|
133
|
-
@movie_info['ratings'] = {}
|
134
|
-
@movie_info['ratings']['cinepassion'] = {}
|
135
|
-
@movie_info['ratings']['allocine'] = {}
|
136
|
-
@movie_info['ratings']['imdb'] = {}
|
137
|
-
ratings = root.elements['movie'].elements["ratings"]
|
138
|
-
ratings_cinepassion = ratings.elements["rating[@type='cinepassion']"]
|
139
|
-
@movie_info['ratings']['cinepassion']['votes'] = ratings_cinepassion.attributes['votes']
|
140
|
-
@movie_info['ratings']['cinepassion']['value'] = ratings_cinepassion.text
|
141
|
-
ratings_allocine = ratings.elements["rating[@type='allocine']"]
|
142
|
-
@movie_info['ratings']['allocine']['votes'] = ratings_allocine.attributes['votes']
|
143
|
-
@movie_info['ratings']['allocine']['value'] = ratings_allocine.text
|
144
|
-
ratings_imdb = ratings.elements["rating[@type='imdb']"]
|
145
|
-
@movie_info['ratings']['imdb']['votes'] = ratings_imdb.attributes['votes']
|
146
|
-
@movie_info['ratings']['imdb']['value'] = ratings_imdb.text
|
147
|
-
end
|
148
|
-
|
149
|
-
if @status > 0
|
150
|
-
@quota['authorize'] = root.elements['quota'].attributes['authorize']
|
151
|
-
@quota['use'] = root.elements['quota'].attributes['use']
|
152
|
-
@quota['reset_date'] = root.elements['quota'].attributes['reset_date']
|
116
|
+
|
117
|
+
quota = root.elements['quota']
|
118
|
+
if not quota.nil?
|
119
|
+
@quota['authorize'] = quota.attributes['authorize']
|
120
|
+
@quota['use'] = quota.attributes['use']
|
121
|
+
@quota['reset_date'] = quota.attributes['reset_date']
|
153
122
|
end
|
154
123
|
|
155
124
|
@result['quota'] = @quota
|
@@ -157,11 +126,78 @@ class CinePassion
|
|
157
126
|
@result['line'] = @line
|
158
127
|
@result['xml'] = doc.root
|
159
128
|
@result['status'] = @status
|
160
|
-
@result['
|
129
|
+
@result['movies_info'] = @movies_info
|
161
130
|
|
162
131
|
return @result
|
163
132
|
end
|
164
133
|
|
134
|
+
# * Movie
|
135
|
+
# - id
|
136
|
+
# - id_allocine
|
137
|
+
# - id_imdb
|
138
|
+
# - last_change
|
139
|
+
# - url
|
140
|
+
# - title
|
141
|
+
# - originaltitle
|
142
|
+
# - year
|
143
|
+
# - runtime
|
144
|
+
# - plot
|
145
|
+
# - images
|
146
|
+
# - ratings
|
147
|
+
def ScrapAnalyseOneMovie(oneMovieXML)
|
148
|
+
movie_info = {}
|
149
|
+
|
150
|
+
movie_info['id'] = oneMovieXML.elements['id'].text
|
151
|
+
movie_info['id_allocine'] = oneMovieXML.elements['id_allocine'].text
|
152
|
+
movie_info['id_imdb'] = oneMovieXML.elements['id_imdb'].text
|
153
|
+
movie_info['last_change'] = oneMovieXML.elements['last_change'].text
|
154
|
+
movie_info['url'] = oneMovieXML.elements['url'].text
|
155
|
+
movie_info['title'] = oneMovieXML.elements['title'].text
|
156
|
+
movie_info['originaltitle'] = oneMovieXML.elements['originaltitle'].text
|
157
|
+
movie_info['year'] = oneMovieXML.elements['year'].text
|
158
|
+
movie_info['runtime'] = oneMovieXML.elements['runtime'].text
|
159
|
+
movie_info['plot'] = oneMovieXML.elements['plot'].text
|
160
|
+
|
161
|
+
movie_info['images'] = {}
|
162
|
+
images = oneMovieXML.elements["images"]
|
163
|
+
if not images.nil?
|
164
|
+
images.each_element("image") do |image|
|
165
|
+
img_id = image.attributes['id']
|
166
|
+
img_size = image.attributes['size']
|
167
|
+
|
168
|
+
if not movie_info['images'].has_key? img_id
|
169
|
+
movie_info['images'][img_id] = {}
|
170
|
+
end
|
171
|
+
|
172
|
+
movie_info['images'][img_id]['type'] = image.attributes['type']
|
173
|
+
if not movie_info['images'][img_id].has_key? img_size
|
174
|
+
movie_info['images'][img_id][img_size] = {}
|
175
|
+
end
|
176
|
+
movie_info['images'][img_id][img_size]['url'] = image.attributes['url']
|
177
|
+
movie_info['images'][img_id][img_size]['width'] = image.attributes['width']
|
178
|
+
movie_info['images'][img_id][img_size]['height'] = image.attributes['height']
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
movie_info['ratings'] = {}
|
183
|
+
movie_info['ratings']['cinepassion'] = {}
|
184
|
+
movie_info['ratings']['allocine'] = {}
|
185
|
+
movie_info['ratings']['imdb'] = {}
|
186
|
+
ratings = oneMovieXML.elements["ratings"]
|
187
|
+
ratings_cinepassion = ratings.elements["rating[@type='cinepassion']"]
|
188
|
+
movie_info['ratings']['cinepassion']['votes'] = ratings_cinepassion.attributes['votes']
|
189
|
+
movie_info['ratings']['cinepassion']['value'] = ratings_cinepassion.text
|
190
|
+
ratings_allocine = ratings.elements["rating[@type='allocine']"]
|
191
|
+
movie_info['ratings']['allocine']['votes'] = ratings_allocine.attributes['votes']
|
192
|
+
movie_info['ratings']['allocine']['value'] = ratings_allocine.text
|
193
|
+
ratings_imdb = ratings.elements["rating[@type='imdb']"]
|
194
|
+
movie_info['ratings']['imdb']['votes'] = ratings_imdb.attributes['votes']
|
195
|
+
movie_info['ratings']['imdb']['value'] = ratings_imdb.text
|
196
|
+
|
197
|
+
return movie_info
|
198
|
+
end
|
199
|
+
|
200
|
+
|
165
201
|
# Scrap get a filename with garbage information & clean it
|
166
202
|
def Scrap(search)
|
167
203
|
short_name = search.gsub(/\./, ' ')
|
data/test/test_cine_passion.rb
CHANGED
@@ -53,33 +53,102 @@ class TestCinePassion < Test::Unit::TestCase
|
|
53
53
|
@test.DataLoadFromFile("test/data/cinepassion-scraper-test-01-one-response.xml")
|
54
54
|
assert_not_equal(@test.xml_data, "")
|
55
55
|
assert_equal(@test.result_nb, 1)
|
56
|
-
assert_equal(@test.
|
57
|
-
assert_equal(@test.
|
58
|
-
assert_equal(@test.
|
59
|
-
assert_equal(@test.
|
60
|
-
assert_equal(@test.
|
61
|
-
assert_equal(@test.
|
62
|
-
assert_equal(@test.
|
63
|
-
assert_equal(@test.
|
64
|
-
assert_equal(@test.
|
65
|
-
assert_equal(@test.
|
66
|
-
|
67
|
-
assert_equal(@test.
|
68
|
-
assert_equal(@test.
|
69
|
-
assert_equal(@test.
|
70
|
-
assert_equal(@test.
|
71
|
-
assert_equal(@test.
|
56
|
+
assert_equal(@test.movies_info[0]['id'], "136356")
|
57
|
+
assert_equal(@test.movies_info[0]['id_allocine'], "136356")
|
58
|
+
assert_equal(@test.movies_info[0]['id_imdb'], "1234548")
|
59
|
+
assert_equal(@test.movies_info[0]['last_change'], "1279466676")
|
60
|
+
assert_equal(@test.movies_info[0]['url'], "http://passion-xbmc.org/scraper/index2.php?Page=ViewMovie&ID=136356")
|
61
|
+
assert_equal(@test.movies_info[0]['title'], "Les Chèvres du Pentagone")
|
62
|
+
assert_equal(@test.movies_info[0]['originaltitle'], "The Men Who Stare at Goats")
|
63
|
+
assert_equal(@test.movies_info[0]['year'], "2009")
|
64
|
+
assert_equal(@test.movies_info[0]['runtime'], "90")
|
65
|
+
assert_equal(@test.movies_info[0]['plot'], "Bob Wilton, un journaliste désespéré fait l'heureuse rencontre de Lyn Cassady, un soldat aux pouvoirs paranormaux combattant le terrorisme. Ils se rendent ensemble en Irak ou ils rencontrent Bill Django, le fondateur de l'unité, et Larry Hooper, soldat de l'unité qui dirige une prison.")
|
66
|
+
|
67
|
+
assert_equal(@test.movies_info[0]['images']['311335']['type'], "Poster")
|
68
|
+
assert_equal(@test.movies_info[0]['images']['311335']['original']['height'], "2716")
|
69
|
+
assert_equal(@test.movies_info[0]['images']['311335']['original']['width'], "2000")
|
70
|
+
assert_equal(@test.movies_info[0]['images']['311335']['original']['url'], "http://passion-xbmc.org/scraper/Gallery/main/Poster_LesChvresduPentagone-311335.jpg")
|
71
|
+
assert_equal(@test.movies_info[0]['images']['311335']['preview']['url'], "http://passion-xbmc.org/scraper/Gallery/preview/Poster_LesChvresduPentagone-311335.jpg")
|
72
|
+
assert_equal(@test.movies_info[0]['images']['311335']['thumb']['url'], "http://passion-xbmc.org/scraper/Gallery/thumb/Poster_LesChvresduPentagone-311335.jpg")
|
73
|
+
|
74
|
+
assert_equal(@test.movies_info[0]['images']['316672']['type'], "Fanart")
|
75
|
+
assert_equal(@test.movies_info[0]['images']['316672']['original']['height'], "1080")
|
76
|
+
assert_equal(@test.movies_info[0]['images']['316672']['original']['width'], "1920")
|
77
|
+
assert_equal(@test.movies_info[0]['images']['316672']['original']['url'], "http://passion-xbmc.org/scraper/Gallery/main/Fanart_LesChvresduPentagone-316672.jpg")
|
78
|
+
assert_equal(@test.movies_info[0]['images']['316672']['preview']['url'], "http://passion-xbmc.org/scraper/Gallery/preview/Fanart_LesChvresduPentagone-316672.jpg")
|
79
|
+
assert_equal(@test.movies_info[0]['images']['316672']['thumb']['url'], "http://passion-xbmc.org/scraper/Gallery/thumb/Fanart_LesChvresduPentagone-316672.jpg")
|
80
|
+
|
81
|
+
assert_equal(@test.movies_info[0]['ratings']['cinepassion']['votes'], "1")
|
82
|
+
assert_equal(@test.movies_info[0]['ratings']['cinepassion']['value'], "7")
|
83
|
+
assert_equal(@test.movies_info[0]['ratings']['allocine']['votes'], "1603")
|
84
|
+
assert_equal(@test.movies_info[0]['ratings']['allocine']['value'], "2,5")
|
85
|
+
assert_equal(@test.movies_info[0]['ratings']['imdb']['votes'], "30695")
|
86
|
+
assert_equal(@test.movies_info[0]['ratings']['imdb']['value'], "6,4")
|
72
87
|
|
73
88
|
# Quota extraction
|
74
89
|
assert_equal(@test.quota['authorize'], "300")
|
75
90
|
assert_equal(@test.quota['use'], "1")
|
76
91
|
assert_equal(@test.quota['reset_date'], "2010-08-04 12:45:26")
|
77
92
|
|
78
|
-
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_xml_load_data_multiple_movies
|
96
|
+
@test = CinePassion.new
|
79
97
|
@test.DataLoadFromFile("test/data/cinepassion-scraper-test-02-mutiple-response.xml")
|
98
|
+
|
99
|
+
# Quota extraction
|
80
100
|
assert_not_equal(@test.xml_data, "")
|
101
|
+
|
102
|
+
assert_equal(@test.result_nb, 20)
|
103
|
+
|
104
|
+
assert_equal(@test.movies_info[0]['id'], "128179")
|
105
|
+
assert_equal(@test.movies_info[0]['id_allocine'], "128179")
|
106
|
+
assert_equal(@test.movies_info[0]['id_imdb'], "1014762")
|
107
|
+
assert_equal(@test.movies_info[0]['last_change'], "1279466610")
|
108
|
+
|
109
|
+
assert_equal(@test.movies_info[1]['id'], "125081")
|
110
|
+
assert_equal(@test.movies_info[1]['id_allocine'], "125081")
|
111
|
+
assert_equal(@test.movies_info[1]['id_imdb'], "822388")
|
112
|
+
assert_equal(@test.movies_info[1]['last_change'], "1279466639")
|
113
|
+
|
114
|
+
assert_equal(@test.movies_info[2]['id'], "130190")
|
115
|
+
assert_equal(@test.movies_info[2]['id_allocine'], "130190")
|
116
|
+
assert_equal(@test.movies_info[2]['id_imdb'], "1319569")
|
117
|
+
assert_equal(@test.movies_info[2]['last_change'], "1279466629")
|
118
|
+
|
119
|
+
assert_equal(@test.movies_info[3]['id'], "24226")
|
120
|
+
assert_equal(@test.movies_info[3]['id_allocine'], "24226")
|
121
|
+
assert_equal(@test.movies_info[3]['id_imdb'], "825475")
|
122
|
+
assert_equal(@test.movies_info[3]['last_change'], "1279466647")
|
123
|
+
|
124
|
+
assert_equal(@test.movies_info[4]['id'], "172454")
|
125
|
+
assert_equal(@test.movies_info[4]['id_allocine'], "172454")
|
126
|
+
assert_equal(@test.movies_info[4]['id_imdb'], "861795")
|
127
|
+
assert_equal(@test.movies_info[4]['last_change'], "1279466623")
|
128
|
+
|
129
|
+
assert_equal(@test.movies_info[5]['id'], "61770")
|
130
|
+
assert_equal(@test.movies_info[5]['id_allocine'], "61770")
|
131
|
+
assert_equal(@test.movies_info[5]['id_imdb'], "471005")
|
132
|
+
assert_equal(@test.movies_info[5]['last_change'], "1279466668")
|
133
|
+
|
134
|
+
assert_equal(@test.movies_info[6]['id'], "126889")
|
135
|
+
assert_equal(@test.movies_info[7]['id'], "61521")
|
136
|
+
assert_equal(@test.movies_info[8]['id'], "111582")
|
137
|
+
assert_equal(@test.movies_info[9]['id'], "108235")
|
138
|
+
assert_equal(@test.movies_info[10]['id'], "124132")
|
139
|
+
assert_equal(@test.movies_info[11]['id'], "38634")
|
140
|
+
assert_equal(@test.movies_info[12]['id'], "112059")
|
141
|
+
assert_equal(@test.movies_info[13]['id'], "23239")
|
142
|
+
assert_equal(@test.movies_info[14]['id'], "7380")
|
143
|
+
assert_equal(@test.movies_info[15]['id'], "112129")
|
144
|
+
assert_equal(@test.movies_info[16]['id'], "19203")
|
145
|
+
assert_equal(@test.movies_info[17]['id'], "36161")
|
146
|
+
assert_equal(@test.movies_info[18]['id'], "36331")
|
147
|
+
assert_equal(@test.movies_info[19]['id'], "16194")
|
148
|
+
|
81
149
|
assert_equal(@test.quota['authorize'], "300")
|
82
150
|
assert_equal(@test.quota['use'], "2")
|
83
151
|
assert_equal(@test.quota['reset_date'], "2010-08-04 12:45:26")
|
84
152
|
end
|
153
|
+
|
85
154
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cine-passion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nicolas Ledez
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-30 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -81,7 +81,7 @@ licenses: []
|
|
81
81
|
post_install_message: |
|
82
82
|
**************************************************
|
83
83
|
|
84
|
-
Thank you for installing cine-passion-0.
|
84
|
+
Thank you for installing cine-passion-0.7.0
|
85
85
|
|
86
86
|
Please be copy lib/lib/cine_passion_config.rb.sample to lib/cine_passion_config.rb
|
87
87
|
And replace APIKEY with your own.
|