webs-allocine 0.3.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.
- data/README.textile +92 -0
- data/allocine.gemspec +28 -0
- data/lib/allocine.rb +11 -0
- data/lib/allocine/allocine.rb +21 -0
- data/lib/allocine/movie.rb +54 -0
- data/lib/allocine/show.rb +49 -0
- data/spec/allocine.rb +17 -0
- data/spec/helper.rb +3 -0
- data/spec/movie.rb +49 -0
- data/spec/show.rb +40 -0
- metadata +62 -0
data/README.textile
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
h2. Allocine
|
2
|
+
|
3
|
+
Allocine consiste en trois classes.
|
4
|
+
|
5
|
+
* @Allocine@ : permet de rechercher des films/séries,
|
6
|
+
* @Allocine::Movie@ qui permet de récupérer toutes les informations sur un film,
|
7
|
+
* @Allocine::Show@ qui permet de récupérer toutes les information sur les séries.
|
8
|
+
|
9
|
+
Une documentation (et un code) plus propre arrive prochainement.
|
10
|
+
|
11
|
+
Bug reports : http://webs.lighthouseapp.com/projects/18095-allocine
|
12
|
+
|
13
|
+
Mis a disposition sous licence MIT. (c) 2008 Jordan Bracco <jordan@lifeisdead.net>
|
14
|
+
|
15
|
+
h3. Installation
|
16
|
+
|
17
|
+
<pre>
|
18
|
+
$ gem sources -a http://gems.github.com
|
19
|
+
$ sudo gem install webs-allocine
|
20
|
+
</pre>
|
21
|
+
|
22
|
+
h3. Recherche
|
23
|
+
|
24
|
+
Les recherches s'effectuent avec @Allocine.find_movie@ et @Allocine.find_show@, et renvoie un Hash de l'ID Allocine et du titre exact.
|
25
|
+
|
26
|
+
h4. Recherche d'un film
|
27
|
+
|
28
|
+
La recherche s'effectue avec @Allocine.find_movie@ et renvoie un Hash de l'ID allocine et du titre exact.
|
29
|
+
|
30
|
+
<pre>
|
31
|
+
>> Allocine.find_movie('Plan 9 From Outer Space')
|
32
|
+
=> {"13031"=>"Plan 9", "136668"=>"Plan 9 from Outer Space"}
|
33
|
+
</pre>
|
34
|
+
|
35
|
+
h4. Recherche d'une série
|
36
|
+
|
37
|
+
<pre>
|
38
|
+
>> Allocine.find_show('xfiles')
|
39
|
+
=> {"182"=>"X-Files : Aux frontières du réel"}
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
h3. Récupération des informations d'un film/série
|
43
|
+
|
44
|
+
h4. Film
|
45
|
+
|
46
|
+
<pre>
|
47
|
+
>> movie = Allocine::Movie.new('13031')
|
48
|
+
=> #<AllocineMovie:0x11fb250 ....>
|
49
|
+
>> movie.title
|
50
|
+
=> "Plan 9"
|
51
|
+
>> movie.original_title
|
52
|
+
=> "Plan 9 from Outer Space"
|
53
|
+
>> movie.actors
|
54
|
+
=> "Tom Keene, Tor Johnson, Vampira"
|
55
|
+
>> movie.directors
|
56
|
+
=> "Ed Wood"
|
57
|
+
>> movie.production_date
|
58
|
+
=> "1959"
|
59
|
+
>> movie.genres
|
60
|
+
=> "Science fiction, Epouvante-horreur, Fantastique"
|
61
|
+
>> movie.nat
|
62
|
+
=> "am\303\251ricain"
|
63
|
+
>> movie.image
|
64
|
+
=> ""
|
65
|
+
>> movie.synopsis
|
66
|
+
=> "Des extraterrestres appliquent le plan 9 destine a manoeuvrer les terriens. Plan diabolique, il consiste a la resurrection des morts en introduisant des electrodes a longue portee stimulant la glande pineale de cadavres recemment enterres."
|
67
|
+
</pre>
|
68
|
+
|
69
|
+
h4. Série
|
70
|
+
|
71
|
+
<pre>
|
72
|
+
>> show = Allocine::Show.new('182')
|
73
|
+
=> #<AllocineShow:0x1255908 ...>
|
74
|
+
>> show.title
|
75
|
+
=> "X-Files : Aux fronti\303\250res du r\303\251el"
|
76
|
+
>> show.created_by
|
77
|
+
=> "Chris Carter"
|
78
|
+
>> show.image
|
79
|
+
=> "http://a69.g.akamai.net/n/69/10688/v1/img5.allocine.fr/acmedia/medias/nmedia/18/35/65/25/18600368.jpg"
|
80
|
+
>> show.actors
|
81
|
+
=> "Robert Patrick, Annabeth Gish"
|
82
|
+
>> show.nat
|
83
|
+
=> "Am\303\251ricaine, canadienne"
|
84
|
+
>> show.duree
|
85
|
+
=> "42 mn"
|
86
|
+
>> show.genres
|
87
|
+
=> "Fantastique"
|
88
|
+
>> show.original_title
|
89
|
+
=> "The X Files"
|
90
|
+
>> show.synopsis
|
91
|
+
=> "Deux agents du FBI sont charg\303\251s d'enqu\303\252ter sur les dossiers non r\303\251solus, appel\303\251s \"X-files\" la plupart du temps des affaires o\303\271 le paranormal entre en jeu. L'agent Fox Mulder, malgr\303\251 le scepticisme de sa co-\303\251quipi\303\250re Dana Scully, tente de prouver sa th\303\250se du complot gouvernement/extra-terrestres...\r\n\r\nFox Mulder n'aura de cesse de rechercher sa soeur disparue des ann\303\251es auparavant lorsqu'il avait 12 ans."
|
92
|
+
</pre>
|
data/allocine.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "allocine"
|
3
|
+
s.version = "0.3.0"
|
4
|
+
s.date = "2009-02-08"
|
5
|
+
s.summary = "Allocine.fr parser"
|
6
|
+
s.email = "jordan@lifeisdead.net"
|
7
|
+
s.homepage = "http://github.com/webs/allocine"
|
8
|
+
s.description = "Allocine.fr parser"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ["Jordan Bracco", "Sunny Ripert"]
|
11
|
+
s.files = ["README.textile",
|
12
|
+
"allocine.gemspec",
|
13
|
+
"lib/allocine.rb",
|
14
|
+
"lib/allocine/allocine.rb",
|
15
|
+
"lib/allocine/movie.rb",
|
16
|
+
"lib/allocine/show.rb"
|
17
|
+
]
|
18
|
+
s.test_files = ["spec/allocine.rb",
|
19
|
+
"spec/helper.rb",
|
20
|
+
"spec/movie.rb",
|
21
|
+
"spec/show.rb"
|
22
|
+
]
|
23
|
+
#s.rdoc_options = ["--main", "README.txt"]
|
24
|
+
#s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
25
|
+
#s.add_dependency("diff-lcs", ["> 0.0.0"])
|
26
|
+
#s.add_dependency("mime-types", ["> 0.0.0"])
|
27
|
+
#s.add_dependency("open4", ["> 0.0.0"])
|
28
|
+
end
|
data/lib/allocine.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'iconv'
|
5
|
+
require 'allocine/allocine'
|
6
|
+
require 'allocine/movie'
|
7
|
+
require 'allocine/show'
|
8
|
+
MOVIE_SEARCH_URL = "http://www.allocine.fr/recherche/?motcle=%s&rub=1"
|
9
|
+
MOVIE_DETAIL_URL = "http://www.allocine.fr/film/fichefilm_gen_cfilm=%s.html"
|
10
|
+
SHOW_SEARCH_URL = "http://www.allocine.fr/recherche/?motcle=%s&rub=6"
|
11
|
+
SHOW_DETAIL_URL = "http://www.allocine.fr/series/ficheserie_gen_cserie=%s.html"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Allocine
|
2
|
+
|
3
|
+
# Make a search on movies
|
4
|
+
def self.find_movie(search)
|
5
|
+
Allocine::Movie.find(search)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Make a search on shows
|
9
|
+
def self.find_show(search)
|
10
|
+
Allocine::Show.find(search)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the first result
|
14
|
+
def self.lucky_movie(search)
|
15
|
+
Allocine::Movie.lucky_find(search)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.lucky_show(search)
|
19
|
+
Allocine::Show.lucky_find(search)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Allocine
|
2
|
+
class Movie
|
3
|
+
attr_accessor :title, :directors, :nat, :genres, :out_date, :duree, :production_date, :original_title, :actors, :synopsis, :image, :interdit
|
4
|
+
|
5
|
+
def self.find(search)
|
6
|
+
search.gsub!(' ', '+')
|
7
|
+
str = open(MOVIE_SEARCH_URL % search).read.to_s
|
8
|
+
data = Iconv.conv('UTF-8', 'ISO-8859-1', str)
|
9
|
+
movies = {}
|
10
|
+
while data =~ /<a href="\/film\/fichefilm_gen_cfilm=(\d+).html" class="link(\d+)">(.*?)<\/a>/i
|
11
|
+
id, klass, name = $1, $2, $3
|
12
|
+
data.gsub!("<a href=\"/film/fichefilm_gen_cfilm=#{id}.html\" class=\"link#{klass}\">#{name}</a>", "")
|
13
|
+
name.gsub!(/<(.+?)>/,'')
|
14
|
+
movies[id] = name
|
15
|
+
end
|
16
|
+
movies
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.lucky_find(search)
|
20
|
+
results = find(search)
|
21
|
+
new(results.keys.first)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(id, debug=false)
|
25
|
+
regexps = {
|
26
|
+
:title => '<h1 class="TitleFilm">(.*?)<\/h1>',
|
27
|
+
:directors => '<h3 class="SpProse">Réalisé par <a .*?>(.*?)<\/a><\/h3>',
|
28
|
+
:nat => '<h3 class="SpProse">Film (.*?). </h3>',
|
29
|
+
:genres => '<h3 class="SpProse">Genre : (.*?)</h3>',
|
30
|
+
:out_date => '<h3 class="SpProse">Date de sortie : <b>(.*?)</b>',
|
31
|
+
:duree => '<h3 class="SpProse">Dur\ée : (.*?). </h3>',
|
32
|
+
:production_date => '<h3 class="SpProse">Année de production : (.*?)</h3>',
|
33
|
+
:original_title => '<h3 class="SpProse">Titre original : <i>(.*?)</i></h3>',
|
34
|
+
:actors => '<h3 class="SpProse">Avec (.*?) ',
|
35
|
+
:synopsis => '<td valign="top" style="padding:10 0 0 0"><div align="justify"><h4>(.*?)</h4>',
|
36
|
+
:image => '<td valign="top" width="120".*?img src="(.*?)" border="0" alt=".*?" class="affichette" />',
|
37
|
+
:interdit => '<h4 style="color: #D20000;">Interdit(.*?)</h4>'
|
38
|
+
}
|
39
|
+
str = open(MOVIE_DETAIL_URL % id).read.to_s
|
40
|
+
data = Iconv.conv('UTF-8', 'ISO-8859-1', str)
|
41
|
+
regexps.each do |reg|
|
42
|
+
print "#{reg[0]}: " if debug
|
43
|
+
r = data.scan Regexp.new(reg[1], Regexp::MULTILINE)
|
44
|
+
r = r.first.to_s.strip
|
45
|
+
r.gsub!(/<.*?>/, '')
|
46
|
+
if r[0..0] == " "
|
47
|
+
r = r.reverse.chop.reverse # that's a little bit ugly, but the only simple way i found to remove the first space in the out date
|
48
|
+
end
|
49
|
+
self.instance_variable_set("@#{reg[0]}", r)
|
50
|
+
print "#{r}\n" if debug
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Allocine
|
2
|
+
class Show
|
3
|
+
attr_accessor :title, :created_by, :producters, :nat, :genres, :duree, :original_title, :actors, :synopsis, :image
|
4
|
+
|
5
|
+
def self.find(search)
|
6
|
+
search.gsub!(' ', '+')
|
7
|
+
str = open(SHOW_SEARCH_URL % search).read.to_s
|
8
|
+
data = Iconv.conv('UTF-8', 'ISO-8859-1', str)
|
9
|
+
shows = {}
|
10
|
+
while data =~ /<a href="\/series\/ficheserie_gen_cserie=(\d+).html" class="link(\d+)">(.*?)<\/a>/i
|
11
|
+
id, klass, name = $1, $2, $3
|
12
|
+
data.gsub!("<a href=\"/series/ficheserie_gen_cserie=#{id}.html\" class=\"link#{klass}\">#{name}</a>", "")
|
13
|
+
name.gsub!(/<(.+?)>/,'')
|
14
|
+
shows[id] = name
|
15
|
+
end
|
16
|
+
shows
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.lucky_find(search)
|
20
|
+
results = find(search)
|
21
|
+
new(results.keys.first)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(id, debug=false)
|
25
|
+
regexps = {
|
26
|
+
:title => '<title>(.*?)<\/title>',
|
27
|
+
:created_by => '<h4>Série créée par <a .*?>(.*?)</a>',
|
28
|
+
:producters => '<h4>Producteurs : (.*?)</h4>',
|
29
|
+
:nat => '<span style=\'font-weight:bold\'>Nationalité</span> : (.*?)</h5>',
|
30
|
+
:genres => '<span style=\'font-weight:bold\'>Genre</span> : (.*?) ',
|
31
|
+
:duree => '<span style=\'font-weight:bold\'>Format</span> : (.+?). ',
|
32
|
+
:original_title => '<h4><b>Titre original : </b></h4><h4 style="color:#D20000"><b>(.*?)</b></h4>',
|
33
|
+
:actors => '<h4>Avec : (.*?) ',
|
34
|
+
:synopsis => '<h5><span style=\'font-weight:bold\'>Synopsis</span> .*?<br />(.*?)</h5>',
|
35
|
+
:image => '<td><div id=\'divM\' .*?><img src=\'(.*?)\' style=\'border:1px solid black;.*?>',
|
36
|
+
}
|
37
|
+
str = open(SHOW_DETAIL_URL % id).read.to_s
|
38
|
+
data = Iconv.conv('UTF-8', 'ISO-8859-1', str)
|
39
|
+
regexps.each do |reg|
|
40
|
+
print "#{reg[0]}: " if debug
|
41
|
+
r = data.scan Regexp.new(reg[1], Regexp::MULTILINE)
|
42
|
+
r = r.first.to_s.strip
|
43
|
+
r.gsub!(/<.*?>/, '')
|
44
|
+
self.instance_variable_set("@#{reg[0]}", r)
|
45
|
+
print "#{r}\n" if debug
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/allocine.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
describe "Allocine" do
|
2
|
+
it "find movie" do
|
3
|
+
Allocine.find_movie('Plan 9').should == {"13031"=>"Plan 9", "136668"=>"Plan 9 from Outer Space"}
|
4
|
+
end
|
5
|
+
|
6
|
+
it "find show" do
|
7
|
+
Allocine.find_show('XFiles').should == {"182"=>"X-Files : Aux fronti\303\250res du r\303\251el"}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "lucky movie" do
|
11
|
+
Allocine.lucky_movie('Les pirates de la Silicon Valley').is_a?(Allocine::Movie).should == true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "lucky show" do
|
15
|
+
Allocine.lucky_show('Stargate').is_a?(Allocine::Show).should == true
|
16
|
+
end
|
17
|
+
end
|
data/spec/helper.rb
ADDED
data/spec/movie.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
describe "Allocine Movie (Star Trek - 4854)" do
|
2
|
+
|
3
|
+
before(:each) { @movie = Allocine::Movie.new('4854') }
|
4
|
+
|
5
|
+
it 'should have a title' do
|
6
|
+
@movie.title.should == "Star Trek : Premier contact"
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should have a synopsis' do
|
10
|
+
@movie.synopsis.should == "De m\303\251chants extraterrestres, les Borgs, complotent contre les habitants de la Terre. Ils mettent au point une machination diabolique pour d\303\251truire l'humanit\303\251."
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have an original title' do
|
14
|
+
@movie.original_title.should == "Star Trek: First Contact"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have a nationality' do
|
18
|
+
@movie.nat.should == "am\303\251ricain"
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have a picture' do
|
22
|
+
@movie.image.should == "http://a69.g.akamai.net/n/69/10688/v1/img5.allocine.fr/acmedia/medias/nmedia/18/66/82/23/18957530.jpg"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should have a genre' do
|
26
|
+
@movie.genres.should == "Science fiction"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should have a director' do
|
30
|
+
@movie.directors.should == "Jonathan Frakes"
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should have a duree (lolwtffrench)' do
|
34
|
+
@movie.duree.should == "1h 52min"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have actors' do
|
38
|
+
@movie.actors.should == "Jonathan Frakes, Patrick Stewart, Brent Spiner"
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should have an out date' do
|
42
|
+
@movie.out_date.should == "05 Mars 1997"
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should have a production date' do
|
46
|
+
@movie.production_date.should == "1996"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/show.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
describe "Allocine Show (Enterprise - 109)" do
|
2
|
+
|
3
|
+
before(:each) { @show = Allocine::Show.new('109') }
|
4
|
+
|
5
|
+
it 'should have a title' do
|
6
|
+
@show.title.should == "Enterprise"
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should have producters' do
|
10
|
+
@show.producters.should == "J.P. Farrell, Antoinette Stella"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have a genre' do
|
14
|
+
@show.genres.should == "Fantastique"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have an image' do
|
18
|
+
@show.image.should == "http://a69.g.akamai.net/n/69/10688/v1/img5.allocine.fr/acmedia/medias/nmedia/18/35/64/59/18415355.jpg"
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have a creator' do
|
22
|
+
@show.created_by.should == "Rick Berman"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should have actors' do
|
26
|
+
@show.actors.should == "Dominic Keating, Scott Bakula"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should have a nationality' do
|
30
|
+
@show.nat.should == "Am\303\251ricaine"
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should have a synopsis' do
|
34
|
+
@show.synopsis.should == "Le premier vaisseau terrien Enterprise, dirig\303\251 par le capitaine Jonathan Archer, part \303\240 la d\303\251couverte de mondes nouveaux, de nouvelles formes de vie et de civilisations diff\303\251rentes.Note : L'histoire se d\303\251roule 100 ans avant les aventures du capitaine Kirk dans la s\303\251rie originale Star Trek."
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have a duree' do
|
38
|
+
@show.duree.should == "42 mn" # \o/
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webs-allocine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jordan Bracco
|
8
|
+
- Sunny Ripert
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-02-08 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Allocine.fr parser
|
18
|
+
email: jordan@lifeisdead.net
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- README.textile
|
27
|
+
- allocine.gemspec
|
28
|
+
- lib/allocine.rb
|
29
|
+
- lib/allocine/allocine.rb
|
30
|
+
- lib/allocine/movie.rb
|
31
|
+
- lib/allocine/show.rb
|
32
|
+
has_rdoc: false
|
33
|
+
homepage: http://github.com/webs/allocine
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.2.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 2
|
57
|
+
summary: Allocine.fr parser
|
58
|
+
test_files:
|
59
|
+
- spec/allocine.rb
|
60
|
+
- spec/helper.rb
|
61
|
+
- spec/movie.rb
|
62
|
+
- spec/show.rb
|