Class: Allocine::Movie
- Inherits:
-
Object
- Object
- Allocine::Movie
- Defined in:
- lib/allocine/movie.rb
Instance Attribute Summary
- - (Object) actors Returns the value of attribute actors.
- - (Object) directors Returns the value of attribute directors.
- - (Object) duree Returns the value of attribute duree.
- - (Object) genres Returns the value of attribute genres.
- - (Object) id Returns the value of attribute id.
- - (Object) image Returns the value of attribute image.
- - (Object) interdit Returns the value of attribute interdit.
- - (Object) nat Returns the value of attribute nat.
- - (Object) original_title Returns the value of attribute original_title.
- - (Object) out_date Returns the value of attribute out_date.
- - (Object) press_rate Returns the value of attribute press_rate.
- - (Object) production_date Returns the value of attribute production_date.
- - (Object) synopsis Returns the value of attribute synopsis.
- - (Object) title Returns the value of attribute title.
- - (Object) trailer Returns the value of attribute trailer.
Class Method Summary
Instance Method Summary
- - (Movie) initialize(id, debug = false) constructor A new instance of Movie.
- - (Object) press_reviews
Constructor Details
- (Movie) initialize(id, debug = false)
A new instance of Movie
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/allocine/movie.rb', line 58 def initialize(id, debug=false) self.id = id regexps = { :title => '<div class="titlebar"><h1>(.*?)<\/h1>', :directors => 'Réalisé par <span .*?><a .*?>(.*?)<\/a><\/span>', :nat => 'Long-métrage(.*?)\.', :genres => 'Genre : (.*?)<br\/>', :out_date => 'Date de sortie cinéma : <span .*?><a .*?>(.*?)<\/a><\/span>', :duree => 'Durée :(.*?) min', :production_date => 'Année de production.*?<a .*?>(.*?)<\/a>.*?<br \/>', :original_title => 'Titre original : <span .*?><em>(.*?)<\/em><\/span>', :actors => 'Avec (.*?), <a class=', :synopsis => '<p><span class="bold">Synopsis : </span>(.*?)</p>', :image => '<div class="poster"><em class="imagecontainer"><a .*?><img src=\'(.*?)\'alt=".*?"title=".*?"\/><img .*?><\/a><\/em>', :press_rate => '<p class="withstars"><a href=\'/film/revuedepresse_gen_cfilm=[0-9]*?.html\'><img .*? /></a><span class="moreinfo">\((.*?)\)</span></p></div>', :trailer => "<li class=\"\"><a href=\"\/video\/player_gen_cmedia=(.*?)&cfilm=#{id}\.html\">Bandes-annonces<\/a><\/li>" } data = Allocine::Web.new(MOVIE_DETAIL_URL % id).data.gsub(/\r|\n|\t/,"") regexps.each do |reg| print "#{reg[0]}: " if debug r = data.scan Regexp.new(reg[1], Regexp::MULTILINE) r = r.first.to_s.strip r.gsub!(/<.*?>/, '') r.strip! self.instance_variable_set("@#{reg[0]}", r) print "#{r}\n" if debug end end |
Instance Attribute Details
- (Object) actors
Returns the value of attribute actors
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def actors @actors end |
- (Object) directors
Returns the value of attribute directors
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def directors @directors end |
- (Object) duree
Returns the value of attribute duree
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def duree @duree end |
- (Object) genres
Returns the value of attribute genres
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def genres @genres end |
- (Object) id
Returns the value of attribute id
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def id @id end |
- (Object) image
Returns the value of attribute image
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def image @image end |
- (Object) interdit
Returns the value of attribute interdit
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def interdit @interdit end |
- (Object) nat
Returns the value of attribute nat
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def nat @nat end |
- (Object) original_title
Returns the value of attribute original_title
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def original_title @original_title end |
- (Object) out_date
Returns the value of attribute out_date
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def out_date @out_date end |
- (Object) press_rate
Returns the value of attribute press_rate
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def press_rate @press_rate end |
- (Object) production_date
Returns the value of attribute production_date
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def production_date @production_date end |
- (Object) synopsis
Returns the value of attribute synopsis
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def synopsis @synopsis end |
- (Object) title
Returns the value of attribute title
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def title @title end |
- (Object) trailer
Returns the value of attribute trailer
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def trailer @trailer end |
Class Method Details
+ (Object) find(search)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/allocine/movie.rb', line 6 def self.find(search) search = ActiveSupport::Multibyte.proxy_class.new(search.to_s).mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.to_s. downcase. gsub(/[\W]/u, ' '). gsub(/\s[a-z]{1}\s/, ' '). strip. gsub(/-\z/u, ''). gsub(' ', '+'). gsub('2nd', '2'). to_s data = Allocine::Web.new(MOVIE_SEARCH_URL % search).data.gsub(/\r|\n|\t|\s{2,}/,"") movies = Array.new while data =~ /<a href='\/film\/fichefilm_gen_cfilm=(\d+).html'><imgsrc='.*?'alt='(.*?)' \/><\/a>/i id, name = $1, $2 data.gsub!("<a href='/film/fichefilm_gen_cfilm=#{id}.html'>", "") name.gsub!(/<(.+?)>/,'') movies << [id, name] end movies = searchGoogle(search, movies.collect{|m| m[0]}) + movies return movies end |
+ (Object) lucky_find(search)
38 39 40 41 |
# File 'lib/allocine/movie.rb', line 38 def self.lucky_find(search) results = find(search) new(results.first) end |
+ (Object) searchGoogle(search, movies)
29 30 31 32 33 34 35 36 |
# File 'lib/allocine/movie.rb', line 29 def self.searchGoogle(search, movies) data = Allocine::Web.new("http://www.google.fr/search?hl=fr&q=site:allocine.fr+#{search}").data #.gsub(/\r|\n|\t/,"") matches = Array.new data.scan(/fichefilm_gen_cfilm=([0-9]*).html/) do |m| matches << [m.first, "#{search} - Found by Google"] unless movies.include? m.first end return matches.uniq end |
Instance Method Details
- (Object) press_reviews
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/allocine/movie.rb', line 43 def press_reviews data = Allocine::Web.new(MOVIE_PRESS_URL % self.id).data.gsub(/\r|\n|\t/,"") reviews = Array.new while data =~ /<div class="rubric"><div class="titlebar vmargin20t novmarginb"><a id="pressreview(.*?)" class="anchor"><\/a>(.*?)<\/p><\/div><div class="rubric">/i pressreviewid, content = $1, $2 data.gsub!(/<a id="pressreview#{pressreviewid}" class="anchor">/, "") content =~ /<h2><a href="\/critique\/fichepresse_gen_cpresse=(.*?).html">(.*?)<\/a><\/h2><span><img.*?stareval n([0-9]{1}?)0 on4.*?\/><\/span><\/div><p class="lighten">(.*?)<\/p><p>(.*?)<\/p>/ # 1 : ID, 2 : Journal, 3 : Note, 4 : Auteur, 5 : Critique reviews << [$1, $2, $3, $4, $5] unless $2.nil? || $3.nil? end reviews end |