Class: Allocine::Movie
- Inherits:
-
Object
- Object
- Allocine::Movie
- Defined in:
- lib/allocine/movie.rb
Instance Attribute Summary collapse
-
#actors ⇒ Object
Returns the value of attribute actors.
-
#directors ⇒ Object
Returns the value of attribute directors.
-
#duree ⇒ Object
Returns the value of attribute duree.
-
#genres ⇒ Object
Returns the value of attribute genres.
-
#image ⇒ Object
Returns the value of attribute image.
-
#interdit ⇒ Object
Returns the value of attribute interdit.
-
#nat ⇒ Object
Returns the value of attribute nat.
-
#original_title ⇒ Object
Returns the value of attribute original_title.
-
#out_date ⇒ Object
Returns the value of attribute out_date.
-
#press_rate ⇒ Object
Returns the value of attribute press_rate.
-
#production_date ⇒ Object
Returns the value of attribute production_date.
-
#synopsis ⇒ Object
Returns the value of attribute synopsis.
-
#title ⇒ Object
Returns the value of attribute title.
-
#trailer ⇒ Object
Returns the value of attribute trailer.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, debug = false) ⇒ Movie
constructor
A new instance of Movie.
Constructor Details
#initialize(id, debug = false) ⇒ Movie
Returns a new instance of Movie.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/allocine/movie.rb', line 42 def initialize(id, debug=false) 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
#actors ⇒ Object
Returns the value of attribute actors.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def actors @actors end |
#directors ⇒ Object
Returns the value of attribute directors.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def directors @directors end |
#duree ⇒ Object
Returns the value of attribute duree.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def duree @duree end |
#genres ⇒ Object
Returns the value of attribute genres.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def genres @genres end |
#image ⇒ Object
Returns the value of attribute image.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def image @image end |
#interdit ⇒ Object
Returns the value of attribute interdit.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def interdit @interdit end |
#nat ⇒ Object
Returns the value of attribute nat.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def nat @nat end |
#original_title ⇒ Object
Returns the value of attribute original_title.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def original_title @original_title end |
#out_date ⇒ Object
Returns the value of attribute out_date.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def out_date @out_date end |
#press_rate ⇒ Object
Returns the value of attribute press_rate.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def press_rate @press_rate end |
#production_date ⇒ Object
Returns the value of attribute production_date.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def production_date @production_date end |
#synopsis ⇒ Object
Returns the value of attribute synopsis.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def synopsis @synopsis end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def title @title end |
#trailer ⇒ Object
Returns the value of attribute trailer.
3 4 5 |
# File 'lib/allocine/movie.rb', line 3 def trailer @trailer end |
Class Method Details
.find(search) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/allocine/movie.rb', line 5 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 |
.lucky_find(search) ⇒ Object
37 38 39 40 |
# File 'lib/allocine/movie.rb', line 37 def self.lucky_find(search) results = find(search) new(results.first) end |
.searchGoogle(search, movies) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/allocine/movie.rb', line 28 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 |