require 'net/http'\r
+require 'uri'\r
require 'cgi'\r
require 'thread'\r
require 'iconv'\r
\r
require "basemodule.rb"\r
\r
-# un mixin pour allocine\r
+# un module d'importation pour le site "www.allocine.fr"\r
class Allocine < Basemodule\r
\r
+ def createConnexion\r
+ @connexion = Net::HTTP::new('www.allocine.fr') if @connexion.nil? \r
+ end\r
+ \r
# Voir le parent.\r
def rechercherFilm(titre)\r
- Thread.current["connexion"] = Net::HTTP::new('www.allocine.fr') if Thread.current["connexion"].nil?\r
- connexion = Thread.current["connexion"]\r
- \r
+ createConnexion\r
+\r
donneesHtml = nil\r
begin\r
begin\r
- reponse, donneesHtml = connexion.get("/recherche/?rub=1&motcle=#{CGI::escape(Iconv.iconv("ISO-8859-1", "UTF-8", titre)[0])}")\r
+ reponse, donneesHtml = @connexion.get("/recherche/?rub=1&motcle=#{CGI::escape(Iconv.iconv("ISO-8859-1", "UTF-8", titre)[0])}")\r
rescue Exception => e\r
p e\r
puts "[!] Connexion lost, retry.."\r
\r
reponses = {}\r
unless titre.nil? or titre.empty?\r
- \r
r = donneesHtml.scan(/<a href="\/film\/fichefilm_gen_cfilm=(\d+)\.html" class="link1">(.*?)<\/a>(?:<\/h4><h5 style="color: #666666"> (.*?)<\/h5>){0,1}(?:<h4><br \/><\/h4>){0,1}(?:<h4 style="color: #666666"> de (.*?)<\/h4>){0,1}(?:<h4 style="color: #666666"> avec (.*?)<\/h4>){0,1}(?:<h4 style="color: #666666"> \((.*?)\)<\/h4>){0,1}/)\r
\r
r.each{|f|\r
\r
# Voir le parent.\r
def load(id, film) \r
- Thread.current["connexion"] = Net::HTTP::new('www.allocine.fr') if Thread.current["connexion"].nil?\r
- connexion = Thread.current["connexion"]\r
- \r
- r, ficheHtml = connexion.get("/film/fichefilm_gen_cfilm=#{id}.html") \r
+ createConnexion\r
+\r
+ r, ficheHtml = @connexion.get("/film/fichefilm_gen_cfilm=#{id}.html") \r
\r
+ /<img src="(.*?)" border="0" alt="" class="affichette" \/>/ =~ ficheHtml\r
+ unless $1.nil?\r
+ @threadImage = Thread::new($1){|imageUrl|\r
+ begin\r
+ imageUrl = URI.parse(imageUrl) \r
+ connexionImage = Net::HTTP::new(imageUrl.host)\r
+ r, image = connexionImage.get(imageUrl.path)\r
+ f = File::new($repBase + "/" + $repAffichette + film.id.to_s + ".jpg", 'w').binmode\r
+ f.write(image)\r
+ f.close\r
+ rescue Exception => e\r
+ puts e.message\r
+ puts e.backtrace \r
+ end\r
+ }\r
+ end\r
+\r
#convertit le code latin-1 en UTF8\r
ficheHtml = Iconv.iconv("UTF-8", "ISO-8859-1", ficheHtml)[0]\r
\r
/Budget<\/b> : (.+?) millions d'euros<\/h4>/ =~ ficheHtml\r
film.budget = $1 unless $1.nil?\r
end \r
+ \r
+ def finish\r
+ @threadImage.join if defined? @threadImage\r
+ end\r
end
\ No newline at end of file