X-Git-Url: http://git.euphorik.ch/?p=pompage.git;a=blobdiff_plain;f=src%2Ffilm.rb;h=91dcf37f18c3056a17aef89aaceefb3279a2a903;hp=1eaa33f9ed97f307d68e3098dcd58cbad26602b9;hb=2a499b47db2419a221fed7cc0e9b899b2505d26f;hpb=e4a433cf5e1b42635a8b11877d67a08dcf6bf3fe
diff --git a/src/film.rb b/src/film.rb
index 1eaa33f..91dcf37 100644
--- a/src/film.rb
+++ b/src/film.rb
@@ -10,6 +10,12 @@ require 'personne.rb'
require 'constantes.rb'
+class String
+ def virerBalisesHTML
+ return self.gsub(/<(.*?)>/, '')
+ end
+end
+
class Film
attr_accessor :id, :titre, :fichiers, :annee, :realisateurs, :acteurs, :pays, :duree, :critiquePresse, :critiqueSpectateur, :genres, :synopsis, :budget
@@ -57,12 +63,15 @@ class Film
if !File.exists?(xmlFile)
return
end
-
+
racine = REXML::Document::new(File::new(xmlFile)).root
racine.each_element{|e|
- id = e.attribute('id').to_s().to_i()
+ id = e.attribute('id').to_s.to_i
- @@idDisponible = id + 1
+ if id > @@idDisponible
+ @@idDisponible = id + 1
+ end
+
titre = e.get_elements('titre')[0].get_text
fichiers = e.get_elements('fichiers')[0].get_elements('fichier')
@@ -129,12 +138,8 @@ class Film
private
def Film::filmsFactory(fichier)
- /^.*?\.(.{3,4})$/ =~ fichier
- if FILMS_EXTENSIONS.include?($1)
- #convertit le code latin-1 en UTF8
- Film::new(fichier.unpack("C*").pack("U*")).loadData
- end
- end
+ Film::new(fichier).loadData
+ end
def Film::litRepertoireR(r)
Dir::foreach(r){|f|
@@ -143,13 +148,23 @@ private
if File::directory?(fichier)
litRepertoireR(fichier)
else
-
- #si le film n'existe pas déjà dans la liste
+
+ # vérification de l'extension
+ /^.*?\.(.{3,4})$/ =~ fichier
+ if !FILMS_EXTENSIONS.include?($1)
+ next
+ end
+
+ fichier = CGI::escapeHTML(fichier.unpack("C*").pack("U*"))
+
+ # on skip si le film est déjà a dans la BD
if film = @@filmsFichier[fichier]
- puts "[i] Already exists in DB : #{film.titre} (#{film.fichiers[0]})"
+ puts "[i] Already exists in DB : #{film.titre} (#{fichier})"
next
end
+ #p fichier
+
film = nil
@@nbConn += 1
@@ -187,7 +202,7 @@ private
@@films[film.titre].addFichier(film.fichiers[0])
@@filmsFichier[film.fichiers[0]] = @@films[film.titre]
else
- puts "[!] Duplicate movie : #{film.titre} (#{film.fichier})"
+ puts "[!] Duplicate movie : #{film.titre} (#{film.fichiers[0]})"
end
else
puts "[i] movie added : #{film.titre} (#{film.fichiers[0]})"
@@ -229,13 +244,46 @@ public
# demande à l'utilisateur de faire un choix
# ret : true si le conflit à été résolu sinon false
def reglerConflitPlusieursReponses
- puts "prout"
- return false
+ @aPlusieursReponses = false # pour faire les choses bien
+
+ puts
+ puts "Plop, ya un conflit : #{@fichiers[0]}"
+ puts "Fais ton choix jeune padawan (un caractère et pas plus)"
+ tabNoms = @idsAllocine.keys
+ choix = 1
+ loop do
+ i = 1
+ tabNoms.each{|n|
+ puts "#{i}. #{n}"
+ i += 1
+ }
+ puts "A. Passer et l'ajouter"
+ puts "B. Ignorer"
+ choix = STDIN.gets
+
+ if /A/i =~ choix
+ return true
+ elsif /B/i =~ choix
+ return false
+ end
+
+ choix = choix.to_i
+ if choix > 0 && choix <= tabNoms.length
+ break;
+ else
+ puts
+ puts "Choix pas bon !!"
+ end
+ end
+
+ loadDepuisIdAllocine(@idsAllocine[tabNoms[choix-1]])
+
+ return true
end
def addFichier(fichier)
- if (!@fichiers.include?(fichier))
+ if !@fichiers.include?(fichier)
@fichiers << fichier
end
end
@@ -269,7 +317,7 @@ public
donneesHtml = nil
begin
begin
- reponse, donneesHtml = connexionHttp.get("/recherche/?motcle=#{CGI::escape(titre)}")
+ reponse, donneesHtml = connexionHttp.get("/recherche/?motcle=#{CGI::escape(titre.unpack("U*").pack("C*"))}")
rescue Exception => e
p e
puts "[!] Connexion lost, retry.."
@@ -292,12 +340,13 @@ public
unless titre.nil? or titre.empty?
#// =~ donneesHtml
- r = donneesHtml.scan(/(.*?)<\/a>/)
+ #r = donneesHtml.scan(/(.*?)<\/a>/)
+ r = donneesHtml.scan(/(.*?)<\/a>(?:<\/h4> (.*?)<\/h5>){0,1}/)
if r.length > 1
@aPlusieursReponses = true
r.each{|f|
- @idsAllocine[f[1].gsub(/<(.*?)>/, '')] = f[0]
+ @idsAllocine[f[1].virerBalisesHTML + (f[2] != nil ? " " + f[2].virerBalisesHTML : "")] = f[0]
}
elsif r.length == 1
loadDepuisIdAllocine(r[0][0], connexionHttp)
@@ -309,7 +358,11 @@ public
end
private
- def loadDepuisIdAllocine(id, connexionHttp)
+ def loadDepuisIdAllocine(id, connexionHttp = nil)
+ if (connexionHttp == nil)
+ connexionHttp = Net::HTTP::new('www.allocine.fr')
+ end
+
r, ficheHtml = connexionHttp.get("/film/fichefilm_gen_cfilm=#{id}.html")
#convertit le code latin-1 en UTF8
@@ -322,7 +375,7 @@ private
/(.*?)<\/title>/ =~ ficheHtml
@titre = $1 unless $1.nil?
- puts "Movie found : #{@titre} (#{@fichier})"
+ puts "Movie found : #{@titre} (#{@fichiers[0]})"
# Année
/Année de production : (\d+)<\/h4>/ =~ ficheHtml